postgresql Postgresql9.1 突然无法连接到服务器:没有到主机的路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11183355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:02:28  来源:igfitidea点击:

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

postgresqlnetworking

提问by whb_zju

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.

这个问题是昨晚我在使用 Adempiere 时发生的。我的 adempiere 服务器崩溃,提示没有数据库,这一切都是突然发生的,我不知道为什么。

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

所以我检查了netstat -nlp | grep 5432,它显示如下

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 -U postgres -h localhost,它连接成功,但是当我尝试时psql -U postgres -h 192.168.1.103,它连接失败,显示如下:

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:

然后我查了pg_hba.conf和postgresql.conf,都是对的,如下:

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?

所以我认为我的配置是正确的,我之前连接过成功,现在很可能无法连接,有人可以帮助我吗,谢谢?

回答by francs

"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 .

“No route to host”表示可能是网络问题,先ping 192.168.1.103;如果它有效,则使用“telnet 192.168.1.103 5432”来查看端口是否正常。

And it's not the pg_hba issue。

而且不是 pg_hba 的问题。

回答by ribbit

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.

我在 Centos 7 上运行 POstgres 9.5 并且遇到了同样的问题。在客户端机器上,我可以 ping 和 telnet 到端口 22。然后我从客户端机器执行到端口 5432 的 telnet 并出现以下错误。

[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.

由于这是一个测试环境,我只是在数据库服务器上禁用了 firewalld,即

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.

从那以后它一直有效。对于生产环境,请您的系统管理员将来自客户端计算机的防火墙规则添加到数据库服务器的端口 543x。

Hope that helps!

希望有帮助!

回答by Slivicon

You may need to run:

您可能需要运行:

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

This allows incoming connections through the OS firewall in Redhat\CentOS for postgresql default port 5432.

这允许通过 Redhat\CentOS 中的操作系统防火墙进入 postgresql 默认端口 5432 的连接。

Ref. https://serverfault.com/a/789015/518039

参考 https://serverfault.com/a/789015/518039