Sub topic 11
Using the PgBouncer Admin Console
Assume you know basic SQL, can use psql, and have already configured PgBouncer to listen on 127.0.0.1:6432. The admin console is a special database-like interface for inspecting and controlling PgBouncer. It does not provide access to application tables.
Connecting to the console
Connect to the database named pgbouncer through PgBouncer’s listening port:
psql -h 127.0.0.1 -p 6432 -U pgbouncer_admin pgbouncerThe username must be listed in admin_users in pgbouncer.ini. A user in stats_users can run permitted monitoring commands but cannot perform every administrative action.
PgBouncer authenticates this login using its configured auth_file or auth_query. The database name pgbouncer is reserved for the console. If you connect to appdb, PgBouncer forwards the connection to PostgreSQL instead.
Inspecting pools and connections
Run these commands inside the console:
SHOW POOLS;
SHOW STATS;
SHOW CLIENTS;
SHOW SERVERS;SHOW POOLS is usually the first command to run. It shows one row for each database and user pool. Important columns include:
cl_active: clients currently using a server connection.cl_waiting: clients waiting for a server connection.sv_active: server connections currently processing work.sv_idle: open server connections available for reuse.maxwait: how long the oldest waiting client has waited.pool_mode: the mode used by that pool.
A nonzero cl_waiting value means demand is higher than the available server connections at that moment. A high or continuously increasing maxwait indicates that clients are experiencing queueing.
SHOW CLIENTS lists connections from applications to PgBouncer. SHOW SERVERS lists PgBouncer’s connections to PostgreSQL. Comparing these views demonstrates the pooler’s main function: many client connections can share fewer server connections.
Reloading and controlling PgBouncer
After editing pgbouncer.ini, reload the configuration without restarting the process:
RELOAD;
SHOW CONFIG;SHOW CONFIG displays configuration values and whether a setting can be changed during a reload. A setting that requires a restart will not take effect from RELOAD.
PAUSE stops PgBouncer from assigning new server connections. Existing work can finish. RESUME allows assignment again:
PAUSE;
RESUME;Use these commands only during a planned operation. Pausing a busy pool can make application requests wait.
Reading statistics
SHOW STATS reports traffic and timing for each pool. Useful fields include transaction counts, query counts, received and sent bytes, and average transaction or query time. These values help separate database slowness from pool contention:
| Observation | Likely interpretation |
|---|---|
| `cl_waiting` is high and `sv_active` is at its limit | The pool may be undersized or PostgreSQL is saturated |
| `sv_idle` is available but requests are slow | Investigate queries, locks, or network latency |
| Transaction counts rise but query time also rises | Queries or PostgreSQL resources may be the bottleneck |
Exercise
Which command should you check first when applications report that connections are waiting for PgBouncer?
Show answer
Run SHOW POOLS; and inspect cl_waiting, maxwait, sv_active, and sv_idle.