Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk5 min

Postgres Connection Pooling: Why Your App Runs Out of Connections Under Load

Connection limits multiply across app replicas and workers. Calculate total demand, identify the bottleneck, and choose between smaller pools, PgBouncer, or a carefully raised PostgreSQL limit.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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).

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.