In-order to connect to a remote postgresql database , the following changes have to be done on the postgresql side:
1) Connect to the System where Postgresql is installed. (Use SSH or login directly to the server using username postgres).
2) Enable the client authentication by editing the file pg_hba.conf ( please check the file '/etc/postgresql/9.1/main/postgresql.conf' for the location of the pg_hba.conf )
Add the following configuration (replace Your_IP with your actual IP address)
host all all Your_IP/24 trust
3) Enable networking for Postgresql by editing the file:
search for 'listen_addresses' and uncomment it (if its commented) and modify to look it as below:
4) Restart the postgresql server by using command:
sudo service postgresql restart
5) Test your set-up. Connect to Remote database using pg_admin on your client system. Or use psql to connect to it.
In case you are wondering how to check the Port number on which your postgresql is running, just type in command:
You will get output like below:
Version Cluster Port Status Owner Data directory ... 9.1 main 5433 online postgres /mnt/data ....
That's it. Now you can connect remotely to your postgresql.