I’m trying to configure a PostgreSQL instance running on SERVER_A to connect to another PostgreSQL instance on SERVER_B. I’m running a shell script on SERVER_A that ultimately needs to connect and execute a pg_restore onto a database that resides on SERVER_B.
SERVER_B is on Amazon’s AWS. Normally, to ssh into the machine, I would run the following commands:
# ssh -i .ssh/server-dev.pem root@dev.hostname.com
[root@dev]# ssh -i .ssh/dev1mac 0.0.0.0
…With the Postgres instance residing at 0.0.0.0
Can anyone help explain to me how I would use the above information to configure Postgres on SERVER_A? I have been looking into pg_hba.conf, but quite frankly I’ve never done this before and from the documentation, it’s not clear to me how to achieve my desired result. Is there perhaps an easier way that would allow me to skip configuring Postgres altogether, and instead just run a series of commands from my shell script to achieve the restore?
I’d appreciate any help, thanks!
If all you want to do is pg_restore a dump file currently on SERVER_A
to the DB instance running on SERVER_B
it’s easy:
SERVER_A # cat dump_file | ssh SERVER_B pg_restore
(Include any necessary options to pg_restore, but don’t specify a filename. Per the postgres manual, If [filename is] not specified, the standard input is used.
)
(You could also scp
the dump file over and then run the restore using the file on SERVER_B
, but the above seems to be more in line with your goal of running one script on SERVER_A
that does everything).
Check more discussion of this question.