Home > Software engineering >  FATAL: data directory "/var/lib/postgresql/data/pgdata" has invalid permissions Docker-com
FATAL: data directory "/var/lib/postgresql/data/pgdata" has invalid permissions Docker-com

Time:12-29

I faced with problem when create postgres container in the Docker on Windows 10 (on the MacOS is OK) I get error: FATAL: data directory "/var/lib/postgresql/data/pgdata" has invalid permissions

full logs

2022-12-27 11:40:08 This user must also own the server process.
2022-12-27 11:40:08 
2022-12-27 11:40:08 The database cluster will be initialized with locale "en_US.utf8".
2022-12-27 11:40:08 The default database encoding has accordingly been set to "UTF8".
2022-12-27 11:40:08 The default text search configuration will be set to "english".
2022-12-27 11:40:08 
2022-12-27 11:40:08 Data page checksums are disabled.
2022-12-27 11:40:08 
2022-12-27 11:40:08 fixing permissions on existing directory /var/lib/postgresql/data/pgdata ... ok
2022-12-27 11:40:08 creating subdirectories ... ok
2022-12-27 11:40:08 selecting dynamic shared memory implementation ... posix
2022-12-27 11:40:08 selecting default max_connections ... 20
2022-12-27 11:40:08 selecting default shared_buffers ... 400kB
2022-12-27 11:40:08 selecting default time zone ... Etc/UTC
2022-12-27 11:40:08 creating configuration files ... ok
2022-12-27 11:40:08 2022-12-27 08:40:08.524 UTC [69] FATAL:  data directory "/var/lib/postgresql/data/pgdata" has invalid permissions
2022-12-27 11:40:08 2022-12-27 08:40:08.524 UTC [69] DETAIL:  Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).
2022-12-27 11:40:08 child process exited with exit code 1
2022-12-27 11:40:08 initdb: removing contents of data directory "/var/lib/postgresql/data/pgdata"

I use such docker-compose.yml

  postgres_container:
    container_name: postgres_container
    image: postgres:13.3
    environment:
      - POSTGRES_DB=$POSTGRES_NAME_DB
      - POSTGRES_USER=$POSTGRES_USER
      - POSTGRES_PASSWORD=$POSTGRES_PASSWORD
      - PGDATA=$POSTGRES_PGDATA
    ports:
      - $POSTGRES_LOCAL_PORT:$POSTGRES_DOCKER_PORT
    user: postgres
    volumes:
      - ./postgres/scripts/init.sql:/docker-entrypoint-initdb.d/init.sql
      - .:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U admin -d pgdb"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 4G

Where $POSTGRES_PGDATA=/var/lib/postgresql/data/pgdata

CodePudding user response:

I add pgdata volumes

- pgdata:/var/lib/postgresql/data

and added

volumes:
  pgdata:

it works for me

  • Related