PSBouncer
PSBouncer enables high availability for Postgres database by efficiently pooling connections and buffering queries during failovers. It is similar to PGBouncer, but is optimized for PlanetScale's infrastructure.
When to use PSBouncer
PSBouncer is generally recommended for OLTP workloads. For example, we'd recommend routing your application connections through PSBouncer. You can connect through PSBouncer by updating your connection string to use port 6432
.
PSBouncer connections operate in transaction mode, which means each connection is only held for the duration of a single transaction. This provides excellent performance for OLTP workloads but limits certain PostgreSQL features that require persistent connections. For use cases that require long-running operations, we recommend a direct connection on port 5432
.
Connecting through PSBouncer
PlanetScale offers two connection methods for PostgreSQL databases: direct (port 5432
) and via PSBouncer (port 6432
).
To connect to PSBouncer, switch the port in your connection string from 5432
to 6432
. For example:
psql 'host=xxxxxxxxxx-useast1-1.horizon.psdb.cloud port=6432 user=postgres.xxxxxxxxxx password=pscale_pw_xxxxxxxxxxxxxxxxxx dbname=my_database sslnegotiation=direct sslmode=verify-full sslrootcert=system'
Note
PSBouncer (port 6432) does not support replica routing. All connections through PSBouncer are automatically routed to the primary database, regardless of the username specification. Use direct connections (port 5432) for replica access.
PSBouncer configuration
Your cluster's PSBouncer settings are automatically configured based on your cluster size, but you can customize pooling parameters on your database's cluster configuration page under Parameters:
- Number of processes: Number of PSBouncer processes per node (1-4)
- Default pool size: Default connection pool size
- Max client connections: Maximum client connections
- Max prepared statements: Maximum prepared statements cache
- Server lifetime: Connection lifetime settings
- Server idle timeout: Idle connection timeout
These settings are managed through your cluster parameters and don't require changes to your application connection strings.
Need help?
Get help from the PlanetScale Support team, or join our GitHub discussion board to see how others are using PlanetScale.