How Do You Troubleshoot This Error with a PostgreSQL Front End Application “Connection refused … Is the server running on host “x.x.x.x” and accepting TCP/IP connections on port 5432″?

Problem scenario
With a SQL front end (e.g., pgAdmin or HeidiSQL) you get this error "could not connect to server: Connection refused 0x0000274D/10061) Is the server running on host "x.x.x.x" and accepting TCP/IP connections on port 5432?

You double checked you are trying to connect to the correct IP address (x.x.x.x).  You know port 5432 is not blocked.  You know the postgres service is listening on port 5432 on the destination server. How do you fix this problem?

With Postgres version 9 on Ubuntu 16.x, the "postmaster" service does not need to be running.  One of these below may solve the problem by itself.

Possible solution #1  Go to the server with Postgres.  Find the postgresql.conf file (e.g., with this find / -name postgresql.conf).  Find the listen_addresses stanza.  Make sure the server's own IP address is listed next to the "localhost," text separated by a space.  A common mistake is to have the IP address of a Postgres client.  The Postgres server's IP address is the one that is needed.  Here is how it should look where x.x.x.x is the IP address of the PostgreSQL server:

listen_addresses = 'localhost, x.x.x.x'      # Replace x.x.x.x with the IP address of the Postgres server.

Possible solution #2  Go to the /etc/hosts file.  Make sure that one IP address to DNS name maps "localhost" to the server's IP address.

Possible solution #3  Make sure that postgresql.conf file does not have this stanza:

tcpip_socket = true

It used to be necessary.  This stanza will now cause this "connection refused" error.  Remove this stanza if it is there.

Leave a comment

Your email address will not be published. Required fields are marked *