2

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
  • Please edit your question to include the output of running netstat -an | grep -E '^tcp[^6].*LISTEN' while PostgreSQL is up and running.
    – user
    Aug 19, 2014 at 20:43
  • Server is not listening on 10.0.1.23, only on loopback device (127.0.0.1). But it's late and my brain just stopped.
    – rsm
    Aug 19, 2014 at 21:10
  • So how would I be able to change what the server is listening to?
    – Jonathan
    Aug 19, 2014 at 21:26

3 Answers 3

7

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

3
  • 1
    It's alright. Honest mistake. We've all done it. :) Aug 19, 2014 at 21:50
  • I change configuration for 100 times, restart PG for 100 times and find this :) Jul 24, 2016 at 16:41
  • I have worked as a programmer for over 10 years, and today I spent several hours debugging before this answer helped me. Aug 12, 2019 at 20:35
1

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.

1

Do following

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

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

restart service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .