From a1ba2cdca7c134d85a1cb44b1220aeebbf34c442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lardi=C3=A8re=20S=C3=A9bastien?= Date: Wed, 21 Nov 2018 12:03:22 +0100 Subject: [PATCH] Add confd template for pgbouncer (#844) --- docs/replica_bootstrap.rst | 2 +- extras/README.md | 4 ++-- extras/confd/conf.d/pgbouncer.toml | 12 ++++++++++++ extras/confd/templates/pgbouncer.tmpl | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 extras/confd/conf.d/pgbouncer.toml create mode 100644 extras/confd/templates/pgbouncer.tmpl diff --git a/docs/replica_bootstrap.rst b/docs/replica_bootstrap.rst index 9ca4b079..1f3cb520 100644 --- a/docs/replica_bootstrap.rst +++ b/docs/replica_bootstrap.rst @@ -101,7 +101,7 @@ example: pgbackrest - pgbackrest - basebackup pgbackrest: - command: /usr/bin/pgbackrest --stanza=mydb --deltarestore + command: /usr/bin/pgbackrest --stanza= --delta restore keep_data: True no_params: True basebackup: diff --git a/extras/README.md b/extras/README.md index 03b7cf1a..5933857a 100644 --- a/extras/README.md +++ b/extras/README.md @@ -1,11 +1,11 @@ ### confd -`confd` directory contains haproxy template files for the [confd](https://github.com/kelseyhightower/confd) -- lightweight configuration management tool +`confd` directory contains haproxy and pgbouncer template files for the [confd](https://github.com/kelseyhightower/confd) -- lightweight configuration management tool You need to copy content of `confd` directory into /etcd/confd and run confd service: ```bash $ confd -prefix=/service/$PATRONI_SCOPE -backend etcd -node $PATRONI_ETCD_URL -interval=10 ``` -It will periodically update haproxy.cfg with the actual list of Patroni nodes from `etcd` and "reload" haproxy when it is necessary. +It will periodically update haproxy.cfg and pgbouncer.ini with the actual list of Patroni nodes from `etcd` and "reload" haproxy and pgbouncer.ini when it is necessary. ### startup-scripts diff --git a/extras/confd/conf.d/pgbouncer.toml b/extras/confd/conf.d/pgbouncer.toml new file mode 100644 index 00000000..268cb383 --- /dev/null +++ b/extras/confd/conf.d/pgbouncer.toml @@ -0,0 +1,12 @@ +[template] +prefix = "/service/batman" +owner = "postgres" +mode = "0644" +src = "pgbouncer.tmpl" +dest = "/etc/pgbouncer/pgbouncer.ini" + +reload_cmd = "systemctl reload pgbouncer" + +keys = [ + "/members/","/leader" +] \ No newline at end of file diff --git a/extras/confd/templates/pgbouncer.tmpl b/extras/confd/templates/pgbouncer.tmpl new file mode 100644 index 00000000..6cfab7bb --- /dev/null +++ b/extras/confd/templates/pgbouncer.tmpl @@ -0,0 +1,17 @@ +[databases] +{{with get "/leader"}}{{$leader := .Value}}{{$leadkey := printf "/members/%s" $leader}}{{with get $leadkey}}{{$data := json .Value}}{{$hostport := base (replace (index (split $data.conn_url "/") 2) "@" "/" -1)}}{{ $host := base (index (split $hostport ":") 0)}}{{ $port := base (index (split $hostport ":") 1)}}* = host={{ $host }} port={{ $port }} pool_size=10{{end}}{{end}} + +[pgbouncer] +logfile = /var/log/postgresql/pgbouncer.log +pidfile = /var/run/postgresql/pgbouncer.pid +listen_addr = * +listen_port = 6432 +unix_socket_dir = /var/run/postgresql +auth_type = trust +auth_file = /etc/pgbouncer/userlist.txt +auth_hba_file = /etc/pgbouncer/pg_hba.txt +admin_users = pgbouncer +stats_users = pgbouncer +pool_mode = session +max_client_conn = 100 +default_pool_size = 20