Django и Postgres, OperationalError при удалении объекта - PullRequest
0 голосов
/ 30 ноября 2018

У меня есть приложение Django и база данных Postgres, развернутая и докеризованная.Это мой 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)

Есть также несколько других классов, имеющих ForeignKey to Story, таких как Like, View или Comment.

Моя проблемачто я получаю операционную ошибку всякий раз, когда я пытаюсь удалить историю.Забавно, что я могу создавать или обновлять столько историй, сколько захочу, но не удалять их.

Когда я пытаюсь удалить любую историю, я получаю следующее исключение:

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

И историю, комментарии, мнения или лайки, которые у нее были,остается как обычно.

Я не испытываю такого поведения в localhost при той же настройке dockerized.

Я также пытался удалить строку, используя raw 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

Есть подсказки?Я пытался решить эту проблему в течение нескольких дней, но понятия не имел, что делать дальше.

1 Ответ

0 голосов
/ 07 декабря 2018

Для дальнейшего использования проблема была исправлена ​​после создания docker-compose и docker-compose up.

Вы, ребята, все поняли правильно, данные, вероятно, были повреждены.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...