How do we deploy PgBouncer?

Hey everyone,

We’re looking to deploy pgbouncer or something similar to handle connection pooling between our App containers and PostgreSQL database. How do we set up pgbouncer on Aptible?

Hey anonymous13,

We recommend you to deploy PgBouncer as a separate App especially if you have multiple Services connecting to a Database. Deploying PgBouncer as a separate App allows for all App containers to use the same connection pool rather than each container having its own.

When deploying PgBouncer as an App, there are some platform considerations to make:

  1. You’ll have to provide PgBouncer with an SSL certificate and use an internal TCP Endpoint so your Services can connect to it securely. Using Internal placement will expose PgBouncer only to the Apps on the same Stack. Whereas using an External Endpoint would be roughly the equivalent of creating a Database Endpoint which exposes the Database to the public internet.
  2. You should configure PgBouncer with CLIENT_TLS_SSLMODE=require and SERVER_TLS_SSLMODE=require to ensure that the client and server connections are secure.
  3. Consider scaling the PgBouncer App to at least two containers to ensure high-availability. This does split the pool in two, but if one of the containers is unavailable, your Services will still be able to reach the Database via the other. You can Horizontally Scale through the dashboard or the CLI by using the aptible apps:scale command.