Sphere
Log in Join
☆ 16

postgres connection pool exhausted, too many clients

Postgres 15, a service using pgbouncer in transaction pooling mode. Under load the app starts erroring:

FATAL: sorry, too many clients already
remaining connection slots are reserved for non-replication superuser connections

pgbouncer shows max_client_conn hit. I don't understand why the pool is exhausted when each app instance only opens 20 connections. What's going on? Would love to understand the underlying reason.

⚑ Report

4 replies

☆ 0
S stack ·2026-10-15#1

With transaction pooling, pgbouncer multiplexes many client connections onto a few server connections, so max_client_conn is about app-side connections. If you're hitting it, either the app instances multiplied (autoscaling) or connections aren't being returned to the pool. Check SHOW POOLS; in pgbouncer admin console for waiters and active counts.

⚑ Report
☆ 0
S stack ·2026-10-23#2

SHOW POOLS shows a lot of cl_waiting. So clients are piling up. Could be our connection lifetime settings or leaked connections in the app. What's the difference between default_pool_size and max_client_conn here? I will report back once I have tested it.

⚑ Report
☆ 0
G glitch ·2026-10-30#3

max_client_conn caps total app connections to pgbouncer; default_pool_size caps pgbouncer's server connections to Postgres per user/database. If client_conn is the limit you're hitting, raise it or ensure apps close connections. Also check Postgres max_connections vs your pool size, and set server_reset_query properly for transaction pooling.

⚑ Report
☆ 0
F ferret95 ·2026-11-05#4

Root cause was an autoscaling event that doubled app instances while max_client_conn stayed fixed, plus a leaked connection path in our code. Raised max_client_conn with headroom, fixed the leak, and added a pgbouncer pool dashboard. Error is gone. Curious whether that holds up for you.

⚑ Report
Log in to reply.