0PricingLogin
PostgreSQL Performance & Query Optimization · Lesson

Transaction vs Session Pooling Modes

Pick the right PgBouncer mode and know which features break under transaction pooling.

Why Pooling Modes Matter

Each PostgreSQL backend process costs memory (work_mem, catalog caches, plan caches) and CPU. A few thousand idle client connections can exhaust a server even when nothing is running.

PgBouncer sits between your app and PostgreSQL, multiplexing many client connections onto a small set of real server connections. The pool_mode setting decides when a server connection is handed back to the pool.

  • session — server held for the client's whole session
  • transaction — server held only for one transaction
  • statement — server released after every statement

Session Pooling Mode

In session pooling, a server connection is assigned to a client when it connects and is only returned to the pool when the client disconnects.

This is the safest mode: the client gets a dedicated backend for its entire lifetime, so every PostgreSQL feature behaves exactly as if it connected directly. The cost is poor reuse — an idle but connected client still pins a server connection.

; PgBouncer config: pgbouncer.ini
[pgbouncer]
pool_mode = session
max_client_conn = 10000
default_pool_size = 20

[databases]
appdb = host=127.0.0.1 port=5432 dbname=appdb

All lessons in this course

  1. Why Connections Are Expensive in PostgreSQL
  2. Transaction vs Session Pooling Modes
  3. Sizing Pools Against Core Count
  4. Diagnosing Pool Saturation and Queueing
← Back to PostgreSQL Performance & Query Optimization