DBAtlas · 数据库运维图谱

显示 PgBouncer 连接池、统计信息和连接(SHOW POOLS/STATS/CLIENTS/SERVERS)

PostgreSQLPgBouncer

命令

# Connect to the PgBouncer admin console (user must be in admin_users/stats_users):
psql -h 127.0.0.1 -p 6432 -U pgbouncer -d pgbouncer -X
SHOW POOLS;    -- if cl_waiting > 0 and maxwait grows, the pool is saturated
SHOW STATS;    -- per-database total/average query, transaction and wait times
SHOW CLIENTS;  -- client connections (state, source address, linked server connection)
SHOW SERVERS;  -- server connections opened to PostgreSQL
SHOW CONFIG;

作用

针对每个数据库/用户连接池,显示活动和等待中的客户端(cl_active、cl_waiting)、活动/空闲的服务端连接(sv_active、sv_idle)、最长等待时间(maxwait)以及查询/事务计数器。

适用场景

当应用报告连接失败/超时、规划连接池大小,以及在维护前查看活动连接时。

注意

管理控制台不接受 SQL,只运行 PgBouncer 命令。如果 cl_waiting 持续偏高,请先检查服务端是否有长事务或锁;盲目调大 default_pool_size 会把 PostgreSQL 推向 max_connections 上限并带来内存压力。SHOW STATS 的值是累计值;平均值指 stats_period 区间。

在 DBAtlas 中打开 →

相关内容