From 48163c2385f3693ce9bb4c539983a8e44238f587 Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik Date: Tue, 26 Dec 2023 13:03:10 +0300 Subject: [PATCH] pgbackrest: automate "backup-standby" setup Implemented an automatic addition of standby servers to the stanza configuration. This feature is triggered when the `backup-standby` option is set to `y` in `pgbackrest_conf`. Standby servers are added sequentially, starting from `pg2-host`, `pg3-host`, and so on. --- roles/pgbackrest/templates/pgbackrest.conf.j2 | 12 +++++++++++- vars/main.yml | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/roles/pgbackrest/templates/pgbackrest.conf.j2 b/roles/pgbackrest/templates/pgbackrest.conf.j2 index bba6c6180..b655a36bc 100644 --- a/roles/pgbackrest/templates/pgbackrest.conf.j2 +++ b/roles/pgbackrest/templates/pgbackrest.conf.j2 @@ -7,4 +7,14 @@ {% for stanza in pgbackrest_conf.stanza %} {{ stanza.option }}={{ stanza.value }} {% endfor %} - +{% if any(item.option == "backup-standby" and item.value == "y" for item in pgbackrest_conf.global) %} +{% set host_index = 2 %} +{% for host in groups['postgres_cluster'] %} + {% if host != ansible_hostname %} + pg{{ host_index }}-host={{ host }} + pg{{ host_index }}-port={{ postgresql_port }} + pg{{ host_index }}-path={{ postgresql_data_dir }} + {% set host_index = host_index + 1 %} + {% endif %} +{% endfor %} +{% endif %} diff --git a/vars/main.yml b/vars/main.yml index 57d6a9a9e..afb932a64 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -508,6 +508,7 @@ pgbackrest_conf: - { option: "archive-async", value: "y" } # Enables asynchronous WAL archiving (details: https://pgbackrest.org/user-guide.html#async-archiving) - { option: "archive-get-queue-max", value: "1GiB" } # - { option: "archive-push-queue-max", value: "100GiB" } + - { option: "backup-standby", value: "y" } # When set to 'y', standby servers will be automatically added to the stanza section. # - { option: "", value: "" } stanza: # [stanza_name] section - { option: "pg1-path", value: "{{ postgresql_data_dir }}" }