Sub topic 15
Troubleshooting Common PgBouncer Problems
Assume you know basic SQL, psql, PostgreSQL roles, Linux commands, and the difference between a client connection and a PostgreSQL server connection. Troubleshoot PgBouncer in layers: confirm that the listener is reachable, verify authentication, inspect pool state, and then check PostgreSQL.
A diagnostic path
PgBouncer can accept a client connection while the client still waits for a PostgreSQL server connection. The admin console distinguishes these states.
The client cannot reach PgBouncer
A connection-refused error usually means that no process is listening at the requested address and port. Check the process and socket first.
systemctl status pgbouncer
ss -ltnp | grep 6432
psql -h 127.0.0.1 -p 6432 -U app_user appdbIf PgBouncer is running, compare the application's host and port with listen_addr and listen_port. A listener bound to 127.0.0.1 accepts local connections only. A remote application needs an appropriate listen address and a firewall rule. Apply configuration changes through the admin console:
RELOAD;A syntax error can prevent a reload. Check PgBouncer's log after changing pgbouncer.ini.
Authentication fails
An error such as password authentication failed can come from PgBouncer or PostgreSQL. Confirm that the username exists in auth_file, or that auth_query returns the expected username and password hash.
For an auth_file, each entry must use the expected quoted format:
"app_user" "SCRAM-SHA-256-hash"If auth_query is used, check that the lookup function is executable by auth_user, returns both columns, and can read the password hash. PostgreSQL's pg_hba.conf still applies after PgBouncer authenticates the client, so verify both authentication layers.
Clients wait for a server connection
A client waiting in transaction pooling often means every server slot for its database and user is busy. Inspect the pool:
psql -h 127.0.0.1 -p 6432 -U pgbouncer_admin pgbouncerSHOW POOLS;
SHOW CLIENTS;
SHOW SERVERS;
SHOW STATS;In SHOW POOLS, compare cl_waiting with sv_active and sv_idle. Waiting clients need shorter transactions, more available server connections, or less application concurrency. Increasing max_client_conn alone does not create PostgreSQL capacity. It can increase memory use and the number of waiting clients.
PostgreSQL refuses new server connections
If PgBouncer logs errors about too many connections, compare its possible server connections with PostgreSQL's max_connections. Add the connection budget from every pooler instance, application, maintenance job, and monitoring tool. Leave room for administrative access.
A reserve pool helps with short bursts, but it does not fix a permanently overloaded database.
Session state behaves unexpectedly
Transaction pooling gives a server connection back after COMMIT or ROLLBACK. Session-level settings, temporary tables, session advisory locks, and session-bound cursors may therefore be unavailable on the next transaction. Use SET LOCAL inside a transaction where possible, or use session pooling for workloads that require persistent session state.
Prepared statements can also fail if the client expects them to remain on one server connection. Use a driver mode compatible with transaction pooling, configure PgBouncer support for the relevant prepared-statement behavior, or choose session pooling.
Exercise
SHOW POOLS reports waiting clients, but PostgreSQL has unused capacity. What should you inspect next?
Show answer
Check the pool's user and database limits, the configured default_pool_size, active transactions, and whether another pool or PgBouncer instance consumes the available connection budget.