A connection pool reuses database sessions. Its size has to fit the shared connection limit after accounting for every application replica and other clients.
A shared connection budget
PostgreSQL caps concurrent connections with max_connections and reserves some slots for privileged roles. Estimate peak demand by multiplying the maximum pool size by the number of application replicas, then add workers, maintenance, and other clients. Include replicas that overlap during deployments.
Sessions idle in a transaction
A session marked idle in transaction is waiting for the client while a transaction remains open. It still occupies a connection and can retain locks or prevent cleanup of old row versions. Trace the caller and make sure application code commits or rolls back. A timeout can limit how long abandoned transactions stay open.
Capacity for bursts and recovery
Leave room for unexpected demand and for operators to connect during an incident. Raising max_connections increases some server resource requirements. Compare open and active sessions with pool wait time before changing the server limit or application pool sizes.