I'm writing a shell script that will perform a pg_dump from one server, and later it will restore the dump into a database on another server.
To access the Postgres database on the first server, I use export PGPASSWORD in order to avoid a password prompt.
When I perform the restore on the Postgres database for the second server, I am prompted for a user password. I tried to re-declare export PGPASSWORD (since the password for this database is different), but this does not work. I'm suspecting it has something to do with the fact that I have to double SSH hop in order to access the second database:
export PGPASSWORD=******
perform pg_dump
...
export PGPASSWORD=********
cat out.sql | ssh -i .ssh/server1.pem [email protected] "ssh -i .ssh/server2 \
0.0.0.0 psql -U postgres -h localhost -p 5432 DBNAME"
The above results in:
Password for user postgres:
psql: FATAL: password authentication failed for user "postgres"
Does anyone have any suggestions? Thanks!