OOmnistu

Blog / Databases

Databases

Database connection pooling explained: why apps fall over at scale

Every PostgreSQL connection costs a backend process. What a pooler does, session vs transaction vs statement modes, and the failure modes to test.

OOmnistu
Reviewed 2026-11-19 · 4 min read

An application that behaves perfectly in development can fall over in production with one blunt error: "too many connections". The cause is usually architectural, not a bug. Every client connection to PostgreSQL costs the database real resources, and the default instinct - let every worker, thread or serverless function open its own connection - does not survive contact with production concurrency. Connection pooling is the standard fix.

This guide explains why connections are expensive, what a pooler does, and the behavior differences that matter before you point an app at one. It follows the PgBouncer and PostgreSQL documentation, checked on 19 November 2026. Pooler configuration values for your workload should come from your own load tests, not from this article.

Why PostgreSQL connections are expensive

PostgreSQL uses a process-per-connection model: each client connection is served by its own backend process, with its own memory. The PostgreSQL documentation's connection and authentication settings exist precisely because the number of concurrent connections is a limited resource with a configured ceiling. Hundreds of mostly-idle connections still hold backend processes open, and every new connection pays a startup cost - process creation, authentication, and session setup - before a single query runs.

Two common architectures make this worse. Horizontally scaled app servers multiply connections by instance count, and scale-to-zero platforms (containers, functions) churn connections constantly, so the database spends its effort opening and closing sessions instead of answering queries.

What a pooler actually does

A connection pooler sits between your application and the database. Applications open as many client connections to the pooler as they like; the pooler maintains a small, bounded set of real server connections to PostgreSQL and assigns them to client work as needed. From the database's perspective, a thousand app connections become a few dozen long-lived ones.

The three pooling modes, and why the choice changes app behavior

PgBouncer's documentation defines three modes, and they are not interchangeable:

Application-level pools vs an external pooler

Most frameworks have a built-in pool, and it is worth having - it bounds connections per app instance and reuses them. It does not solve the multiplication problem: twenty app instances with a pool of ten each is still two hundred database connections. An external pooler bounds the total at the database edge. Larger deployments commonly run both: a small in-app pool for locality, an external pooler as the hard ceiling.

Sizing and failure modes to test

Pooling sits next to the rest of database hygiene, not in place of it. For the query side, see how indexes fix slow queries and reading a query plan without guesswork; for correctness under concurrency, PostgreSQL isolation levels; and for recovery, logical backups vs point-in-time recovery.

Sources

Drafted with AI assistance from these sources. Pool sizes and modes depend on your schema, framework and workload; verify with your own load tests before changing production settings.