This role is for installing and configuring PgBouncer. PgBouncer is a lightweight connection pooler for PostgreSQL.
Following are the requirements of this role.
- Ansible
edb_devops.edb_postgres->setup_reporole for setting the repository on the systems.
Which port to listen on. Applies to both TCP and Unix sockets. Default: 6432
Example:
pgbouncer_listen_port: 6432Specifies a list of addresses where to listen for TCP connections. You may also
use * meaning “listen on all addresses”. Addresses can be specified
numerically (IPv4/IPv6) or by name. Default: *
Example:
pgbouncer_listen_addr: "*"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"How many server connections to allow per user/database pair. Can be overridden
in the per-database configuration. Default: 20
Example:
pgbouncer_default_pool_size: 20Maximum number of client connections allowed. Default: 100
Example:
pgbouncer_max_client_conn: 100File descriptor limits. Default: 2048
Example:
pgbouncer_fd_limit: 2048Pooling mode. Could be session, transaction or statement.
Default: session
Example:
pgbouncer_pool_mode: "session"Query sent to server on connection release, before making it available to
other clients. Default: DISCARD ALL
Example:
pgbouncer_server_reset_query: "DISCARD ALL"Comma-separated list of database users that are allowed to connect and run all
commands on the console. Default: pgbouncer_admin
Example:
pgbouncer_admin_users: "pgbouncer_admin"Comma-separated list of database users that are allowed to connect and run
read-only queries on the console. Default: pgbouncer_stats
Example:
pgbouncer_stats_users: "pgbouncer_stats"How to authenticate users. Could be pam, hba, cert, md5,
scram-sha-256, plain, trust or any. Default: scram-sha-256
Example:
pgbouncer_auth_type: "scram-sha-256"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"PostgreSQL user used to run the query auth_query in the database when the
user is not found in the authentication file.
Default: not defined
Example:
pgbouncer_auth_user: "pgbouncer"Query to load user’s password from database. Default: not defined
Example:
pgbouncer_auth_query: "SELECT usename, passwd FROM pg_shadow WHERE usename = $1"Main configuration file path. Default: /etc/pgbouncer/pgbouncer.ini
Example:
pgbouncer_config_file: "/etc/pgbouncer/pgbouncer.ini"PID file path. Default: /run/pgbouncer/pgbouncer.pid
Example:
pgbouncer_pid_file: "/run/pgbouncer/pgbouncer.pid"Log file path. Default: /var/log/pgbouncer/pgbouncer.log
Example:
pgbouncer_log_file: "/var/log/pgbouncer/pgbouncer.log"Toggles syslog on/off. Default: 0
Example:
pgbouncer_syslog: 0Under what name to send logs to syslog. Default: pgbouncer
Example:
pgbouncer_syslog_ident: "pgbouncer"Configuration file path that contains databases (connection pools)
configuration.
Default: /etc/pgbouncer/databases.ini
Example:
pgbouncer_databases_file: "/etc/pgbouncer/databases.ini"Systemd unit configuration file path.
Default: /etc/systemd/system/pgbouncer.service.d/pgbouncer.conf
Example:
pgbouncer_systemd_unit_file: "/etc/systemd/system/pgbouncer.service.d/pgbouncer.conf"This role does not have any dependencies, but packages repositories should have
been configured beforehand with the setup_repo role.
To deploy PgBouncer as a standalone application on a dedicated host,
node_type should be set up to pgbouncer. When deploying PgBouncer alongside
a Postgres instance, the key 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: trueBelow is an example of how to include the setup_pgbouncer role:
---
- hosts: pgbouncer,primary,standby
name: Setup PgBouncer connection pooler
become: true
gather_facts: yes
any_errors_fatal: true
collections:
- edb_devops.edb_postgres
pre_tasks:
- name: Initialize the user defined variables
set_fact:
pg_version: 14
pg_type: "PG"
roles:
- role: setup_repo
when: "'setup_repo' in lookup('edb_devops.edb_postgres.supported_roles', wantlist=True)"
- role: setup_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: "'setup_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:
- roles/setup_pgbouncer/defaults/main.yml
- roles/setup_pgbouncer/vars/PG_RedHat.yml
- roles/setup_pgbouncer/vars/PG_Debian.yml
- roles/setup_pgbouncer/vars/EPAS_RedHat.yml
- roles/setup_pgbouncer/vars/EPAS_Debian.yml
BSD
Author:
- Julien Tachoires
- Vibhor Kumar (Reviewer)
- EDB Postgres
- edb-devops@enterprisedb.com www.enterprisedb.com