Your app can run out of PostgreSQL connections even when its pool setting looks modest: pool limits usually apply per process or worker, so replicas multiply the total. PostgreSQL also has a finite server connection ceiling. First calculate the deployment-wide maximum and measure what happens during failures; then decide whether to reduce application pools, add PgBouncer, or cautiously raise the server limit.
Why connections run out as load grows
A connection pool reuses database connections and limits how many a particular process can open. It does not necessarily set a single limit for the whole application. If every worker, process, or server replica owns a separate pool, each can open up to its own configured maximum.
As an Amazon Associate I earn from qualifying purchases.
For a first-pass upper bound, calculate:
maximum app-side connections = replicas × worker/process count per replica × pool maximum per worker/process
For example, a service with 4 replicas, 3 workers per replica, and a pool maximum of 10 per worker could allow up to 120 application connections. That is a planning example, not a recommended pool size; libraries and deployment behavior can affect the actual count.
#1 Best Overall
Add connections from every service and workload that uses the database: background workers, scheduled jobs, migration processes, monitoring, administration, and other applications. Posit’s deployment guidance illustrates how per-node pools multiply across a cluster and includes an operational metrics pool in that product’s default setup; those are Posit Connect specifics, not general PostgreSQL defaults (Posit Connect pool guidance).
What PostgreSQL’s connection limit means
PostgreSQL controls the maximum number of concurrent server connections with max_connections. PostgreSQL 18 documentation says its default is typically 100, but that is neither a universal default across hosted services nor a capacity recommendation. Reserved connection slots affect which clients can still connect near the limit, so compare your calculated demand with the database’s actual configuration and provider limits—not just the nominal setting (PostgreSQL 18 connection settings).
Increasing max_connections is not free: PostgreSQL allocates some resources based directly on the setting, and it can only be changed at server start. A larger limit may allow more sessions, but it does not guarantee higher throughput. If concurrent work overwhelms available resources, contention can increase latency and reduce throughput (PostgreSQL community guidance on connection counts).
Recommended Free Tools
Diagnose the failure before changing pool sizes
Capture connection and pool behavior during the period when errors occur. A snapshot taken after traffic subsides can miss a brief peak or queue. Compare the app-side pool maximum and active/idle counts with the database’s current connections, configured ceiling, and any reserved capacity.
- Count the configured ceiling: apply the formula above to every process and service, then add jobs and operational clients.
- Measure waiting and timeouts: check application pool wait time and connection-acquisition errors. The exact metric names depend on your driver or framework.
- Inspect the database: distinguish a server at its connection ceiling from clients failing earlier due to application or provider limits.
- Look for long-held connections: investigate slow queries, long transactions, idle-in-transaction sessions, and code that checks out a connection well before using it or returns it late.
If you use PgBouncer, its usage statistics expose current client and server connection counts as well as maxima. That helps distinguish many app clients queued behind a smaller server pool from a pooler that has itself reached its client limit (PgBouncer usage statistics).
Choose a remedy based on the bottleneck
| Remedy | When it fits | Trade-off to check |
|---|---|---|
| Reduce per-process pool maxima or replica count | The aggregate configured ceiling exceeds the database connection budget, or pools reserve more connections than workloads need. | Less simultaneous database work may mean more waiting in the application; measure pool wait latency and throughput. |
| Add PgBouncer | Many application clients need to share a smaller, controlled set of PostgreSQL server connections. | Pooling mode affects session-state behavior and adds a component to configure and operate. |
Raise max_connections |
Measured demand justifies more concurrent server sessions and the database has resources and provider support for them. | More connections consume server resources; the setting requires a server restart to change. |
| Shorten connection hold time | Connections are occupied by long queries, long transactions, idle-in-transaction work, or unnecessarily early checkout. | Requires identifying and correcting the workload or application behavior that holds connections. |
These remedies address different constraints. A pooler can queue clients rather than letting every client consume a server connection, while reducing pool maxima controls application-side concurrency. Raising the database limit changes the ceiling, not the amount of useful work the server can perform. Choose using server connection demand, queueing and wait latency, PostgreSQL resource cost, operational complexity, and whether the application depends on session state.
Rank #4
What PgBouncer pooling modes change
PgBouncer offers session, transaction, and statement pooling. They differ in when a PostgreSQL server connection becomes available to serve another client; the choice can change application behavior, not just performance (PgBouncer configuration reference).
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Session pooling
The server connection returns to the pool when the client disconnects. This retains a connection for the client’s session, so it offers less sharing when clients remain connected but is the mode most aligned with session-bound behavior.
Transaction pooling
The server connection returns to the pool when a transaction ends. This can let many client connections share fewer server connections when their database work is intermittent. Before using it, check whether the application relies on state that persists across transactions, including session variables, temporary tables, advisory locks, or session-level prepared-statement behavior.
Prepared-statement compatibility depends on versions and configuration. PgBouncer’s FAQ says transaction pooling can track prepared statements beginning with version 1.21.0 when max_prepared_statements is set to a non-zero value. The FAQ also notes constraints involving PHP/PDO versions and a JDBC configuration consideration; verify the deployed PgBouncer and driver versions rather than assuming compatibility (PgBouncer FAQ).
Statement pooling
The server connection returns after each query, and transactions spanning multiple statements are disallowed. That restriction makes this mode unsuitable for application flows that need multi-statement transactions.
Configure limits with the whole topology in mind
PgBouncer’s configuration reference documents defaults of 20 server connections for default_pool_size per user/database pair and 100 client connections for max_client_conn. These are PgBouncer configuration defaults, not PostgreSQL limits or sizing recommendations. The number of user/database pools, deployment topology, and server capacity all matter. The reference also warns that increasing max_client_conn may require a higher operating-system file descriptor limit (PgBouncer configuration reference).
Before applying a change, confirm the actual values in your PostgreSQL provider and PgBouncer configuration, determine whether a PostgreSQL restart is required, and check operating-system and provider constraints. Treat pool sizes as concurrency controls: choose them to fit the database’s capacity and the work that needs to run at once, then validate against observed wait time, connection counts, and workload performance.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




