Database Connection Pool Sizing (PostgreSQL / HikariCP Formula) Calculator

Prevent DB context-switching thrash by sizing HikariCP / PgBouncer pools.

Recommended Pool Size per App Pod 5 connections/pod
Optimal Total DB Active Connections 34 connections
Total Connections Across All Pods 30 connections
Unallocated Headroom Connections 4 connections
Inputs
Try:
vCPUs
Number of vCPU cores on the primary database server.
spindles
Effective I/O parallelism factor (1–2 for NVMe SSD).
pods
Number of application pods/instances connecting directly.
Results & Graph
Recommended Pool Size per App Pod
5 connections/pod
Optimal Total DB Active Connections
34 connections
Total Connections Across All Pods
30 connections
Unallocated Headroom Connections
4 connections

Recommended Pool Size per App Pod

Graph 1 • How the inputs feed DB Connection Pool
Database Connection Pool Sizing (PostgreSQL / HikariCP Formula) Calculator • Custom Domain Schematic (Cloud SRE & Distributed Systems) databaseeffectivOut Database Vcpu Cores: 16 vCPUs • Effective Storage Spindles: 2 spindles RECOMMENDED POOL SIZE PER 5 connections/pod • Optimal Total DB Activ: 34 connections • Total Connections Acro: 30 connections Eq: OptimalTotalConnections = (DB_vC
Graph 2 • Recommended Pool Size per App Pod as Database Vcpu Cores changes (40% to 160% of current)
0 connec 4.40 connec 8.80 connec 2 6.40vCPUs 3 9.60vCPUs 4 12.80vCPUs 5 16vCPUs 6 19.20vCPUs 7 22.40vCPUs 8 25.60vCPUs
Graph 3 • Database Vcpu Cores and Effective Storage Spindles together Compares Recommended Pool Size per App Pod when Effective Storage Spindles is shifted +25% (solid) vs. −25% (dashed).
0 connec 3.58 connec 7.15 connec --- Effective Storage Spindles @ 75% 3.50 -30% 4.25 -15% 5 +0% 5.75 +15% 6.50 +30%
Summary: A 16-vCPU database server reaches peak throughput around 34 active connections; across 6 app pods, configure maxPoolSize = 5 per pod (30 total).
Summary: A 16-vCPU database server reaches peak throughput around 34 active connections; across 6 app pods, configure maxPoolSize = 5 per pod (30 total).
Interactive chart & math engine powered by CalculatorGraph

Formula: DB Connection Pool Systems Engineering Formula

OptimalTotalConnections = (DBvCPUs × 2) + EffectiveStorageSpindles
PerPodPool = floor(OptimalTotal / AppPods)
OptimalTotalConnections = (DB_vCPUs × 2) + EffectiveStorageSpindles; PerPodPool = floor(OptimalTotal / AppPods)
  • databaseVcpuCores: Database Vcpu Cores (vCPUs)
  • effectiveStorageSpindles: Effective Storage Spindles (spindles)
  • applicationPodReplicas: Application Pod Replicas (pods)

Frequently Asked Questions

Should I enter vCPUs or physical cores for a cloud database?

The formula was designed around physical cores. Many cloud vCPUs are hyperthreads, so a 16-vCPU instance may have 8 physical cores. Entering 8 gives 18 total connections and 3 per pod across six pods, against 34 and 5 for the default. Treat the two results as a range and let a load test decide where in that range you land.

What spindle count fits an SSD or a cloud volume?

The field's help suggests 1 to 2 for NVMe SSD, and 2 is the default. For a database whose active data sits in memory, storage parallelism matters little and the cores term dominates. Zero is accepted: with 16 vCPUs it gives a total of 32 instead of 34. With the default six pods the per-pod answer stays at 5, and only the headroom changes.

Why does the calculator round the per-pod pool down?

Rounding up would push the total past what the database was sized for. With 34 connections and six pods, 5.67 per pod would become 6, and six pods at 6 make 36. Rounding down keeps the fleet at 30 and leaves the remainder as headroom, which helps absorb a rolling deploy or a one-off job. Ten pods show the same effect, with 3 each and 4 spare.

What does the Over the Optimum line mean?

It means the minimum of one connection per pod already uses more than the formula's total. With 4 vCPUs and 12 pods, the database budget is 10 but twelve pods need 12, so the line shows the pods over the optimum by 2. Put a pooler like PgBouncer in front, consolidate pods, or size up the database rather than accepting the overshoot.

Is this the same as PostgreSQL max_connections?

No. max_connections is a hard cap on how many connections may exist at once, including idle ones. This calculator estimates how many should be actively running queries for good throughput. You normally set max_connections higher than the formula's total, so admin sessions, migrations and short bursts can still connect.

How should autoscaling change the pod count I enter?

Enter the most pods the autoscaler is allowed to run, not the average. Each pod opens its own pool, so a scale-out during a traffic spike multiplies the total at the worst moment. If that maximum makes the per-pod pool too small to be useful, a central pooler such as PgBouncer is usually the better fix.

Does the formula work with read replicas?

Apply it to each server separately. A replica with its own CPUs has its own budget, so a 16-vCPU replica also gets about 34 active connections. If your pods send reads to replicas and writes to the primary, they need two pools, each sized from the server it talks to and the number of pods using it.

What should I set minimumIdle to?

The HikariCP project recommends leaving minimumIdle unset so it equals maximumPoolSize, giving a fixed-size pool. With small pools like the 5 per pod in the default, shrinking and regrowing the pool saves little memory and adds connection setup work just as traffic returns, so a fixed pool is usually simpler and steadier.

My requests wait for connections. Should I raise the pool?

Check the database first. If its CPU is near full, a bigger pool adds contention and makes each query slower, so the wait moves into the database. If CPU is low while requests queue in the pool, queries are waiting on locks or I/O, and a small step up may help. Change one pod's pool and measure before rolling it out.

Does this apply to MySQL or other databases?

The reasoning, that a server can only run as many queries at once as it has cores plus a little for I/O waits, applies broadly. The specific formula comes from PostgreSQL guidance and is the one HikariCP cites. For another database, use the result as a first guess and confirm it with a load test on your own workload.

Do several worker processes in one pod change the answer?

Yes. If each pod runs several processes, and each process opens its own pool, enter the total number of processes across the fleet as the pod count. Six pods with two processes each behave like twelve pools, so the default database would give 2 connections per pool rather than 5, with 10 connections of headroom.

Sixteen vCPUs, two spindles, six pods: 5 connections each

The default describes a fairly common setup. A PostgreSQL server with 16 vCPUs, storage given an effective spindle count of 2, and an application running as 6 identical pods, each with its own HikariCP pool.

The first step is the core formula: connections = (cores x 2) + effective spindles. Here that is 16 x 2 + 2 = 34. That is the Optimal Total DB Active Connections line, and it describes the whole database, not one pod.

The second step shares that budget out. 34 divided by 6 pods is 5.67, and the calculator rounds down to 5, because rounding up to 6 would put 36 connections on a server sized for 34. That gives the headline of 5 connections per pod, 30 in total across the fleet, and 4 connections left over in the headroom line.

So the advice for the default is to set maximumPoolSize to 5 in each pod's HikariCP config. That number surprises people who are used to pools of 50 or 100 per service. The point of the formula is that a database with 16 cores can only run a limited number of queries truly at once, and stacking more connections on top adds queuing inside the database rather than throughput.

Why a small pool can beat a large one

Each active connection in PostgreSQL is served by its own backend process. A CPU core can only run one of them at a time. When there are many more busy connections than cores, the operating system switches between them, caches go cold, and locks are held for longer while their owners wait for a turn on a core.

The cores x 2 part of the formula allows for the fact that a query is not always on the CPU. Part of the time it is waiting for a disk read, a network packet or a lock, and a second connection per core can use the CPU during those gaps. The spindle term adds a little more for storage that can serve several reads in parallel.

When more requests arrive than the pool has connections, they wait in the pool's queue in the application, not inside the database. That queue is cheap and visible. You can see it in HikariCP metrics as pending threads, and tune connectionTimeout to decide how long a request waits before failing. A queue inside an overloaded database is much harder to see and much more expensive.

A practical test of this idea is to halve a pool that seems too small and measure again. Teams that try it on an overloaded database often find latency falls, because the queries that do run finish sooner and free their locks faster. The formula gives you a sensible place to start that experiment rather than guessing.

Counting cores and spindles honestly

The formula was written with physical cores in mind. Many cloud instance types sell vCPUs that are hyperthreads, two per physical core. If that applies to your database, a 16-vCPU instance has 8 physical cores, and entering 8 gives 18 total connections and 3 per pod with the default six pods. Try both numbers and treat the gap between them as the range to benchmark.

Effective spindles is the fuzzier input. It was meant for spinning disks, where each spindle could serve one seek at a time. The field's own help suggests 1 to 2 for NVMe SSD. If your working set fits in memory and queries rarely touch the disk, the storage term barely matters, and the cores term dominates.

Zero is a valid entry. With 16 vCPUs and 0 spindles, the total becomes 32, the per-pod pool stays at 5 across six pods, and headroom drops from 4 to 2. Smaller databases show the term more clearly: 8 vCPUs with 1 spindle and 3 pods gives 17 in total and 5 per pod, with 2 spare. All three inputs must be whole numbers.

How pod count splits the budget

Changing the pod count does not change the 34-connection total. It only changes how the total is divided and how much is lost to rounding down.

With one pod, it gets the whole 34 and headroom is zero. With three pods, each gets 11, which uses 33 and leaves 1 spare. With ten pods, each gets 3, which uses only 30 and leaves 4, the same headroom as the default but with much smaller pools in each pod.

If you scale on load, enter the maximum number of pods your autoscaler can reach, not the usual count. Pool size is set per pod at startup. When the autoscaler doubles the fleet in a traffic spike, every new pod opens its own pool, and the total can sail past the database's comfortable limit at exactly the moment the database is busiest.

Rolling deployments cause a similar spike. While new pods start before old ones stop, both sets hold connections. The headroom line is what absorbs that overlap, so a design with zero headroom and a surge of extra pods will briefly overshoot the target.

When pods outnumber the connection budget

The per-pod answer is never allowed to fall below 1, since a pool of zero connections cannot serve any traffic. That floor creates an odd result for small databases with many pods.

Try 4 vCPUs and 12 pods. The formula gives 4 x 2 + 2 = 10 connections for the whole server. Ten divided by twelve rounds down to zero, so the calculator sets 1 per pod. Twelve pods at one connection each is 12, and the last line changes its label to Over the Optimum by (1-per-pod Minimum), showing 2 connections. That line is the calculator telling you the design is already over budget.

The usual fixes are to put a pooler such as PgBouncer between the pods and the database, so many client connections share a small number of server connections, to merge pods that are really separate deployments of the same light service, or to move to a bigger database. A pool of 1 per pod also means a single slow query blocks that pod completely, which is a separate reason to avoid it.

Other clients that share the same server

The calculator assumes your application pods are the only thing connecting. Real databases also serve migration jobs, scheduled tasks, analytics queries, admin consoles, monitoring agents and sometimes a second application. Each of them takes connections from the same cores.

List those clients and subtract their typical active connections from the 34 before you divide by pods. If a nightly report uses 2 connections and a background worker uses 3, the budget left for the web pods is 29, which still gives 4 per pod across six pods rather than 5.

The formula also counts connections that are actively running queries. Idle connections cost memory but not CPU. That is why PostgreSQL max_connections is usually set well above the formula's number: it is a hard ceiling on how many connections can exist, while this calculator estimates how many should be busy at once.

Connection-hungry tools deserve a special look. Some ORMs open a separate pool per process, and a pod running several worker processes multiplies the per-pod figure by the process count. Count processes, not pods, if that applies to your stack.

Setting HikariCP to the number

In HikariCP, the property to set is maximumPoolSize. The HikariCP documentation recommends leaving minimumIdle unset, which makes it equal to the maximum and keeps a fixed-size pool. With a pool of 5, there is little benefit in letting it shrink and then paying the cost of opening connections again when traffic returns.

If you use PgBouncer in transaction mode, apply the formula to the pooler's server-side pool, the connections from PgBouncer to PostgreSQL. The application pods can then hold more client connections to PgBouncer, because those are cheap.

Read the output as a starting point. Load test the service with the suggested pool, watch database CPU, query latency and pool wait time, and adjust in small steps. If the database CPU sits low while requests queue in the pool, the workload spends more time waiting on I/O or locks than the formula assumes, and a slightly larger pool may help.

A worked check at 24 vCPUs

Scaling the database up is the other lever. At 24 vCPUs, the total becomes 24 x 2 + 2 = 50. Across the same six pods, 50 / 6 = 8.33, which rounds down to 8 per pod, 48 total, and 2 connections of headroom.

Going from 16 to 24 vCPUs, a 50% bigger server, raised each pod's pool from 5 to 8. The rounding happens to work in your favour here, since the leftover shrank from 4 to 2.

If you are deciding between a bigger database and more pods, run both through the calculator. More pods without a bigger database only slices the same 34 more thinly. A bigger database raises the total, and it is the only change in the formula that adds real concurrent query capacity.

Price the two options against each other too, since a larger instance and a few more application pods rarely cost the same.