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

PgBouncer连接PostgreSQL时DNS解析失败问题求助

解决PgBouncer连接PostgreSQL时的server DNS lookup failed错误

解决方案

  • 直接使用IP地址替代localhost
    修改PgBouncer配置文件的[databases]段,将host=localhost替换为host=127.0.0.1(IPv4)或host=::1(IPv6),绕过DNS解析步骤:

    [databases]
    postgres = host=127.0.0.1 port=5435
    tags = dbname=postgres host=127.0.0.1 port=5435 user=postgres password=Admin@!23 auth_user=postgres
    
  • 检查并修复Windows hosts文件
    打开C:\Windows\System32\drivers\etc\hosts文件(需管理员权限),确认存在以下映射:

    127.0.0.1       localhost
    ::1             localhost
    

    若缺失则添加,保存后重启PgBouncer服务。

  • 验证PostgreSQL的监听配置
    确认PostgreSQL的postgresql.conf中:

    • port = 5435(与PgBouncer配置的后端端口一致)
    • listen_addresses包含127.0.0.1/::1或设为*
      重启PostgreSQL后,用以下命令测试直接连接是否正常:
    psql -U postgres -h 127.0.0.1 -p 5435
    
  • 重启PgBouncer服务
    修改配置后必须重启服务才能生效,可通过Windows服务管理器操作,或执行命令:

    net stop pgbouncer
    net start pgbouncer
    

错误原因分析

日志中的WARNING DNS lookup failed: localhost: result=11001表明,PgBouncer无法通过DNS解析localhost对应的IP地址(Windows错误码11001表示找不到主机),导致无法建立与后端PostgreSQL的连接。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 10:40:29