sudo rpm -Uvh http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-centos94-9.4-1.noarch.rpm
sudo yum update
sudo yum install postgresql94-server postgresql94-contrib
sudo yum install postgresql postgresql-contrib postgresql-client
sudo yum install postgresql-server-dev-9.4 (for server)
sudo yum install libpq-dev (for client)
sudo yum install postgresql-devel
sudo service postgresql-9.4 initdb
sudo service postgresql-9.4 start
sudo chkconfig postgresql-9.4 on

sudo nano /etc/sysconfig/iptables

Add the following line:

-A INPUT -m state –state NEW -m tcp -p tcp –dport 5432 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT

sudo service iptables restart

sudo su - postgres
psql
["\q" or "quit" to quit but don't now]
\password postgres
postgres=# CREATE EXTENSION adminpack;
\q
createuser USER
createdb DBNAME
psql
alter user USER with encrypted password 'PASSWORD';
grant all privileges on database DBNAME to USER;
\q

Configure PostgreSQL-MD5 Authentication

sudo nano /var/lib/pgsql/9.4/data/pg_hba.conf

Add or Modify the lines as shown below

[...]
 # TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
 local all all md5
 # IPv4 local connections:
 host all all 127.0.0.1/32 md5
 host all all 192.168.1.0/24 md5
 # IPv6 local connections:
 host all all ::1/128 md5
 [...]
sudo service postgresql-9.4 restart

Configure PostgreSQL-Configure TCP/IP

sudo nano /var/lib/pgsql/9.4/data/postgresql.conf

Find the lines (Uncomment):

[...]
 #listen_addresses = 'localhost'
 [...]
 #port = 5432
 [...]

 

Change to:

 listen_addresses = '*'
 port = 5432

sudo /etc/init.d/postgresql-9.4 restart