dkduckkit.dev

PgBouncer

Databases

PgBouncer is a lightweight connection pooler for PostgreSQL. Instead of letting every application client open a dedicated database connection (and therefore a dedicated PostgreSQL backend process), PgBouncer sits in front of Postgres and multiplexes many client connections onto a smaller pool of server connections.

Why it matters in practice

PostgreSQL connections are not “free”: each connection maps to an OS process with memory overhead, and bursts of new connections can create latency spikes or outages. PgBouncer lets you serve high client concurrency while keeping the database connection count stable, which protects latency and avoids exhausting RAM or CPU on the DB server.

Common mistakes

  • Using session pooling mode by default; for most web apps transaction pooling is the safer default (verify compatibility with prepared statements and session state).
  • Not sizing the server pool based on database CPU/IO capacity; a pool that is too large just increases contention.
  • Ignoring timeouts and retries: a saturated pool can amplify latency; use queue time as a signal to scale or shed load.