我有一个Django应用程序和一个Postgres DB进行了部署和码头化。这是我的docker-compose.yml
version: '3'
services:
web:
build: .
container_name: web
command: python manage.py migrate
command: python manage.py runserver 0.0.0.0:8000
volumes:
- ./src:/src
ports:
- "8000:8000"
depends_on:
- postgres
postgres:
image: postgres:latest
container_name: postgres
environment:
POSTGRES_USER: my_user
POSTGRES_PASSWORD: my_secret_pass!
POSTGRES_DB: my_db
ports:
- "5432:5432"
一切正常,我可以创建,更新或删除10个应用程序中任何一个的对象,但是,当我尝试删除以下类的Story
对象时,它将失败:>
class Story(models.Model):
title = models.CharField(max_length=255)
slug = models.SlugField(max_length=255)
author = models.ForeignKey(User, on_delete=models.CASCADE)
description = models.TextField(blank=True, null=True)
image = models.ImageField(upload_to="stories", null=True, blank=True)
还有一些其他具有“故事”外键的类,例如“赞”,“查看”或“评论”。
我的问题是,每当尝试删除故事时,都会出现操作错误。有趣的事实是,我可以创建或更新所需的故事,而不必删除它们。
当我尝试删除任何故事时,出现以下异常:
OperationalError: FATAL: the database system is in recovery mode
如果我查看执行的查询,我发现没有错:
DELETE FROM "votes_like" WHERE "votes_like"."story_id" IN (91)
DELETE FROM "comments_comment" WHERE "comments_comment"."story_id" IN (91)
DELETE FROM "stories_story" WHERE "stories_story"."id" IN (91)
然后:
OperationalError: server closed the connection unexpectedly
This probably means the server terminated abnormally before or while processing the request.
server process was terminated by signal 11: Segmentation fault
故事,评论,观点或喜欢的事物依旧。
在相同的dockerized设置下,我在localhost中没有遇到这种行为。
我还尝试在控制台中使用原始SQL删除该行,但是它不起作用,连接已关闭。
Postgres日志:
2018-11-30 16:09:58.980 UTC [1] LOG: server process (PID 3679) was terminated by signal 11: Segmentation fault
2018-11-30 16:09:58.980 UTC [1] DETAIL: Failed process was running: COMMIT
2018-11-30 16:09:58.980 UTC [1] LOG: terminating any other active server processes
2018-11-30 16:09:58.980 UTC [3588] WARNING: terminating connection because of crash of another server process
2018-11-30 16:09:58.980 UTC [3588] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2018-11-30 16:09:58.980 UTC [3588] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2018-11-30 16:09:58.980 UTC [3594] WARNING: terminating connection because of crash of another server process
2018-11-30 16:09:58.980 UTC [3594] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2018-11-30 16:09:58.980 UTC [3594] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2018-11-30 16:09:58.980 UTC [3595] WARNING: terminating connection because of crash of another server process
2018-11-30 16:09:58.980 UTC [3595] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2018-11-30 16:09:58.980 UTC [3595] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2018-11-30 16:09:58.981 UTC [3584] WARNING: terminating connection because of crash of another server process
2018-11-30 16:09:58.981 UTC [3584] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2018-11-30 16:09:58.981 UTC [3584] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2018-11-30 16:09:58.984 UTC [1] LOG: all server processes terminated; reinitializing
2018-11-30 16:09:58.998 UTC [3680] LOG: database system was interrupted; last known up at 2018-11-30 15:51:05 UTC
2018-11-30 16:09:59.000 UTC [3681] FATAL: the database system is in recovery mode
2018-11-30 16:09:59.708 UTC [3682] FATAL: the database system is in recovery mode
2018-11-30 16:10:00.204 UTC [3680] LOG: database system was not properly shut down; automatic recovery in progress
2018-11-30 16:10:00.211 UTC [3680] LOG: redo starts at 0/554D028
2018-11-30 16:10:00.212 UTC [3680] LOG: invalid record length at 0/5558040: wanted 24, got 0
2018-11-30 16:10:00.212 UTC [3680] LOG: redo done at 0/5558018
2018-11-30 16:10:00.212 UTC [3680] LOG: last completed transaction was at log time 2018-11-30 16:09:58.810025+00
2018-11-30 16:10:00.275 UTC [1] LOG: database system is ready to accept connections
有任何提示吗?几天来我一直在努力解决这个问题,但不知道如何进行。
答案 0 :(得分:0)
为将来参考,在完成docker-compose down和docker-compose up之后的问题已解决。
你们弄对了,数据可能已损坏。