【发布时间】:2013-11-23 20:48:00
【问题描述】:
请在将其作为重复回复之前阅读(因为它可能会发生)。我正在运行我的 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
我可以使用
从本地主机连接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:无法连接到服务器:连接被拒绝 服务器是否在主机 XXXXXX 上运行并接受端口 5432 上的 TCP/IP 连接?
这里有什么问题?
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 端口。
【问题讨论】:
-
@nos - 是的,在客户端机器上,我确实有 /etc/hosts 条目。从客户端机器上,我可以 ssh -A
OK。谢谢 -
@nos - 是的,我在 postgresql.conf 文件中使用了实际的 IP 地址。
-
设置
listen_addresses后是否重启了postgres?根据 netstat,它仅设置为 127.0.0.1。
标签: postgresql