I'm trying to connect to a remote psql database. Before I added the pg_hba.conf entry with the client's IP address, I was getting an error message :

xdev@xdevbox:~$ psql -U postgres testdb -h 10.1.1.47
psql: FATAL:  no pg_hba.conf entry for host "10.201.50.71", user "postgres", database "testdb", SSL off

I added the client's IP with trust settings. I also changed the listen address in postgres.conf on the server to listen to "*". Then I restarted the database server using /etc/init.d/postgresql restart command.

Now when I try to connect, I get the following error message:

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

in postgresql.conf, the port is set to 5432. I'm not sure what else to check.

Thanks

  • Can you ping that address? – dezso May 4 '15 at 19:44
  • 1
    I'd say the DB didn't restart correctly when you restarted it. Check the PostgreSQL log files for the reason why - probably a typo in pg_hba.conf. – Craig Ringer May 5 '15 at 5:03
  • I had to change the listen address from * to the specific ip address. – dot May 5 '15 at 13:29
up vote 16 down vote accepted

You have to configure the following two files

pg_hba.conf

host all all 0.0.0.0/0 md5

postgresql.conf

listen_addresses='*'

You have to check if the port 5432 is open: http://www.yougetsignal.com/tools/open-ports/

If it's not then add a rule to your iptables:

iptables -A INPUT -s 0/0 -p tcp --dport 5432 -j ACCEPT

0/0: If you want anybody to access it. You can change it to a specific IP address or range of IP addresses.

  • Just an addition. You don't need to use an external tool. Just use telnet [yourServerIp] 5432 if you haven't telnet installed you can use PowerShell on windows for example. – Ionic Jul 4 '15 at 15:41
  • @Ionic that's true – Danish Khakwani Jul 4 '15 at 18:01
  • 2
    Well call me paranoid, but I don't trust too many services on the net. ;-) Just to be aware. :-) – Ionic Jul 4 '15 at 18:10

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.