Skip to content

Commit

Permalink
pgbackrest: automate "backup-standby" setup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vitabaks committed Dec 26, 2023
1 parent 32bbceb commit 48163c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 11 additions & 1 deletion roles/pgbackrest/templates/pgbackrest.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}" }
Expand Down

0 comments on commit 48163c2

Please sign in to comment.