talira

PgBouncer

Lightweight connection pooler for PostgreSQL

open sourceISCself-hostablefree

PgBouncer is a lightweight connection pooler that sits between applications and PostgreSQL, so thousands of client connections share a small number of server connections. It pools per session, per transaction or per statement: transaction pooling gives the most reuse but breaks session features such as SET, LISTEN and session advisory locks, while protocol-level prepared statements work once max_prepared_statements is set. An admin console (a virtual pgbouncer database) shows pools and clients and can pause, resume and reload without dropping clients, and several processes can share a port with so_reuseport for rolling restarts. It's written in C and released under the ISC licence.

Ways to install

Problems it solves

  • Postgres runs out of connections when our app scales to many web and worker processes
  • FATAL: sorry, too many clients already from Postgres under load
  • each Postgres connection costs memory, and we have hundreds of mostly idle ones
  • serverless functions open a new database connection on every request and swamp the server
  • share a small pool of Postgres connections across many application servers
  • pause traffic to the database while we restart or fail over Postgres, without clients erroring
  • restart our connection pooler without dropping client connections
  • route several logical databases to different Postgres hosts behind one endpoint
  • keep prepared statements working while pooling connections per transaction
  • see how many clients are waiting for a database connection right now

Features

  • session, transaction and statement pooling modes
  • protocol-level prepared statements in transaction mode (max_prepared_statements)
  • admin console with SHOW, PAUSE, RESUME, RELOAD and SHUTDOWN commands
  • rolling restarts with several processes on one port (so_reuseport) and peering
  • TLS for client and server connections
  • auth via userlist, auth_query, HBA file, PAM or LDAP
  • per-database and per-user pool sizes and limits

Limitations

  • Doesn't support SET, LISTEN, session advisory locks or SQL PREPARE in transaction pooling mode: use session pooling for those3

Capabilities

Has a command line toolplan not known

Alternatives

The same job

These do what PgBouncer does.

  1. Supavisor A cloud-native, multi-tenant Postgres connection pooler
  2. PgCat PostgreSQL pooler with sharding, load balancing and failover support

Compare PgBouncer with the top 3