Postgres服务器拒绝连接

时间:2017-01-02 12:46:13

标签: postgresql

也许这个问题重复,但我没有得到任何解决方案,我使用的是centos 7和Postgres 9.3。 通过错误连接PostgreSQL服务器时,

错误

  

连接被拒绝服务器是否在主机上运行" localhost" (:: 1)   并接受端口5432上的TCP / IP连接

即使我设置了pg_hba.config文件,但我仍然遇到同样的错误 我尝试删除postmaster.pid,但收到错误no such file and no pid exist 请告诉我解决方案

2 个答案:

答案 0 :(得分:0)

我有同样的问题,我用解释解决了这个问题:

“在黑暗中狂野刺伤:你在拥有IPv6解析器的机器上,其中localhost默认为IPv6地址::1,但postgresql.conf中的listen_addresses是设置为127.0.0.10.0.0.0而不是*,或者您使用的是使用没有透明IPv6支持的C库构建的旧版PostgreSQL。

listen_addresses更改为localhost并确保localhost解析为IPv4IPv6地址,或将其设置为::1127.0.0.1明确指定IPv4IPv6。或者只需将其设置为*即可监听所有接口。或者,如果您不关心IPv6,请与127.0.0.1联系,而不是localhost。“

参考链接here

我认为this post也可以为您提供帮助。

答案 1 :(得分:0)

尝试检查防火墙是否允许该端口连接 如果在Ubuntu命令sudo ufw status上 结果将是这样的

To                         Action      From
--                         ------      ----
22                         LIMIT       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
8000                       ALLOW       Anywhere                  
Nginx Full                 ALLOW       Anywhere                  

您可以看到不允许使用端口5432 现在运行命令sudo ufw allow 5432/tcp和 检查ufw状态
sudo ufw status现在将返回

22                         LIMIT       Anywhere                  
443                        ALLOW       Anywhere                  
80                         ALLOW       Anywhere                  
8000                       ALLOW       Anywhere                  
Nginx Full                 ALLOW       Anywhere                  
5432/tcp                   ALLOW       Anywhere      

如果这不起作用,您可能不允许IP听postgres 将listen_address = 'localhost'更改为listen_address = '*' postgres.conf 文件中。

相关问题