The PgBouncer Operator deploys and operates the PgBouncer lightweight connection pooler for PostgreSQL. This charm is only compatible with the data platform postgresql-operator charm.
To deploy pgbouncer in front of three units of postgres:
juju deploy pgbouncer --channel=edge
juju deploy postgresql --channel=edge -n 3
juju add-relation pgbouncer:backend-database postgresql:database
To deploy and relate your application to the above cluster, using the updated data platform relation (recommended):
juju deploy my-app
juju add-relation pgbouncer:database my-app:pg-backend
To deploy and relate an application to the above cluster, using the legacy pgsql relation (not recommended - this will be deprecated in future):
juju deploy my-app
juju add-relation pgbouncer:db my-app:db
Or, if my-app needs admin permissions:
juju add-relation pgbouncer:db-admin my-app:db
Set these using the command juju config <option>=<value>
.
pool_mode
:
session
max_db_connections
:
100
From these values and the current deployment, the following pgbouncer.ini config values are calculated proportional to max_db_connections
:
effective_db_connections = max_db_connections / number of pgbouncer instances running in a unit
default_pool_size = effective_db_connections / 2
default_pool_size
means each new unit will have plenty of spare space when it comes online, allowing the cluster to be more stable when more traffic is needed.min_pool_size = effective_db_connections / 4
min_pool_size
and reserve_pool_size
(relative to pgbouncer defaults) means that if a unit goes down for whatever reason, the other units in the cluster should be able to easily handle its workload.reserve_pool_size = effective_db_connections / 4
If max_db_connections
is set to 0, the derivatives are set as below, based on pgbouncer defaults. It's advised to avoid this and instead set max_db_connections
to an amount you're expecting to use, as it will set the following values to better suit your use case.
default_pool_size = 20
min_pool_size = 10
reserve_pool_size = 10
The following config values are set as constants in the charm:
max_client_conn = 10000
ignore_startup_parameters = extra_float_digits
extra_float_digits
is a parameter in postgresdatabase
f"{dbname}_readonly"
."endpoints"
field, and the follower nodes are stored in the "read-only-endpoints"
field of the relation databag. This is to preserve interoperability with the postgres charm.backend-database
The expected data presented in a relation interface is provided in the docstring at the top of the source files for each relation.
The following relations are legacy, and will be deprecated in a future release in favour of relations using the data platform provides library. For future compatibility, build relations with the data platform requires library.
db
db-admin
The Charmed PgBouncer Operator is free software, distributed under the Apache Software License, version 2.0. See LICENSE for more information.
Security issues in the Charmed PgBouncer Operator can be reported through LaunchPad. Please do not file GitHub issues about security issues.
Please see the Juju SDK docs for guidelines on enhancements to this charm following best practice guidelines, and CONTRIBUTING.md for developer guidance. For more information, get in touch on the Charmhub Mattermost server.