Forums

Question: Password authentication failure when using pg_restore

[SOLVED - see two posts down.]

As strongly suggested by pythonanywhere, I am setting up backups for my postgresql database.

I dumped the data following the instructions on https://help.pythonanywhere.com/pages/RegularPostgresBackups, and everything went well.

I want to restore the postgres database from the dump data, but I am getting a password authentication failure. My terminal input and output are shown below.

(virtual-env-uptodate-production) 12:55 ~/postgresql_backups $ pg_restore --verbose -h measuredfood4875-23.postgres.eu.pythonanywhere-services.com -p 10023 -d measuredfooddb -S measuredfooduser pgbackup2019-11-18-1239.dump

pg_restore: connecting to database for restore

Password:

pg_restore: [archiver (db)] connection to database "measuredfooddb" failed: FATAL: password authentication failed for user "measuredfood4875"

I have tried both the password for measuredfooduser and measuredfood4875, neither have worked.

What I would like to know most: which password is actually required?

You need to use the password that you originally configured your Postgres server 'super' to have and then use the 'super' user to restore your database.

That was not the solution, but it ended up leading me to the solution, which I am posting for future reference.

SOLUTION:

I needed to specify the --username option in order to connect as the correct user. After I did that, I did not get the password authentication failure anymore. I am getting some other error messages but I will try to solve them on my own first.

Here is the code I put into the bash console:

11:23 ~/postgresql_backups $ pg_restore --verbose -h measuredfood4875-23.postgres.eu.pythonanywhere-services.com -p 10023 -d measuredfooddb --superuser super --username measuredfooduser pgbackup2019-11-18-1239.dump

I used the password for 'measuredfooduser' and it worked.

I thought the -S option specified the user to connect to the database as, but it does not. -S specifies the superuser, and the user has to specified in addition to that. Here is a link to the relevant documentation.

aha, thanks for sharing!