What's Actually Happening
PgBouncer rejects new client connections because maximum limit reached. Applications cannot connect to PostgreSQL.
The Error You'll See
```bash $ psql -h pgbouncer -U myuser -d mydb
psql: error: connection to server at "pgbouncer" (10.0.0.1), port 6432 failed: FATAL: sorry, too many clients already ```
Why This Happens
- 1.max_client_conn too low
- 2.Connection leak
- 3.Pool exhausted
- 4.Long-running transactions
- 5.Insufficient pool size
Step 1: Check Current Connections
psql -h pgbouncer -U admin -d pgbouncer -c "SHOW CLIENTS;"
psql -h pgbouncer -U admin -d pgbouncer -c "SHOW POOLS;"Step 2: Check Configuration
cat /etc/pgbouncer/pgbouncer.ini
grep max_client_conn /etc/pgbouncer/pgbouncer.ini
grep default_pool_size /etc/pgbouncer/pgbouncer.iniStep 3: Increase Client Limit
# In pgbouncer.ini
max_client_conn = 1000
default_pool_size = 20
min_pool_size = 5
reserve_pool_size = 5Step 4: Check Pool Settings
[databases]
mydb = host=localhost port=5432 dbname=mydb pool_size=30Step 5: Kill Idle Connections
psql -h pgbouncer -U admin -d pgbouncer -c "SHOW CLIENTS;" | grep idleStep 6: Restart PgBouncer
systemctl restart pgbouncer
systemctl reload pgbouncerStep 7: Check File Descriptors
ulimit -n
ls /proc/$(pidof pgbouncer)/fd | wc -lStep 8: Increase System Limits
# In /etc/security/limits.conf
pgbouncer soft nofile 65535
pgbouncer hard nofile 65535Step 9: Monitor Connections
watch -n 5 'psql -h pgbouncer -U admin -d pgbouncer -c "SHOW POOLS;"'Step 10: Check Backend Connections
psql -h localhost -U postgres -c "SELECT count(*) FROM pg_stat_activity;"Related Issues
- [Fix PgBouncer Connection Pool Exhausted](/articles/fix-pgbouncer-connection-pool-exhausted)
- [Fix PostgreSQL Connection Timeout](/articles/fix-postgresql-connection-timeout)