Hello,
I try to link the postgresql:latest container to an existing data directory.
This ends up with an empty database. I assume, I miss here something.
My compose file looks like this:
pgsql:
image: 'postgres:latest'
env_file: ".env"
restart: always
ports:
- '${FORWARD_DB_PORT:-5432}:5432'
environment:
#PGPASSWORD: '${DB_PASSWORD:-secret}'
# POSTGRES_DB: '${DB_DATABASE}'
POSTGRES_USER: '${DB_USERNAME}'
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
PGDATA: '/Users/mat/Library/Application Support/Postgres/dock'
volumes:
- '/Users/mat/Library/Application Support/Postgres/dock:/var/lib/postgresql/data'
networks:
- sail
what happens is, the server is started and a database is created:
2025-02-11 16:12:17 fixing permissions on existing directory /Users/mat/Library/Application Support/Postgres/dock ... ok
2025-02-11 16:12:17 creating subdirectories ... ok
2025-02-11 16:12:17 selecting dynamic shared memory implementation ... posix
2025-02-11 16:12:17 selecting default "max_connections" ... 100
2025-02-11 16:12:17 selecting default "shared_buffers" ... 128MB
2025-02-11 16:12:17 selecting default time zone ... Etc/UTC
2025-02-11 16:12:17 creating configuration files ... ok
2025-02-11 16:12:18 running bootstrap script ... ok
2025-02-11 16:12:18 performing post-bootstrap initialization ... ok
2025-02-11 16:12:19 syncing data to disk ... ok
2025-02-11 16:12:19
2025-02-11 16:12:19
2025-02-11 16:12:19 Success. You can now start the database server using:
2025-02-11 16:12:19
2025-02-11 16:12:19 pg_ctl -D '/Users/mat/Library/Application Support/Postgres/dock' -l logfile start
2025-02-11 16:12:19
2025-02-11 16:12:19 waiting for server to start....2025-02-11 16:12:19.326 UTC [49] LOG: starting PostgreSQL 17.2 (Debian 17.2-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2025-02-11 16:12:19 2025-02-11 16:12:19.329 UTC [49] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2025-02-11 16:12:19 2025-02-11 16:12:19.336 UTC [52] LOG: database system was shut down at 2025-02-11 16:12:18 UTC
2025-02-11 16:12:19 2025-02-11 16:12:19.343 UTC [49] LOG: database system is ready to accept connections
2025-02-11 16:12:19 done
2025-02-11 16:12:19 server started
2025-02-11 16:12:19 CREATE DATABASE
2025-02-11 16:12:19
2025-02-11 16:12:19
2025-02-11 16:12:19 /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2025-02-11 16:12:19
2025-02-11 16:12:19 waiting for server to shut down...2025-02-11 16:12:19.539 UTC [49] LOG: received fast shutdown request
2025-02-11 16:12:19 .2025-02-11 16:12:19.541 UTC [49] LOG: aborting any active transactions
2025-02-11 16:12:19 2025-02-11 16:12:19.543 UTC [49] LOG: background worker "logical replication launcher" (PID 55) exited with exit code 1
2025-02-11 16:12:19 2025-02-11 16:12:19.544 UTC [50] LOG: shutting down
2025-02-11 16:12:19 2025-02-11 16:12:19.546 UTC [50] LOG: checkpoint starting: shutdown immediate
2025-02-11 16:12:19 2025-02-11 16:12:19.860 UTC [50] LOG: checkpoint complete: wrote 921 buffers (5.6%); 0 WAL file(s) added, 0 removed, 0 recycled; write=0.009 s, sync=0.301 s, total=0.317 s; sync files=301, longest=0.003 s, average=0.001 s; distance=4238 kB, estimate=4238 kB; lsn=0/1908970, redo lsn=0/1908970
2025-02-11 16:12:19 2025-02-11 16:12:19.864 UTC [49] LOG: database system is shut down
2025-02-11 16:12:19 done
2025-02-11 16:12:19 initdb: warning: enabling "trust" authentication for local connections
2025-02-11 16:12:19 initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
2025-02-11 16:12:19 2025-02-11 16:12:19.968 UTC [1] LOG: starting PostgreSQL 17.2 (Debian 17.2-1.pgdg120+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2025-02-11 16:12:19 2025-02-11 16:12:19.969 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2025-02-11 16:12:19 2025-02-11 16:12:19.969 UTC [1] LOG: listening on IPv6 address "::", port 5432
2025-02-11 16:12:19 2025-02-11 16:12:19.972 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2025-02-11 16:12:19 2025-02-11 16:12:19.978 UTC [65] LOG: database system was shut down at 2025-02-11 16:12:19 UTC
2025-02-11 16:12:19 2025-02-11 16:12:19.983 UTC [1] LOG: database system is ready to accept connections
2025-02-11 16:17:20 2025-02-11 16:17:20.054 UTC [63] LOG: checkpoint starting: time
2025-02-11 16:17:24 2025-02-11 16:17:24.550 UTC [63] LOG: checkpoint complete: wrote 47 buffers (0.3%); 0 WAL file(s) added, 0 removed, 0 recycled; write=4.460 s, sync=0.029 s, total=4.496 s; sync files=12, longest=0.023 s, average=0.003 s; distance=269 kB, estimate=269 kB; lsn=0/194C050, redo lsn=0/194BFE0
2025-02-11 16:12:19 server stopped
2025-02-11 16:12:19
2025-02-11 16:12:19 PostgreSQL init process complete; ready for start up.
What am I missing, I just want postgre to open an existing data directory
thanks
matthias