Database Connection Pool Calculator
Size database connection pools across replicas and workers while checking reserve-aware headroom, rollout surge risk and per-holder caps.| Measure | Value | Meaning | Copy |
|---|---|---|---|
| {{ row.label }} | {{ row.value }} | {{ row.context }} |
{{ item.title }}
{{ item.text }}
| App instances | Pool holders | Hard cap / holder | Peak-fit cap / holder | Copy |
|---|---|---|---|---|
| {{ row.instances }} | {{ row.holders }} | {{ row.hardCap }} | {{ row.peakFitCap }} |
A small pool setting can become a large database commitment once it is repeated across replicas and worker processes. Twelve application instances with four workers each create 48 pool holders when every worker owns its own pool. A limit of eight connections per holder can therefore expose 384 database sessions before migrations, monitoring, administration, and rollout overlap are counted.
Connection pooling keeps sessions warm and reuses them, avoiding the setup cost of opening a new database connection for every request. The pool also acts as a queue when demand exceeds the number of available sessions. A pool that is too small can make requests wait; a pool that is too large can move the queue into the database, where excessive concurrency consumes memory and leaves less room to recover from a traffic spike or a slow-query incident.
The most important planning distinction is ownership. A shared pool per application instance grows with the replica count. A separate pool inside every worker grows with both replicas and workers. Server-side poolers may add another boundary because their limits can apply to each user and database pair rather than to the application as a whole.
| Planning question | Why it changes the answer |
|---|---|
| Who owns a pool? | Determines whether workers multiply the number of holders. |
| Which database limit applies? | The effective ceiling may belong to the server, role, database, or pooler. |
| What else uses connections? | Jobs, monitoring, and operator sessions consume the same usable budget. |
| Can releases overlap? | Old and new replicas may hold pools at the same time during a rollout. |
A capacity result is a planning ceiling, not a performance optimum. The database may reach a CPU, memory, lock, or I/O bottleneck long before every connection slot is occupied. Measure waiting requests, active queries, transaction time, and database saturation under representative load before treating a calculated cap as a production setting.
How to Use This Tool:
Start with the boundary that actually limits the application, then model normal traffic and temporary scale separately.
- Choose Pool ownership from the application architecture. Select Per worker process only when every worker creates an independent pool; otherwise use Per app instance for one shared pool per replica.
- Enter App instances, Workers per instance, and Pool size per holder. Use the normal steady-state replica count. The worker count remains descriptive when the pool is shared per instance.
- Set DB max connections and Reserved connections from the effective database, role, user, or pooler limit. Add other active clients that must share the remaining budget.
- Choose Expected peak pool usage and Target free headroom. Add Deploy surge instances when old and new replicas overlap during rollout.
- Read Sizing review before adopting a cap. Resolve an over-capacity result first, then compare the hard and peak-fit per-holder caps with observed connection demand.
Interpreting Results:
Peak ready means both the modeled peak and the full configured pool stay within usable connections while preserving the requested reserve. Reserve review means capacity is not necessarily exceeded, but at least one normal, full-pool, or rollout scenario falls below the reserve target. Over capacity means the normal peak or full configured ceiling exceeds the usable database slots.
- Use Expected peak headroom to judge the normal demand assumption.
- Use Full-pool headroom as the failure-pressure check because a retry storm or slow work can fill every configured slot.
- Use Surge headroom when deployments or autoscaling temporarily increase the number of holders.
- Treat Peak-fit cap per holder as assumption-dependent. The Hard cap per holder is the safer ceiling when every pool could fill.
Technical Details:
Capacity is split into a holder model and a database budget. Pool ownership determines the holder count; the database ceiling and reserved slots determine what remains available to applications. Other active clients are then removed before a per-holder cap is calculated.
Formula Core:
For a per-worker pool, each instance contributes one holder per worker. For a shared instance pool, each instance contributes one holder.
The configured ceiling is the number of holders multiplied by the pool size. Peak demand scales that ceiling by the expected-use fraction and adds other clients.
Usable connections exclude reserved slots. The requested headroom is rounded upward to a whole connection, while caps are rounded downward so the result never exceeds the budget.
| Symbol | Meaning | Unit |
|---|---|---|
| H | Pool holders | count |
| I | Application instances | count |
| W | Workers per instance | count |
| P | Pool size per holder | connections |
| D, R | Database maximum and reserved slots | connections |
| u, h | Peak-use and target-headroom fractions | ratio |
| O | Other active clients | connections |
The peak-fit cap divides the same budget by H × u instead of H. Rollout calculations replace the normal instance count with normal instances plus surge instances. The scale table repeats these cap equations across increasing replica counts.
Status and advisory rules:
| Result | Exact condition |
|---|---|
| Over capacity | Expected peak headroom < 0, or full-pool headroom < 0. |
| Reserve review | Any checked peak, full-pool, or enabled surge headroom is below the rounded target reserve, or the active-query advisory is triggered. |
| Peak ready | No over-capacity or reserve warning condition is present. |
| Active-query advisory | When physical cores are supplied, expected peak pool draw is more than twice 2 × cores + I/O wait allowance. |
The active-query advisory is a rough concurrency signal, not a database throughput formula. Idle and waiting connections may occupy pool slots without consuming CPU, while a smaller number of expensive queries may saturate the server.
Limitations:
The model budgets connection slots; it does not predict query latency, transaction duration, lock contention, memory per backend, pool wait time, or workload throughput.
- Measure the real number of independent pools. Multi-tenant database/user pairs can create more holders than the application replica count suggests.
- Keep administrative and failover capacity outside the application budget.
- Recalculate after changing worker topology, autoscaling limits, pooler mode, database limits, or rollout strategy.
Worked Examples:
Worker-owned pools with a protected reserve
Twelve instances, four workers per instance, and eight connections per holder produce 48 holders and a 384-connection ceiling. With a database maximum of 500, 80 reserved slots, 70% expected use, and 15% target headroom, the usable budget is 420 connections and the target reserve is 63. Expected peak draw is 268.8 connections, but the full-pool headroom is only 36, so the result is Reserve review. The hard cap is seven connections per holder.
One shared pool per replica
Twelve shared instance pools of 16 connections produce a 192-connection ceiling. Against 270 usable slots, 20 other clients, 60% peak use, and 10% target headroom, expected peak total is 135.2 and full-pool total is 212. Both preserve the 27-connection reserve, so the result is Peak ready.
FAQ:
Should reserved connections include only database superuser slots?
Use the total portion of the effective connection limit that the application must not consume. That may include emergency database slots, operator access, or a reserve imposed by a role, database, or pooler policy.
Why can a server-side pooler change the holder count?
Some poolers create separate server pools for combinations such as database and user. Count those independent pools when they can be active together; counting only application replicas can understate the database commitment.
References:
- Connections and Authentication, PostgreSQL Documentation 18.
- PgBouncer configuration, PgBouncer Documentation.
- How to configure connection pooling for PostgreSQL, Simplified Guide.
- How to set connection limits in PostgreSQL, Simplified Guide.