October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Calculate DB Connection Pools for Auto-Scaling

Divide your service's safe database connection allowance by the peak number of pools, including autoscaler maximum, rollout surge and workers per pod, then verify with a scale test.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Size each application pool for the maximum number of pools that can exist at the same time, not for today’s replica count. Pick the number of database connections your service may use, divide it by the peak pool count (autoscaler ceiling, rollout surge, worker processes, separate data sources), round down, then load test. This article gives the formula, a worked example, and the pooler and proxy details that change the math.

The formula

A sound starting point:

max_pool_per_process = floor(service_connection_allowance / (ceil(max_replicas × (1 + max_surge_fraction)) × pools_per_pod))

As an Amazon Associate I earn from qualifying purchases.

This allocates a budget. It does not find a performance optimum. Query duration, transaction length, database CPU and I/O, lock contention and burst shape all still decide whether the resulting pool is fast enough.

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

Worked example

A focused autoscaling guide uses these inputs: an allowance of 180 connections, 16 maximum replicas, 25% rollout surge, and two pools per pod.

  1. Peak pods: ceil(16 × 1.25) = 20
  2. Peak pools: 20 × 2 = 40
  3. Per-pool maximum: floor(180 ÷ 40) = 4

That is the guide’s illustration, not a benchmark or a universal setting.

A second, purely illustrative calculation with a multi-worker web server: allowance 200, 10 maximum replicas, 25% surge, 4 worker processes per pod, each with its own pool. Peak pods are ceil(12.5) = 13, peak pools are 52, and floor(200 ÷ 52) = 3. Each worker gets 3 connections, so the real lever is often worker count, not pod count.

The inputs, one by one

Input What to use Common mistake
Connection allowance This service’s share of usable backend connections, after reserving capacity for admin access, migrations, monitoring, other applications, readers/replicas, failover and a safety margin Using the database’s advertised maximum
Maximum replicas The autoscaler’s configured ceiling Using the current replica count
Rollout surge Replicas temporarily allowed above the desired count during a rolling update (16 at 25% surge can mean 20 pods) Ignoring deploys that happen while traffic is at peak
Pools per pod Every process and every independent pool: workers per pod, plus separate read and write data sources Assuming one pool per pod

Connection allowance

Start from the database’s real usable connection budget and subtract everyone who is not this service. If you front the database with a proxy, the proxy’s permitted backend connections become the backend budget, and application-to-proxy pools are sized separately (see below).

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

Check how your pool library behaves

Verify whether the pool creates connections lazily or eagerly, what its minimum idle setting is, how long connections live, and how its acquisition queue behaves. A pool with a nonzero minimum claims its share the moment a pod starts, which is exactly the surge moment. Lazy pools may hide an overcommitment until traffic arrives.

What happens when the answer is too small

If the per-pool result is 1 or 2, requests will queue for connections. A smaller pool protects the database but moves pressure into wait time and timeouts. Options, in rough order of preference:

  • Cut pools per pod (fewer workers, or share one pool across read paths where sensible).
  • Lower the autoscaler ceiling or surge fraction if the database, not the app, is the bottleneck.
  • Put a pooler or proxy between the app and database so many client connections share fewer backend connections.
  • Increase database capacity. Do not simply raise the database’s connection limit to hide a pool multiplication problem; more backend connections add memory and contention cost without adding throughput.

Poolers and proxies change the budget

With a pooler there are two separate budgets: client connections into the pooler, and server connections to the database. Size them independently.

PgBouncer

PgBouncer’s documentation describes three pool modes. In session mode the server connection is released when the client disconnects. In transaction mode it is released after the transaction; the documentation puts it as “transaction — Server is released back to pool after transaction finishes.” In statement mode it is released after each query, and multi-statement transactions are disallowed.

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

default_pool_size is the maximum number of server connections per user/database pair, and per-database or per-user settings can override it. The client ceiling, max_client_conn, is a distinct setting. Raising it can require higher OS file-descriptor limits, and the documentation gives theoretical maximum file-descriptor calculations based on client count and pool count. When several user/database pairs exist, multiply accordingly when checking the total against the database limit.

Amazon RDS Proxy

AWS’s documentation distinguishes client connections to the proxy from backend connections to the database. The backend cap is MaxConnectionsPercent, a percentage of the target’s max_connections; the proxy does not pre-create the full allowance. AWS recommends setting it at least 30% above the maximum recently monitored usage, and notes that redistribution of proxy capacity may need more headroom. Watch DatabaseConnections, MaxDatabaseConnectionsAllowed and DatabaseConnectionsBorrowLatency. When the proxy reaches its backend maximum, AWS documents higher query latency and increased borrow latency as the side effect.

You can still pool in the application in front of the proxy to avoid repeatedly establishing client-to-proxy connections. Those client connections aren’t bound by the same numeric ceiling as backend connections, so match pool lifetimes and idle timeouts to the proxy’s enforced client limits.

Pinning

Session state such as SET commands or temporary objects can pin a client connection to a backend connection, reducing multiplexing. An idle pinned client keeps its backend connection unavailable for reuse, so client counts alone don’t show backend use. Inspect proxy logs and metrics for pinning.

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

For scale: an AWS Prescriptive Guidance test application reached 20,000 client connections while the database instance was capped at 187 concurrent connections (the opened document shows no year). Treat it as one AWS test, not a capacity promise or an expected ratio.

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

Validate with a scale test

  1. Configure the autoscaler at its real maximum and the deployment at its largest permitted surge.
  2. Graph replica and process counts beside total database backend connections.
  3. Trigger a scale-out and a rolling deploy; note the moment new pods start and whether pools connect eagerly or lazily.
  4. Track pool in-use, idle and waiting counts, acquisition latency and timeouts, and query latency. On RDS Proxy add borrow latency and pinning metrics.
  5. Confirm backend connections stay under the allowance with margin, and that acquisition waits stay within request timeouts.

Recalculate whenever the replica ceiling, surge policy, worker count, data sources, database limits or other workloads’ shares change. The cited official sources document connection caps and proxy behavior; none establishes a universal best pool size, so the final value depends on your own capacity and measurements.

Checklist

  • Divide the service’s safe allowance by the peak number of independent pools.
  • Use the autoscaler maximum and include surge.
  • Multiply by workers and data sources per pod.
  • Treat pooler client connections and backend connections as separate budgets.
  • Monitor wait and borrow latency, since small pools shift pressure into queues.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.