Postgresql remote connection not openning necessary ports

July 9, 2014 4.9k views

I bought a VPS from DigitalOcean with applications Rails+Unicorn+Nginx. I installed Postgresql 9.1 and trying to accept remote connections from that. I read all of the solutions/problems about it (Googled much) and did exactly. The problem is the following:

psql: could not connect to server: Connection refused Is the server running on host "" and accepting TCP/IP connections on port 5432?

I edited the postgresql.conf file with listenaddresses='*' I edited the pghba.conf file and added host all all md5 I restarted postgresql service and even the VPS however still I cannot connected to the database. So I tried to check the server's listening ports:

netstat -an | grep 5432
tcp        0      0*               LISTEN     
unix  2      [ ACC ]     STREAM     LISTENING     8356     /tmp/.s.PGSQL.5432

and then I nmap'ed the server from different machine:

Not shown: 996 closed ports
21/tcp  open  ftp
22/tcp  open  ssh
80/tcp  open  http
554/tcp open  rtsp

But still I cannot understand why postgresql not serving at the port 5432 after the configurations. I thought it might be caused by iptables. So that I add the following rules:

iptables -A INPUT -p tcp -m tcp --dport 5432 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --dport 5432 -j ACCEPT

Still no work.
Need advice.


1 Answer

It definitely seems like you can't access it due to firewalling. What the full output of iptables -L ?

Have another answer? Share your knowledge.