我试图连接postgresql,但我得到这个错误。
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
我的pg_hba.conf文件是这样的。
TYPE DATABASE USER CIDR-ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
如果有人能解释一下这里有什么问题,我将不胜感激。
1条答案
按热度按时间tcbh2hod1#
你所引用的错误与此无关
pg_hba.conf
; 这是连接失败,而不是授权连接失败。执行错误消息中所述的操作:
检查主机名和端口是否正确,以及邮局主管是否接受tcp/ip连接
您尚未显示产生错误的命令。假设你正在连接
localhost
港口5432
(标准postgresql安装的默认设置),然后:postgresql没有运行
postgresql没有侦听tcp/ip连接(
listen_addresses
在postgresql.conf
)postgresql只监听ipv4(
0.0.0.0
或者127.0.0.1
)你正在ipv6上连接(::1
)反之亦然。在一些具有奇怪ipv6套接字行为的旧macosx版本和一些旧windows版本上,这似乎是一个问题。postgresql正在另一个端口上侦听您正在连接的端口
(不太可能)有一个
iptables
规则阻止环回连接(如果您没有连接到
localhost
,它也可能是一个阻止tcp/ip连接的网络防火墙,但我猜你使用的是默认值,因为你没有说)。所以。。。检查这些:
ps -f -u postgres
应列出postgres
过程sudo lsof -n -u postgres |grep LISTEN
或者sudo netstat -ltnp | grep postgres
应该显示postgresql正在侦听的tcp/ip地址和端口顺便说一句,我想你一定是老版本了。在我的9.3安装中,错误更为详细: