Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql9.1 suddenly could not connect to server: No route to host

this problem was happened last night when I was using Adempiere. My adempiere server crash, it hints that there are no database, It all happened suddenly and I don't why.

So I checked the netstat -nlp | grep 5432, it shows as follow

tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::5432                 :::*                    LISTEN      -               
unix  2      [ ACC ]     STREAM     LISTENING     150917   -                   /var/run/postgresql/.s.PGSQL.5432

and I try psql -U postgres -h localhost, it connected success, but when I try psql -U postgres -h 192.168.1.103, it connected failed, showed as follow:

psql: could not connect to server: No route to host
Is the server running on host "192.168.1.103" and accepting
TCP/IP connections on port 5432?

Then I checked the pg_hba.conf and postgresql.conf, they are right, as follow:

host all all 192.168.1.0/24 md5
listen_addresses='*'

So I think my configuration is correct and I have connected successful before, it is odds can not connect now, could anyone help me, thanks?

like image 218
whb_zju Avatar asked Nov 04 '22 21:11

whb_zju


2 Answers

"No route to host" means that it's possible the net problem , first ping 192.168.1.103; if it works ,than " telnet 192.168.1.103 5432" to see if the port is ok .

And it's not the pg_hba issue。

like image 132
francs Avatar answered Nov 09 '22 13:11

francs


I'm running POstgres 9.5 on Centos 7 and had the same issue. From the client machine, I could ping and telnet into port 22. Then I performed a telnet into port 5432 from the client machine and had the error below.

[pegusr@test ~]$ telnet  192.168.xx.x1 5432
Trying 192.168.56.111...
telnet: connect to address 192.168.xx.1x: No route to host

Since this was a test env I just disabled the firewalld on the DB server i.e.

systemctl stop firewalld

And it has worked since. For production environments, ask your sysadmin to add a firewall rule from the client machine into port 543x of your DB server.

Hope that helps!

like image 43
ribbit Avatar answered Nov 09 '22 15:11

ribbit