Skip to content
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

Postgres 16 compatibility (FATAL: database does not exist) #29

Open
juhi24 opened this issue Aug 5, 2024 · 2 comments
Open

Postgres 16 compatibility (FATAL: database does not exist) #29

juhi24 opened this issue Aug 5, 2024 · 2 comments

Comments

@juhi24
Copy link

juhi24 commented Aug 5, 2024

Using a reasonably new version of postgres image (tried 16-alpine), you would get a

FATAL:  database "myapp" does not exist

See https://dev.to/nietzscheson/multiples-postgres-databases-in-one-service-with-docker-compose-4fdf#comment-2fd1m for further discussion and a possible workaround.

@iyxan23
Copy link

iyxan23 commented Oct 12, 2024

genuinely thank you so much for this, I had been stuck troubleshooting this problem. I would recommend to also put the error on the title for better visibility, I did not realize this was the whole culprit after all.

for those that only needed to create specific database(s)/user(s) (with passwords) and is able to mount the script to docker-entrypoint-initdb.d/:

#!/bin/bash

set -e
set -u

echo "setting up";

PGPASSWORD="${POSTGRES_PASSWORD}" psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
    CREATE USER ... PASSWORD '...';
    CREATE DATABASE ...;
    GRANT ALL PRIVILEGES ON DATABASE ... TO ...;

    -- you can copy paste multiple of these commands if you need to
EOSQL

echo "setup done";

this setup requires to set POSTGRES_PASSWORD, POSTGRES_USER and POSTGRES_DATABASE. works on postgresql 16.

@juhi24 juhi24 changed the title Postgres 16 compatibility Postgres 16 compatibility (FATAL: database does not exist) Oct 14, 2024
@juhi24
Copy link
Author

juhi24 commented Oct 14, 2024

Thanks for the suggestion. Glad to hear this helped you resolve the issue you had.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants