微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

psql不能连接到PostgreSQL服务器(postmaster)在IP和端口5432?

请在回覆之前阅读,因为它可能发生重复.我正在运行我的postmaster(postgres)服务器.看到下面的’sudo netstat -anp | grep 5432’输出
tcp  0  0 127.0.0.1:5432    0.0.0.0:*     LISTEN      29606/postmaster       
unix  2      [ ACC ]     STREAM     LISTENING     1650581 29606/postmaster /var/run/postgresql/.s.PGsql.5432
unix  2      [ ACC ]     STREAM     LISTENING     1650582 29606/postmaster    /tmp/.s.PGsql.5432

我可以使用localhost连接

psql -h localhost (OR 127.0.0.1) -d <DB> -U user -W

但是当我尝试使用tcp从其他主机连接时,通过指定

psql -h ip_add_postmaster -d <DB> -U user -W

它抛出:

psql: Could not connect to server: Connection refused
Is the server running on host XXXXXX and accepting TCP/IP connections on port 5432?

这里有什么问题?

pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only                  
local   all             all                                     peer  
# IPv4 local connections:                                             
host    all             all             127.0.0.1/32            md5   
# IPv6 local connections:                                             
host    all             all             ::1/128                 md5

在postgresql.conf中,

listen_addresses = 'localhost,127.0.0.1,ip_add_postmaster'

Note: ip_add_postmaster is same as my Elastic IP and not public DNS. If this information
matters.

在这里做错了什么?机器托管在Amazon EC2上,并打开端口5432.

当你的netstat输出显示为127.0.0.1:5432,这是localhost.这只能从localhost连接;)

在你的配置中设置listen_addresses =’*’,它将工作.

[编辑]
其他要检查的东西:

>亚马逊防火墙是否阻止任何东西?
iptables是否阻塞任何东西?

但首先要确保收听地址是正确的,你的netstat输出显示它不会这样工作.

原文地址:https://www.jb51.cc/postgresql/192555.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐