psql: 错误: 连接到“192.168.105.1“上的服务器,端口5432失败:Connection refused Is the server running on that host an
pg除了配置客户端白名单ip之外,还需要配置服务器监听的ip。
·
问题
进pg16数据库的时候出现了如下错误:
psql: 错误: 连接到"192.168.105.1"上的服务器,端口5432失败:Connection refused
Is the server running on that host and accepting TCP/IP connections?
解决
检查pg_hba.conf白名单
打开pg白名单文件:
code /opt/homebrew/var/postgresql@16/pg_hba.conf
发现我已经配置客户端ip的白名单,内容如下:
# 客户端 IP 范围:
host all all 192.168.105.1/32 scram-sha-256
而且,已经重启了pg16数据库,但是还是报上名的错误。
检查postgresql.conf主配置文件
打开pg主配置文件:
code /opt/homebrew/var/postgresql@16/postgresql.conf
发现并没有配置对外ip。所以添加如下内容,设置服务器IP为所有:
listen_addresses = '*'
然后,重启pg16数据库:
brew services restart postgresql@16
测试
(base) ➜ ~ psql -U zhangyalin -h 192.168.105.1 -p 5432 -W postgres
口令:
psql (16.3 (Homebrew))
输入 "help" 来获取帮助信息.
postgres=#
能够正常连接。
总结
pg除了配置客户端白名单ip之外,还需要配置服务器监听的ip。
更多推荐
所有评论(0)