Log in
updated 11:29 AM UTC, May 4, 2016

How to connect remotely to Postgresql database 9.1

  • Written by Madhu V Rao
  • Published in Database

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 )

vi /etc/postgresql/9.1/main/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:

vi /etc/postgresql/9.1/main/postgresql.conf

search for 'listen_addresses' and uncomment it (if its commented) and modify to look it as below: 

listen_addresses='*'

4) Restart the postgresql server by using command:

sudo service postgresql restart

OR

/etc/init.d/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.

 Note:

In case you are wondering how to check the Port number on which your postgresql is running, just type in command:

  pg_lsclusters

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.


Powered by Bullraider.com
Follow Us on Twitter
Find Us on Facebook
Follow Us on Google
Follow Us on Pinterest