M HYPE SPLASH
// general

Postgresql connection refused

By Emma Payne

I'm trying to remotely connect to my postgresql database. I have two virtual machines set up both running ubuntu 14.04. I am trying to connect to the second vm using the first vm using

psql -h 10.0.1.23 -U postgres -d postgres

But I receive the error:

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

I have changed the pg_hba.conf and added

host all all 10.0.1.64/24 md5
host all all * md5
host all all 0.0.0.0/0 md5

And changed the postgresql.conf listen_address=" * "

In an attempt to allow all incoming connections. I have also tried to change the firewall settings, but I am unsure of whether or not the ports are properly listening for the connection.

Edit: Output of

netstat -an | grep -E '^tcp[^6].*LISTEN'
tcp 0 0 127.0.1.1:53 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:23 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
3

3 Answers

Apparently I had forgotten to remove the # from listen_address="*". It was a comment the entire time. I am dumb.

3

Ensure that the postgresql.conf file has an entry forlisten_addresses='*'. It looks like you are using the wrong configuration parameter name, and might have a space surrounding the asterisk.

Lastly, ensure you restart postgres after making these changes.

Do following

Update : /var/lib/pgsql/<version>/data/postgresql.conf

change : #listen_addresses = 'localhost' to listen_addresses = '*'

restart service

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy