When to use PgBouncer
PgBouncer is generally recommended for OLTP workloads. For example, we recommend routing all application connections through PgBouncer. You can connect through PgBouncer by updating your connection string to use port6432
instead of the Postgres default of 5432
.
PgBouncer connections operate in transaction mode, which means the pooled server connections are assigned to client connections on a per-transaction level. This provides excellent performance for OLTP workloads but limits certain PostgreSQL features that require persistent connections. Learn more at the PgBouncer documentation.
When should you NOT use PgBouncer
For use cases that require long-running operations, we recommend a direct connection on port5432
. For example:
- Schema changes and DDL
- OLAP, analytics, reporting, or batch processing
- Session-specific features: Custom session variables, temporary tables
- ETL processes and data streaming
- Long-running transactions or queries that span multiple transactions
- Creating a local backup with
pg_dump
Connecting through PgBouncer
PlanetScale offers two connection methods for PostgreSQL databases: direct (port5432
) and via PgBouncer (port 6432
).
To connect to PgBouncer, switch the port in your connection string from 5432
to 6432
. For example:
NotePlanetScale’s use of PgBouncer (port
6432
) does not support replica routing. All connections through PgBouncer are automatically routed to the primary database, regardless of the username specification. Use direct connections (port 5432
) for replica access.