Sunday 21 June 2015

postgresql 9.3 pg_dump from remote to local

This should work for a lot more versions as well. 9.3 happens to be the version I am using at the moment.

1
In remote server, edit /etc/postgresql/9.3/main/pg_hba.conf, and change it to
host all all 192.168.0.0/24 password 
It means allow any user from IP 192.168.0.x to connect any database by password. 

2
In remote server, edit /etc/postgresql/9.3/main/postgresql.conf and change it to
listen_addresses = '*'
It specifies the IPs on which the server is to listen for connections, which, in this case, means any IP.

3
Lastly, at local machine do below to pg_dump from remotehost to local machine. 
pg_dump -C -h remotehost -U remoteuser dbname | psql -h localhost -U localuser dbname