Postgresql – Remote postgres Connection

postgresqlremote-access

Well I seem to have tried everything I can find – not that much – but cannot fathom why I cannot get a remote connection to my database.

Here's what I have:

#postgresql.conf
listen_addresses = '12.34.56.78,localhost' # included my local ip
port = 5432                                # the port I'm trying to connect with
tcpip_socket = true                        

#pg_hba.conf
host    all         mydbuser       12.34.56.78/32         md5

I receive: connection to database 'name' failed, could not connect to server: Connection refused.
 Is the server running on host "domain.com" and accepting
 TCP/IP connections on port 5432?

netstat -ant | grep 5432 #returns nothing 

netstat -nltp | grep 5432: returns nothing

Solution

Really I think what was holding me back from grasping an understanding of this was a poorly written blog post on the subject. On the other hand an awesome tutorial at slice host cleared things up for me and if anyone ever comes here having the same problems I suggest they read through it. Slicehost really have to be commended on the quality and maintenance of their tutorials, though I guess it is good business to help people use their service.

Thank you to everyone who answered.

Best Answer

On the db server could you run the following and post the output:

  • ps axf | grep postgres
  • the listening port netstat -nltp | grep 5432

To get around firewalls try using port 80 or 8080 instead of 5432.

Are you connecting from 12.34.56.78/32 (this is the allowed range in your pg_hba.conf)?

Can you ping 12.34.56.78?

From the empty netstat output, looks like your postgres process is not listening on the port!

Does anything interesting show up in /var/log/postgresql/ when you restart the database.