Configuration¶
This page shows where PgBouncer's configuration lives and how to make the common changes: pointing it at your database, users and passwords, pool sizes, backend certificate checks and network access. Edit the files as root.
Where things live¶
| Path | What it is |
|---|---|
/etc/pgbouncer/pgbouncer.ini |
Main configuration. Created on first boot and not overwritten afterwards. |
/etc/pgbouncer/userlist.txt |
User names and passwords that clients authenticate with. |
/var/lib/pgbouncer/credentials/app.password |
Password generated for the app user. |
/var/lib/pgbouncer/credentials/admin.password |
Password generated for the pgbouncer admin user. |
/var/lib/pgbouncer/tls/ |
CA and server certificates and keys. |
/usr/local/share/sushi/pgbouncer/ca.pem |
Public copy of the CA certificate, for clients. |
Apply a change¶
Most changes take effect on a reload, which keeps client connections open:
After you change the listener (listen_addr or listen_port), restart
instead. A restart drops open client connections:
Point PgBouncer at your database¶
The [databases] section ships with two entries that point at the
walkthrough's temporary backend:
[databases]
app = host=127.0.0.1 port=15432 dbname=app
session = host=127.0.0.1 port=15432 dbname=app pool_mode=session
Replace the host, port and database name with your own PostgreSQL or Amazon RDS endpoint, for example:
[databases]
app = host=<db-endpoint> port=<db-port> dbname=<db-name>
session = host=<db-endpoint> port=<db-port> dbname=<db-name> pool_mode=session
The name on the left is the database name your clients connect to. You can add more entries in the same form. Then reload PgBouncer.
Make sure the instance's security group can reach the database port, and that the database's security group allows the instance.
Users and passwords¶
Clients authenticate against /etc/pgbouncer/userlist.txt, which has one
line per user:
PgBouncer logs in to your database with the same user name and password the client used. So each user in this file must exist on your database with the same password.
- Use the generated
apppassword: create a role namedappon your database with the password in/var/lib/pgbouncer/credentials/app.password. - Use an existing role: add a line for it to
userlist.txtwith its password, and connect your application as that user.
After any change to userlist.txt, reload PgBouncer. Keep the file's
ownership and mode as they are (root:pgbouncer, 0640), and never paste
passwords into tickets or chat.
The pgbouncer user is the admin and stats user for the admin console, see
Operations.
Pool modes and sizes¶
The defaults are deliberately small:
pool_modesets the default for all databases. A database entry can override it withpool_mode=session, as thesessionentry does.max_client_connis how many clients can connect to PgBouncer at once.default_pool_sizeis how many server connections PgBouncer opens per database and user pair.
Raise them to fit your workload and your database's connection limit, then reload.
Verify the backend's certificate¶
server_tls_sslmode = require encrypts the connection to your database but
does not check its certificate or host name. To verify it, set
server_tls_sslmode = verify-full and point PgBouncer at your database's CA
certificate with the server_tls_ca_file setting. Test a good and a bad
endpoint before you rely on it.
Reach PgBouncer from your VPC¶
By default PgBouncer listens on 127.0.0.1 only. To accept clients from other
hosts:
- Set
listen_addrto the instance's private address, after you review the security group. - In the security group, allow TCP 6432 only from your application's security group.
- Issue a server certificate that includes that address. The certificate
created on first boot covers only
localhostand127.0.0.1, so clients usingsslmode=verify-fullwould reject it. - Restart PgBouncer and give your clients
/usr/local/share/sushi/pgbouncer/ca.pem.
Keep it private
Do not set listen_addr to * or 0.0.0.0 with an open security group,
and never set client_tls_sslmode to disable.