"psql :could not connect to server: no route to host" - Fix it Now ?

"psql: could not connect to server: No route to host"  often happens when users try to connect to PostgreSQL.

A common reason for this error is Firewall restriction.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform related PostgreSQL queries.

What triggers "psql: could not connect to server: No route to host" ?

While connecting through pgAdmin users often notice the "could not connect to server: No route to host".

Some of the common reasons for pgAdmin to show this error include:

  • Database server isn't running.
  • Server isn't configured to accept TCP/IP requests on the address shown.

Also, this error could also trigger due to restrictions in the Firewall or using a different port for PostgreSQL.

Methods to fix "psql: could not connect to server: No route to host" ?

1. Restart PostgreSQL

This error could trigger when the PostgreSQL database is not working. We can fix this by performing a restart of the service.

$ sudo service postgresql restart

Once we restart the service, try reconnecting to PostgreSQL.

2. Accept TCP/IP requests

For security reasons, a PostgreSQL server "out of the box" doesn't listen on TCP/IP ports. Instead, it must be enabled to listen for TCP/IP requests.

We need to edit the /var/lib/pgsql/data/postgresql.conf to enable this. Add the following line in the conf file to make the server accept connections on any IP interface:


3. Firewall restrictions

A common reason for this error is the firewall restrictions blocking the connections to the port 5432. We may try a telnet request to the port 5432 to check if t is reachable:

telnet 192.x1.xx.x1 5432
Trying 192.x1.xx.x1...
telnet: connect to address 192.x1.xx.x1: No route to host

We may need to run the following code to allow incoming connections through the OS firewall in Redhat\CentOS for postgresql default port 5432:

firewall-cmd --add-service=postgresql --permanent


[Need help to fix PostgreSQL error? We are available 24*7. ]


This article covers how to fix the "could not connect to server: No route to host" PostgreSQL error. Basically, the "could not connect to server: No route to host" triggers while connecting to PostgreSQL due to a number of reasons.

Make the Iptables rules different in Master and Slave.

iptables -L INPUT
iptables -P INPUT ACCEPT
iptables -F INPUT 
iptables -F OUTPUT
iptables  -F FORWARD

For Linux Tutorials

We create Linux HowTos and Tutorials for Sys Admins. Visit us on LinuxAPT.com

Also for Tech related tips, Visit forum.outsourcepath.com or General Technical tips on www.outsourcepath.com