Free Database Audit: comprehensive health report for your database

Learn More
Lightweight PostgreSQL Connection Pooler

PgBouncer: The Fastest Connection Pooler for PostgreSQL — Ideal for Serverless & Microservices

PgBouncer adds connection pooling to PostgreSQL with sub-millisecond overhead and a tiny memory footprint. It supports session, transaction, and statement pooling modes — making it the standard choice for high-concurrency applications, Lambda functions, and microservices architectures.

PgBouncer Pooling Modes Explained

Choosing the right pooling mode determines performance and compatibility. Transaction mode delivers the highest connection multiplexing but has restrictions on PostgreSQL features.

Most compatible

Session Mode

Low multiplexing

Client connection held for the entire session. Same behaviour as a direct PostgreSQL connection. Use when you need full feature compatibility — advisory locks, SET, LISTEN/NOTIFY.

Most efficient ★

Transaction Mode

High multiplexing

Connection returned to pool after each transaction. One server connection can serve thousands of application connections. Restrictions: no advisory locks, no SET, no PREPARE across transactions.

Most restrictive

Statement Mode

Highest multiplexing

Connection returned to pool after each statement. Multi-statement transactions are not allowed. Rarely used except for stateless read-only workloads.

Sub-1ms Connection Latency

PgBouncer reuses idle server connections instantly. Application threads never wait for PostgreSQL to fork a new backend process.

Multiplexing at Scale

1,000 application connections can share 20 PostgreSQL server connections in transaction mode — reducing PostgreSQL memory use by 95%.

Single Binary, Simple Config

PgBouncer is a single C binary with a simple INI config file. Deploy in minutes. No complex dependencies, no runtime libraries to manage.

PgBouncer vs pgPool-II

PgBouncer does one thing exceptionally well: connection pooling. pgPool-II adds load balancing, query routing, and HA — but with significantly higher complexity and resource use.

FeaturePgBouncer ✦pgPool-II
Connection pooling
Transaction-level pooling
Sub-1ms connection overhead
Memory footprint (small)
Read/write query splitting
Built-in load balancing
Connection multiplexing
Watchdog HA (self-healing)
Online recovery of standbys
Parallel query execution
Serverless / Lambda friendly
Simple single-binary deploy

Need load balancing + pooling? Consider pairing PgBouncer with HAProxy or Patroni, rather than using pgPool-II. See pgPool-II services →

When PgBouncer Beats pgPool-II

Choose PgBouncer when…

  • • Serverless functions (Lambda, Cloud Run) create thousands of short-lived connections
  • • Microservices architecture with many application instances
  • • You only need connection pooling — not load balancing
  • • Minimising resource use is critical (PgBouncer uses ~2MB RAM)
  • • You want a simple, auditable single-binary with no JVM/Python dependencies
  • • You pair it with Patroni or HAProxy for HA and routing separately

Choose pgPool-II when…

  • • You need automatic read/write splitting to route SELECTs to standbys
  • • You want a single component that handles both pooling and load balancing
  • • Your app uses parallel queries that pgPool-II can accelerate
  • • You need pgPool-II's watchdog HA to auto-failover the proxy itself

JusDB PgBouncer Implementation

Pool Mode Sizing & Configuration

Analyse your application's connection patterns to select the optimal pool mode (transaction vs session), max_client_conn, default_pool_size, and reserve_pool_size.

TLS & Authentication Setup

Configure PgBouncer with TLS client/server encryption, md5 or scram-sha-256 authentication, and HBA-style access controls via pgbouncer.ini.

High Availability Pairing

Deploy PgBouncer behind HAProxy for active/passive HA, or integrate with Patroni health-check endpoint so PgBouncer always routes to the current primary.

Monitoring Integration

Enable the SHOW STATS, SHOW POOLS, and SHOW CLIENTS admin console. Export metrics to Prometheus via pgbouncer_exporter for Grafana dashboards and alerting.

Serverless Optimization

Configure connection_lifetime and server_idle_timeout for Lambda/serverless workloads where functions open and close connections within seconds.

Migration from Direct Connections

Audit existing application connection strings, identify feature incompatibilities with transaction mode, and migrate without application downtime.

FAQ

Stop wasting PostgreSQL connections

JusDB implements PgBouncer with the right pool mode, HA setup, and monitoring — so your application scales without overwhelming PostgreSQL.