Password authentication failed after Restoring database?

I am trying to migrate my db from one server to another but I am facing authentication error

Steps to reproduce error:

  1. Create Postgres db container

docker run --name aal-postgres -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=aal -d postgres

  1. Restore dump to the newly created container
    cat dump_07-05-2022_16_48_20.sql | docker exec -i aal-postgres psql -U postgres

  2. Setup Database
    docker run --link aal-postgres:postgres -e DB_PASSWORD=mysecretpasswords -it aal trytond-admin -d aal --all -vv

This Produces following error

psycopg2.OperationalError: FATAL: password authentication failed for user “postgres”

I guess that aal image is a derivative from tryton/tryton. If so be sure that it is using the / which is responsible to set the environment variables.

yes it is extended image of tryton/tryton and using still no luck

You’re connecting to the default database postgres because you’re setting the -U (user) param to postgres. You do not provide the postgres database password anywhere - which is not the problem.

To target the aal database as defined in the step 1 on POSTGRES_DB, add the database name in the psql command.

docker exec -i aal-postgres psql -U postgres aal

I Just followed this command and it helped

To backup:

docker exec -u <your_postgres_user> <postgres_container_name> pg_dump -Fc <database_name_here> > db.dump

To drop db (Don’t do it on production, for test purpose only!!!):

docker exec -u <your_postgres_user> <postgres_container_name> psql -c 'DROP DATABASE <your_db_name>'

To restore:

docker exec -i -u <your_postgres_user> <postgres_container_name> pg_restore -C -d postgres < db.dump

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.