Skip to content
gohacks.dev
Databases

Connection Pool Size Calculator

Work out how many database connections a pool needs from the database's cores, and check whether your app servers' workers exceed max_connections.

Free · No sign-up · Your inputs stay in your browser

Input

Size a database connection pool

Output

17 active connections

Pool size per instance

4

16 across 4 instances

Connections workers could open

64

Within the 97 the server accepts.

PgBouncer

max_client_conn = 100 default_pool_size = 17 pool_mode = transaction

Transaction pooling breaks session state: prepared statements (before PgBouncer 1.21), SET and advisory locks.

The (cores × 2) + spindles rule comes from the PostgreSQL wiki and HikariCP's pool-sizing notes: past that, extra connections queue for CPU and disk inside the database instead of in the pool, and throughput falls. Workers can outnumber connections, because most of a request is not spent in a query; a pooler such as PgBouncer in transaction mode lets them share.

Runs in this browser. Nothing you paste is sent to a server.

Smaller pools are faster

A database with 8 cores does not run 200 queries at once; extra connections wait for CPU and disk inside the server, where they also use memory (every PostgreSQL connection is a process). HikariCP's About Pool Sizing walks through measurements where shrinking the pool cut latency. Queue in the pool, not in the database.

When workers outnumber connections

PHP-FPM, Gunicorn and Puma workers each tend to hold a connection, so 10 servers with 50 workers want 500. A pooler in transaction mode lets them share a small number of real connections, as long as the application does not depend on session state between transactions.

Share

Frequently asked questions

What happens when max_connections is reached?
PostgreSQL rejects new connections with FATAL: sorry, too many clients already, and MySQL with Too many connections. Requests fail rather than wait, unless a pool queues them.
Should I just raise max_connections?
Only with memory to spare and after measuring. Raising it moves the queue into the database, where it costs more; a pooler usually fixes the real problem.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools