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

如何解决PostgreSQL搭配pgbouncer时的Segmentation Fault问题

连接pgBouncer管理库时出现Segmentation Fault的排查与解决

问题详情

执行psql连接pgBouncer管理库时触发段错误:

[postgres@test:/pgdata/pg-15/data]$ psql -U [myusername] -h localhost -d pgbouncer -p 6432
Password for user [myusername]:
Segmentation fault (core dumped)

pgBouncer日志仅记录登录尝试和客户端意外EOF,无有效错误详情:

2024-06-25 16:44:01.642 KST [36557] LOG C-0xb6b740: pgbouncer/postgres@[::1]:42698 login attempt: db=pgbouncer user=[username] tls=no
2024-06-25 16:44:02.805 KST [36557] LOG C-0xb6b740: pgbouncer/postgres@[::1]:37478 login attempt: db=pgbouncer user=[username] tls=no
2024-06-25 16:44:02.895 KST [36557] LOG C-0xb6b740: pgbouncer/postgres@[::1]:37478 closing because: client unexpected eof (age=0s)

核心配置(过滤注释后):

[databases]
postgres = host=localhost port=5333 dbname=postgres

[users]
[pgbouncer]
logfile = /pgdata/pg-15/data/pgbouncer.log
pidfile = /tmp/pgbouncer.pid
listen_addr = *
listen_port = 6432
unix_socket_dir = /tmp
auth_type = scram-sha-256
auth_file = /etc/pgbouncer/userlist.txt
admin_users = [myusername]
so_reuseport = 1

已确认userlist.txt采用"[myusername]" "SCRAM-SHA-256$ ..."格式,密码与PostgreSQL的pg_authid.rolpassword值完全一致。

排查与解决步骤

1. 验证版本兼容性

段错误常源于版本不匹配,尤其是SCRAM认证相关:

  • 执行pgbouncer -V确认版本≥1.14(SCRAM-SHA-256从1.14开始正式支持),低于此版本直接升级到最新稳定版。
  • 确认PostgreSQL版本(10+默认启用SCRAM),确保pgBouncer版本对应该版本的兼容要求。

2. 检查auth_file格式细节

即使格式看似正确,隐性错误可能触发崩溃:

  • 确保userlist.txt使用英文双引号,无中文引号或多余转义字符。
  • 验证密码字符串完整性:从pg_authid.rolpassword复制时,确保包含完整的SCRAM-SHA-256$...段,无截断或多余空格。
  • 测试临时用户:创建测试用户CREATE USER testuser WITH PASSWORD 'testpass';,复制其SCRAM密码到userlist.txt,用psql -U testuser -h localhost -d pgbouncer -p 6432测试,排除原用户密码问题。

3. 启用调试日志获取详情

修改pgbouncer.ini提升日志级别:

[pgbouncer]
log_level = debug

重启pgBouncer后重试连接,查看日志中是否有段错误发生时的调用栈或具体错误提示。

4. 检查系统依赖兼容性

  • 执行ldd $(which pgbouncer)查看依赖的libpq.so版本,对比ldd $(which psql)的libpq版本,若差异较大,可能导致兼容性问题,需统一依赖版本。
  • 若生成了核心转储文件,用gdb pgbouncer core分析转储,定位段错误发生的具体代码位置,判断是pgBouncer自身bug还是依赖库问题。

5. 简化配置排除干扰

暂时禁用非必要配置项测试:

  • 注释so_reuseport = 1,重启pgBouncer后重试连接。
  • 临时将auth_type改为md5(同步修改userlist.txt的密码为md5哈希),测试是否是SCRAM认证流程导致的崩溃。

6. 确认admin_users配置正确性

确保admin_users中的用户名与userlist.txt中的用户名完全一致(大小写敏感),无拼写错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 23:34:58