-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Server not properly shut down after initializing empty data directory on first start #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you provide a little bit more detail that would allow us to reproduce? This sounds to me like maybe you had the initialization fail and a restart policy on the container brought it back up? (See #159 for a script adjustment that might help make that specific case more obvious if that's indeed what you're running into.) |
I reproduced this now with the 14-alpine image ID I don't think there's anything from my configuration that could affect that. Other than the secrets and create-non-superuser-db shell script, which I don't think is causing it either, since it doesn't exit with an error. docker-compose.yml: version: '3.8'
services:
postgres:
image: postgres:14-alpine
restart: unless-stopped
stop_grace_period: 1m
environment:
- POSTGRES_NON_ROOT_USER: "myuser"
- POSTGRES_NON_ROOT_DB: "mydb"
- POSTGRES_PASSWORD_FILE: "/run/secrets/POSTGRES_PASSWORD"
- POSTGRES_NON_ROOT_PASSWORD_FILE: "/run/secrets/POSTGRES_NON_ROOT_PASSWORD"
volumes:
- ./database_exports:/docker-entrypoint-initdb.d
- postgres_data:/var/lib/postgresql/data
secrets:
- POSTGRES_PASSWORD
- POSTGRES_NON_ROOT_PASSWORD
volumes:
postgres_data:
secrets:
POSTGRES_PASSWORD:
file: "./secrets/live/POSTGRES_PASSWORD"
POSTGRES_NON_ROOT_PASSWORD:
file: "./secrets/live/POSTGRES_NON_ROOT_PASSWORD" ./database_exports/000-create-non-superuser-db.sh #!/bin/bash -e
file_env 'POSTGRES_NON_ROOT_PASSWORD'
if [ "$POSTGRES_NON_ROOT_USER" ] && [ "$POSTGRES_NON_ROOT_PASSWORD" ]; then
docker_process_sql -v non_root_user="$POSTGRES_NON_ROOT_USER" -v non_root_password="$POSTGRES_NON_ROOT_PASSWORD" <<-'EOSQL'
CREATE ROLE :"non_root_user" WITH LOGIN PASSWORD :'non_root_password';
EOSQL
fi
if [ "$POSTGRES_NON_ROOT_DB" ] && [ "$POSTGRES_NON_ROOT_USER" ]; then
docker_process_sql -v non_root_db="$POSTGRES_NON_ROOT_DB" -v non_root_user="$POSTGRES_NON_ROOT_USER" <<-'EOSQL'
CREATE DATABASE :"non_root_db" WITH OWNER :"non_root_user" TEMPLATE template0;
EOSQL
fi
exit 0 Full startup log:
|
Since your log has these lines, it is definitely crashing/exiting right after or within your script. postgres_1 | /usr/local/bin/docker-entrypoint.sh: sourcing /docker-entrypoint-initdb.d/000-create-non-superuser-db.sh
postgres_1 | CREATE ROLE
postgres_1 | CREATE DATABASE
postgres_1 |
postgres_1 | PostgreSQL Database directory appears to contain a database; Skipping initialization Ah, remove the |
Yes, that is obviously it. I removed the |
When first starting the container, after the entrypoint script completes an empty datadir initialization, the server process prints that it was not properly shut down and does an automatic recovery.
I see the docker-entrypoint.sh script runs
pg_ctl -D "$PGDATA" -m fast -w stop
, which should safely shut it downpostgres/14/alpine/docker-entrypoint.sh
Line 274 in a1ea032
but after initialization is complete, the first time the container starts, it still does a recovery:
The text was updated successfully, but these errors were encountered: