This role is for managing PgBouncer database list (connection pools) and users. PgBouncer is a lightweight connection pooler for PostgreSQL.
Following are the dependencies and requirement of this role.
- Ansible
edb_devops.edb_postgres
->setup_pgbouncer
- role for setting up PgBouncer on the systems.
When executing the role via ansible these are the required variables:
-
os
Operating Systems supported are: CentOS7, CentOS8, RHEL7, RHEL8, Rocky8, and Ubuntu20
The rest of the variables can be configured and are available in the:
Below is the documentation of the rest of the variables:
System user account that runs PgBouncer process and owns its configuration
files. Default: pgbouncer
Example:
pgbouncer_user: "pgbouncer"
System group that PgBouncer system user is part of. Default: pgbouncer
Example:
pgbouncer_group: "pgbouncer"
PID file path. Default: /run/pgbouncer/pgbouncer.pid
Example:
pgbouncer_pid_file: "/run/pgbouncer/pgbouncer.pid"
Configuration file path that contains databases (connection pools)
configuration.
Default: /etc/pgbouncer/databases.ini
Example:
pgbouncer_databases_file: "/etc/pgbouncer/databases.ini"
List of databases (connection pools).
Default: []
Example:
pgbouncer_databases_list:
- dbname: "my_db"
host: "xxx.xxx.xxx.xxx"
port: 5432
pool_size: 50
pool_mode: "transaction"
max_db_connections: 100
reserve_pool: 10
state: present
The path of the file to load user names and passwords from.
Default: /etc/pgbouncer/userlist.txt
Example:
pgbouncer_auth_file: "/etc/pgbouncer/userlist.txt"
List of user names and passwords residing in the authentication file.
Default: []
Example:
pgbouncer_auth_user_list:
- username: "my_user"
password: "SCRAM-SHA-256$4096:xxx...xxx"
state: present
- username: "pgbouncer_admin"
password: "xxxxxx"
state: present
- username: "pgbouncer_stats"
password: "xxxxxx"
state: present
This role does not have any dependencies, but a PgBouncer instance should have
been deployed beforehand with the setup_pgbouncer
role.
To manage PgBouncer as a standalone application on a dedicated host,
node_type
should be set up to pgbouncer
. When managing PgBouncer alongside
a Postgres instance, the host variable pgbouncer
should be set up to true
.
Content of the inventory.yml
file:
---
all:
children:
# PgBouncer pooler instance on a dedicated host
pgbouncer:
hosts:
pooler1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
primary:
hosts:
primary1:
ansible_host: xxx.xxx.xxx.xxx
private_ip: xxx.xxx.xxx.xxx
# Another PgBouncer pooler instance located on the PG host
pgbouncer: true
Below is an example of how to include the manage_pgbouncer
role:
---
- hosts: pgbouncer,primary,standby
name: Manage PgBouncer databases and users
become: true
gather_facts: yes
# When using collections
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
set_fact:
pgbouncer_databases_list:
- dbname: "db1"
host: "xxx.xxx.xxx.xxx"
port: 5432
pool_size: 50
pool_mode: "transaction"
max_db_connections: 100
reserve_pool: 10
state: present
- dbname: "db2"
host: "xxx.xxx.xxx.xxx"
port: 5432
pool_size: 10
pool_mode: "session"
max_db_connections: 100
reserve_pool: 0
state: present
pgbouncer_auth_user_list:
- username: "my_user"
password: "SCRAM-SHA-256$4096:xxx...xxx"
state: present
- username: "pgbouncer_admin"
password: "xxxxxx"
state: present
- username: "pgbouncer_stats"
password: "xxxxxx"
state: present
roles:
- role: manage_pgbouncer
# Ensure to execute this role only on hosts from the pgbouncer group, or,
# from the primary and standby groups having the 'pgbouncer' inventory
# host var is set to true.
when: "'manage_pgbouncer' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
Defining and adding variables is done in the set_fact
of the pre_tasks
.
All the variables are available at:
BSD
Author:
- Julien Tachoires
- Vibhor Kumar (Reviewer)
- EDB Postgres
- [email protected] www.enterprisedb.com