postgresql psql: 无法连接到服务器...服务器是否在主机上运行...并接受端口 5432 上的 TCP/IP 连接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48242010/
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
psql: could not connect to server... Is the server running on host ... and accepting TCP/IP connections on port 5432?
提问by Noah Huntington
I know this is a popular question. I have tried everything suggested in similar threads. I am trying to connect remotely to a postgresql database on an azure windows server 2012 machine. I have tried the following...
我知道这是一个受欢迎的问题。我已经尝试了类似线程中建议的所有内容。我正在尝试远程连接到 azure windows server 2012 机器上的 postgresql 数据库。我尝试了以下...
postgresql.conf
配置文件
listen_addresses = '*'
pg_hba.conf
pg_hba.conf
# IPv4 local connections:
host all all 0.0.0.0/0 md5
Firewall
防火墙
New inbound rule (firewall) protocols and ports > protocol type > TCP
Local port > 5432 Remote port > All
新入站规则(防火墙)协议和端口 > 协议类型 > TCP
本地端口 > 5432 远程端口 > 全部
Grab IP of remote machine
获取远程机器的IP
I copied from azure dashboard and also as indicated on top of remote desktop connection
我从 azure 仪表板复制,也如远程桌面连接顶部所示
CMD from local machine
来自本地机器的 CMD
Then from local machine tried the following.
然后从本地机器尝试以下操作。
psql -U postgres -h 13.xx.xx.xx
Error message.
错误信息。
psql: could not connect to server: Connection timed out (0x0000274C/10060) Is the server running on host "13.xx.xx.xx" and accepting TCP/IP connections on port 5432?
psql: 无法连接到服务器: 连接超时 (0x0000274C/10060) 服务器是否在主机“13.xx.xx.xx”上运行并接受端口 5432 上的 TCP/IP 连接?
I am not sure what else should be done.
我不确定还应该做什么。
回答by Shui shengbao
After you modify configuration file, you need restart it. You could use netstat -ant|findstr 5432
to check it. It should listen like below:
修改配置文件后,需要重启。你可以netstat -ant|findstr 5432
用来检查它。它应该像下面这样听:
C:\Users\shui>netstat -ant|findstr 5432
TCP 0.0.0.0:5432 0.0.0.0:0 LISTENING InHost
TCP [::]:5432 [::]:0 LISTENING InHost
It seems a firewall issue. You need open port 5432 on Azure NSG.
好像是防火墙问题。您需要在 Azure NSG 上打开端口 5432。
I test in my lab, it works for me.
我在我的实验室测试,它对我有用。