2

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!

2 Answers 2

3

You can create a file in your home directory with name .pgpass & give the password details there :

like :

cat .pgpass

hostname:port:database:username:password

localhost:2323:test_db:test_user:test123**

Try this one. Hope your problem will be solved.

Sign up to request clarification or add additional context in comments.

Comments

0

The .ssh/environment file is what you want. I think that file needs to be on server1, though, and server2 needs to be configured to allow users to modify their environment (via the PermitUserEnvironment option. See man ssh under "ENVIRONMENT" for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.