By default, PostgreSQL database server only allow localhost access. When setting up an PostgreSQL in a cluster environment. Here are some hints for you to quick figure out what to do.

Networking configuration

First you have to make sure client and server can see each other, then setup iptable rules for PostgreSQL. If in an trusted LAN environment, client and server already set to widely open and trusted, then skip this part.

Make sure iptables is not blocking communication, open port 5432(or the port you changed from default)

append rules to your iptables scripts or file /etc/sysconfig/iptables:

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d <pg server ip> --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -s <pg server ip> --sport 5432 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

Restart firewall:

# /etc/init.d/iptables restart

Enable PostgreSQL Host Based Authentication

You need edit the PostgreSQL configuration file, edit the PostgreSQL Host Based Authentication configuration file pg_hba.conf, by default it's in the PostgreSQL initialized data directory, for 9.3, it's in


It has 7 different authentication formats, chose one for you.  I use the commonly used one as an example:

host    database  user  address  auth-method  [auth-options]
So, the record should look like this:

host testdb testuser trust

Note: suppose the client ips are in 10.0.1 subnet. You can find more detail configuration of pg_hba.conf in

Allow TCP/IP socket

In the configuration file postgresql.conf, by default it's in PostgreSQL initialized data directory, for 9.3, it's in

Find configuration line that read as follows:

Next set IP address(es) to listen on; you can use comma-separated list of addresses; defaults to 'localhost', and '*' is all ip address:

Or just bind to you PostgreSQL server ip address, for example:

Save and restart the PostgreSQL database

Test your setup

Use psql command from client system. Connect to remote server using IP address and login using vivek username and sales database, enter:

$ psql -h <pg server ip> -U testuser testdb


Comments powered by CComment