Lock file "postmaster.pid" contains wrong PID

I started my app with docker-compose.yml. Everything starts fine and works, but after a few minutes container database stops with lock file "postmaster.pid" contains wrong PID: 7834 instead of 1. I tried to delete postmaster.pid inside docker and containers, but this didn't help. I also did this procedure: How do I fix stale postmaster.pid file on Postgres?. But the problem persists. I don't understand what to do. I want to notice that I've added these lines to /opt/homebrew/var/postgresql@15/postgresql.conf and /opt/homebrew/var/postgresql@15/pg_hba.conf:

postgresql.conf

# Add settings for extensions here
listen_addresses = '*'

pg_hba.conf

host    movies_database    app    0.0.0.0/0    md5

/opt/homebrew/var/postgresql@15/postmaster.pid

8111
/opt/homebrew/var/postgresql@15
1715706343
5432
/tmp
*
936360   3407872
ready  

/var/lib/postgresql/data/postmaster.pid

8234
/opt/homebrew/var/postgresql@15
1715706583
5432
/tmp
*
936360   3473408
ready 

docker logs

database-1     | 2024-05-14 19:32:32.038 [1] LOG:  lock file "postmaster.pid" contains wrong PID: 8234 instead of 1
database-1     | 2024-05-14 19:32:32.038 [1] LOG:  performing immediate shutdown because data directory lock file is invalid
database-1     | 2024-05-14 19:32:32.038 [1] LOG:  received immediate shutdown request
database-1     | 2024-05-14 19:32:32.056 [1] LOG:  database system is shut down
database-1 exited with code 0

docker-compose.yml

version: '3.8' 
  
services:
  django:
    build:
      context: .
    volumes:
      - "./movies_admin:/movies_admin"
    env_file:
      - "movies_admin/config/.env"
    depends_on:
      - database
      - elasticsearch
  
  database:

    image: postgres:15.7

    environment:
    
      - POSTGRES_DB=movies_database
      - POSTGRES_USER=app
      - POSTGRES_PASSWORD=123qwe
    
    volumes:
      - /opt/homebrew/var/postgresql@15:/var/lib/postgresql/data 
    
  

  nginx:
    image: nginx:latest
    container_name: nginx
    volumes:
      - "./nginx/nginx.conf:/etc/nginx/nginx.conf"
      - "./nginx/default.conf:/etc/nginx/conf.d/default.conf"
      - "./movies_admin/movies_admin/staticfiles/admin:/etc/nginx/movies_admin/movies_admin/staticfiles/admin"
      - "./movies_admin/movies_admin/staticfiles/rest_framework:/etc/nginx/movies_admin/movies_admin/staticfiles/rest_framework"
    ports:
      - "80:80"
    depends_on:
      - django
  
  elasticsearch:
    image: elasticsearch:8.13.0
    container_name: elasticsearch
    environment:
      - "ES_JAVA_OPTS=-Xms200m -Xmx200m"
      - discovery.type=single-node
      - xpack.security.enabled=false
    ports:
      - 9200:9200
Back to Top