1
Setting Up PgBouncer
Gather Database Variables
Gather Database Variables
To successfully use and configure PgBouncer, you’ll need to have a PostgreSQL database you want to pool connections for. From that database, you’ll need to know the following:
- PostgreSQL username
 - PostgreSQL password
 - PostgreSQL host
 - PostgreSQL port
 - PostgreSQL database name These values can be retrieved from the Database Credentials in the UI, and will be used to set configuration variables later in the guide. For example:
 
Create your PgBouncer Application
Create your PgBouncer Application
Through the UI or CLI, create the PgBouncer application, and set a few variables:Note that you’ll need to fill out a few variables with the Database Credentials you previously gathered. We’re also assuming the certificate and key you’re using to authenticate will be saved as 
pgbouncer.crt and pgbouncer.key.Generate a Certificate and Key for SSL Authentication
Generate a Certificate and Key for SSL Authentication
Since databases on Aptible require SSL, you’ll also need to provide an authentication certificate and key. These can be self-signed and created using This creates a rootCA.key and rootCA.crt in your current directory. 
openssl.- Generate a Root Certificate and Key
 
-subj "/CN=app-$APP_ID.on-aptible.com/C=US/L=San Francisco" is modifiable — notably, the Common Name, /CN, should match the TCP endpoint you’ve created for the pgbouncer App.
If you’re using a default endpoint, you can fill in $APP_ID with your Application’s ID.- Using the Root Certificate and key, create the authentication certificate and private key:
 
2
Create the Dockerfile
For a basic implementation, the Dockerfile is quite short:We’re using the PgBouncer image as a base, and then copying a certificate-key pair for TLS authentication to where PgBouncer expects them to be.
This means that your git repository needs to contain three files: the Dockerfile, 
pgbouncer.key, and pgbouncer.crt.3
Deploy using Git Push
Now you’re ready to deploy. Since we’re working from a Dockerfile, follow the steps in Deploying with Git to push your repository to your app’s Git Remote to trigger a deploy.
4
Make an Endpoint for PgBouncer
This is commonly done by creating a TCP endpoint.Instead of connecting to your database directly, you should configure your resources to connect to PgBouncer using the TCP endpoint.
5
Celebrate!
At this point, PgBouncer should be deployed. If you run into any issues, or have any questions, don’t hesitate to reach out to Aptible Support

