我正在尝试启用 Postgresql 9.3 以接受 CentOS6 上的远程连接。我在 iptables 中打开了端口,在 pgconf 文件中将端口设置为 5432,将 listen_addresses 设置为 '*'(接受所有连接),并允许 pg_hba 中的地址与主机全部 0.0.0.0/0 信任。 postmaster 在 5432 上运行。但是,我仍然收到以下错误。如何获得有效连接?
错误:
could not connect to server: Connection refused
Is the server running on host "50.63.141.236" and accepting
TCP/IP connections on port 5432?
pg_hba.conf 文件的相关部分:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
#opens postgres to the internet
host all all 0.0.0.0/0 trust
iptables -L 的相关输出:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:postgres
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:postgres
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:postgres
最后,证明 postmaster 正在运行。
EN 1433/sshd
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LIST
最佳答案
更改 listen_addresses
后您还没有重新启动 PostgreSQL .它仍在收听 127.0.0.1
,即仅环回。或者您为不同的 PostgreSQL 安装编辑了配置文件。
如果您连接到主机 127.0.0.1
端口 5432
它会工作的。或者确保您编辑了正确的配置并重新启动(不仅仅是重新加载)PostgreSQL。
关于Postgresql Centos 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23193580/