PgBouncer - lightweight connection pooler for PostgreSQL
Features
- Several levels of brutality when rotating connections:
Session poolingMost polite method. When a client connects, a server connection will be assigned to it for the whole duration it stays connected. When the client disconnects, the server connection will be put back into pool. This mode supports all PostgreSQL features.Transaction poolingA server connection is assigned to a client only during a transaction. When PgBouncer notices that the transaction is over, the server will be put back into the pool.This mode breaks a few session-based features of PostgreSQL. You can use it only when the application cooperates by not using features that break. See the table below for incompatible features.Statement poolingMost aggressive method. This is transaction pooling with a twist: Multi-statement transactions are disallowed. This is meant to enforce “autocommit” mode on the client, mostly targeted at PL/Proxy. - Low memory requirements (2 kB per connection by default). This is because PgBouncer does not need to see full packets at once.
- It is not tied to one backend server. The destination databases can reside on different hosts.
- Supports online reconfiguration for most settings.
- Supports online restart/upgrade without dropping client connections.
SQL feature map for pooling modes
The following table list various PostgreSQL features and whether they are compatible with PgBouncer pooling modes. Note that “transaction” pooling breaks client expectations of the server by design and can be used only if the application cooperates by not using non-working features.
FeatureSession poolingTransaction poolingStartup parameters 1YesYesSET/RESETYesNeverLISTENYesNeverNOTIFYYesYesWITHOUT HOLD CURSORYesYesWITH HOLD CURSORYesNeverProtocol-level prepared plansYesYes 2PREPARE / DEALLOCATEYesNeverON COMMIT DROP temp tablesYesYesPRESERVE/DELETE ROWS temp tablesYesNeverCached plan resetYesYesLOAD statementYesNeverSession-level advisory locksYesNever
- Startup parameters are:
client_encoding,DateStyle,IntervalStyle,Timezone,standard_conforming_strings, andapplication_name. PgBouncer detects their changes and so it can guarantee they remain consistent for the client. If you need PgBouncer to support more than these, take a look attrack_extra_parametersandignore_startup_parameters. ↩ - You need to change
max_prepared_statementsto a non-zero value to enable this support. ↩