You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求诊断Ubuntu 22.04上PostgreSQL 14无法被Windows pgAdmin连接故障

PostgreSQL远程连接超时问题排查方案

1. 确认PostgreSQL监听配置是否生效

  • 检查postgresql.conf中listen_addresses是否设为'*'或包含服务器IP192.168.1.145,执行命令:
    grep listen_addresses /etc/postgresql/14/main/postgresql.conf
    
  • 重启PostgreSQL服务使配置生效:
    sudo systemctl restart postgresql@14-main
    
  • 用ss命令验证端口监听状态,正常输出需包含0.0.0.0:5432或:::5432:
    ss -tulpn | grep 5432
    

2. 验证pg_hba.conf权限规则

  • 在pg_hba.conf末尾添加允许Windows笔记本访问的规则,示例:
    host    all             all             192.168.1.67/32            scram-sha-256
    
    若需开放整个局域网,可替换为:
    host    all             all             192.168.1.0/24            scram-sha-256
    
  • 加载新规则(无需重启服务):
    sudo -u postgres psql -c "SELECT pg_reload_conf();"
    

3. 确认防火墙规则

  • 检查UFW是否允许5432端口:
    sudo ufw status
    
    若没有对应规则,执行添加命令:
    sudo ufw allow 5432/tcp
    
  • 排查iptables是否拦截流量:
    sudo iptables -L -n | grep 5432
    

4. 网络连通性测试

  • 在Windows笔记本上用PowerShell测试端口连通性:
    Test-NetConnection 192.168.1.145 -Port 5432
    
    若测试失败,检查:
    • 两台设备能否互相ping通
    • 路由器是否开启设备隔离规则
    • Windows防火墙是否拦截pgAdmin的出站流量

5. 检查PostgreSQL服务状态

  • 确认服务正常运行:
    sudo systemctl status postgresql@14-main
    
  • 用pg_lsclusters查看集群状态,需确保状态为online:
    pg_lsclusters
    

内容的提问来源于stack exchange,提问作者Lee Jenson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 23:55:13