All Products
Search
Document Center

ApsaraDB RDS:Enable or disable the connection pool (PgBouncer)

Last Updated:Mar 28, 2026

If your application creates many short-lived connections or generates high connection churn, enabling the connection pool (PgBouncer) reduces database server load and improves response time. PgBouncer sits between your application and ApsaraDB RDS for PostgreSQL, reusing backend connections across many client connections so the database avoids repeatedly opening and closing them.

When to use connection pooling

Not every workload benefits from PgBouncer. Use this table to decide whether to use a pooled or direct connection.

ScenarioConnection typeWhy
Serverless or edge functionsPooledEach invocation creates a new connection
Web applications with many concurrent requestsPooledReduces per-request connection overhead
High connection churn from ORM frameworksPooledReuses backend connections
Schema migrationsDirectMigration tools may use SET statements or advisory locks
Long-running analytics queriesDirectAvoids pool contention
pg_dump or pg_restoreDirectUses session-level SET statements
Logical replicationDirectRequires a persistent session
Prepared statements (in transaction mode)DirectNot supported in transaction pooling

Prerequisites

Before you begin, make sure your ApsaraDB RDS for PostgreSQL instance meets all of the following requirements:

  • Major engine version: PostgreSQL 11 or later

  • Product series: Basic Edition or High-availability Edition

  • Billing method: subscription or pay-as-you-go

  • Minor engine version: 20240830 or later, without the babelfish suffix

To view or upgrade the minor engine version, see Upgrade the minor engine version of an ApsaraDB RDS for PostgreSQL instance.

Billing

This feature is free of charge.

How it works

PgBouncer acts as middleware between your application and the database. Clients connect to PgBouncer on port 6432 (default). PgBouncer maintains a pool of backend connections to PostgreSQL on port 5432 (default) and assigns them to clients according to the configured pool mode.

When PgBouncer is enabled:

  • A new PgBouncer port (default: 6432) is allocated. Your existing connections through the original database port (5432) are not affected.

  • The system installs the pgbouncer_fdw and dblink plugins in the postgres database to support connection pool metrics. These plugins cannot be uninstalled.

Enable or disable the connection pool

  1. Go to the Instances page. In the top navigation bar, select the region where your RDS instance resides. Find the instance and click its ID.

  2. In the left navigation pane, click Database Connection.

  3. Click Enable PgBouncer or Disable PgBouncer.

  4. In the dialog box that appears, click OK.

After PgBouncer is enabled, the PgBouncer port (default: 6432) appears on the Database Connection page. To change the port, click Modify Endpoint, select an endpoint type, and update the PgBouncer Port field.

Note After you disable PgBouncer, applications still configured to use port 6432 cannot connect. Switch them back to the original database port (default: 5432) before disabling.

Connect through the connection pool

After enabling PgBouncer, update your application's connection port from 5432 to 6432. All other connection parameters — endpoint, username, and password — remain unchanged.

Before (direct connection):

postgresql://<username>:<password>@<endpoint>:5432/<database>

After (pooled connection):

postgresql://<username>:<password>@<endpoint>:6432/<database>

For more information, see Connect to an ApsaraDB RDS for PostgreSQL instance.

Configure connection pool parameters

After enabling PgBouncer, use the Parameter Settings feature to adjust connection pool behavior.

Note Parameter Settings shows PgBouncer parameters only after PgBouncer is enabled. If you want to apply a parameter template to modify parameters in batches, enable PgBouncer first, then apply the template.

The default parameter template is PostgreSQL_PgBouncer_Default Parameter Template (rpg-sys-pgsql-pgbouncer).

Pool mode

The pgbouncer.pool_mode parameter controls when PgBouncer returns a backend connection to the pool.

ModeDefaultHow it worksWhen to use
transactionYesReturns the connection after each transactionMost applications. Provides the highest connection reuse.
sessionNoReturns the connection when the client disconnectsApplications that use session-level features (SET, LISTEN, prepared statements, advisory locks)
statementNoReturns the connection after each statement. Autocommit workloads only. Transactions spanning multiple statements are not supported.Autocommit-only workloads

Connection limits

The following parameters control how many connections PgBouncer accepts and forwards to the database. max_client_conn and default_pool_size operate at different layers: max_client_conn caps incoming client connections, while default_pool_size caps outgoing backend connections. Many clients can share a smaller pool of backend connections — that is the core benefit of connection pooling.

ParameterTypeDefaultWhat it controls
pgbouncer.max_client_connint100Maximum number of client connections PgBouncer accepts
pgbouncer.default_pool_sizeint20The default number of connections allowed in the connection pool
pgbouncer.min_pool_sizeint0The minimum number of client connections allowed by the connection pool

Other parameters

ParameterTypeDefaultDescription
pgbouncer.query_wait_timeoutint120Maximum time in seconds a query waits in the queue. When the timeout is reached, the client is disconnected. Set to 0 for an indefinite wait.
pgbouncer.ignore_startup_parametersstring"extra_float_digits"Comma-separated list of startup parameters PgBouncer ignores. By default, PgBouncer only processes core parameters (client_encoding, datestyle, timezone, standard_conforming_strings) and rejects connections that send unknown parameters. Add any extra parameters here. Always keep extra_float_digits to maintain compatibility with PostgreSQL JDBC (Java Database Connectivity) drivers.
pgbouncer.stats_usersstring""Comma-separated list of users allowed to connect to the PgBouncer virtual database and run read-only queries.

For the full parameter reference, see the official PgBouncer documentation.

View connection pool metrics

Use Enhanced Monitoring to monitor connection pool activity. Metrics are available only after PgBouncer is enabled.

MetricDescription
db.pgbouncer.client_connections.activeActive client connections
db.pgbouncer.client_connections.waitingClient connections waiting for a backend connection
db.pgbouncer.server_connections.activeActive backend connections
db.pgbouncer.server_connections.idleIdle backend connections
db.pgbouncer.total_pooled_connectionsTotal connections in the pool
db.pgbouncer.num_poolsNumber of connection pools

Limitations

  • The maximum idle time for a connection in the pool is 10 minutes. Idle connections that exceed this duration are automatically closed. This value cannot be changed.

  • When SSL encryption is enabled on the instance, PgBouncer also enables SSL. PgBouncer does not support connection authentication with the Access Control List (ACL) set to verify-ca or verify-full, and does not support client certificate revocation files.

API reference

Call the ModifyDBInstanceConfig operation to enable or disable PgBouncer programmatically.

ParameterDescriptionExample
DBInstanceIdThe ID of the RDS for PostgreSQL instancepgm-****
ConfigNameThe name of the configuration itempgbouncer
ConfigValuetrue to enable, false to disabletrue

What's next