From 61bf839777987d999594fb0bf30ab9cc53f5a5c6 Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik Date: Tue, 29 Dec 2020 01:49:12 +0300 Subject: [PATCH] PITR: "disable_archive_command" and "keep_patroni_dynamic_json" variables * disable_archive_command: By default, we disable archive_command after restoring from a backup. This is necessary to avoid conflicts in the archived log storage when archiving WALs. When multiple clusters try to send WALs to the same storage. For example, when you make multiple clones of a cluster from one backup. You can change this parameter using `patronictl edit-config` after restore. Or set `disable_archive_command: false` to not disable archive_command after restore. * keep_patroni_dynamic_json: Patroni nodes are dumping the state of the DCS options to disk upon for every change of the configuration into the file patroni.dynamic.json located in the Postgres data directory. The master (patroni leader) is allowed to restore these options from the on-disk dump if these are completely absent from the DCS or if they are invalid. Patroni will override the parameters specified in vars/main.yml if there is a patroni.dynamic.json file exist in the backup. Set keep_patroni_dynamic_json: false to remove patroni.dynamic.json after restore (if exists). Issue #82 --- README.md | 8 ++++++++ roles/patroni/tasks/main.yml | 10 +++++++++- vars/main.yml | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a103e4e88..97496b0c3 100644 --- a/README.md +++ b/README.md @@ -342,6 +342,14 @@ Recovery steps with pgBackRest: 17. Check that the patroni is healthy on the replica server (timeout 10 hours); 18. Check postgresql cluster health (finish). ``` + +**Why disable archive_command?** + +This is necessary to avoid conflicts in the archived log storage when archiving WALs. When multiple clusters try to send WALs to the same storage. \ +For example, when you make multiple clones of a cluster from one backup. + +You can change this parameter using `patronictl edit-config` after restore. \ +Or set `disable_archive_command: false` to not disable archive_command after restore.

diff --git a/roles/patroni/tasks/main.yml b/roles/patroni/tasks/main.yml index e490ec0aa..509b6c91d 100644 --- a/roles/patroni/tasks/main.yml +++ b/roles/patroni/tasks/main.yml @@ -699,6 +699,12 @@ path: "{{ postgresql_data_dir }}/patroni.dynamic.json" register: patroni_dynamic_json + - name: Remove patroni.dynamic.json file + file: + path: "{{ postgresql_data_dir }}/patroni.dynamic.json" + state: absent + when: not keep_patroni_dynamic_json|bool + - name: Edit patroni.dynamic.json | disable archive_command (if enabled) yedit: src: "{{ postgresql_data_dir }}/patroni.dynamic.json" @@ -707,7 +713,8 @@ content_type: json vars: ansible_python_interpreter: /usr/bin/python3 - when: patroni_dynamic_json.stat.exists + when: patroni_dynamic_json.stat.exists and + keep_patroni_dynamic_json|bool and disable_archive_command|bool - name: Edit patroni.yml | disable archive_command (if enabled) yedit: @@ -716,6 +723,7 @@ value: "cd ." # not doing anything yet with WAL-s vars: ansible_python_interpreter: /usr/bin/python3 + when: disable_archive_command|bool when: patroni_cluster_bootstrap_method != "initdb" and (pgbackrest_install|bool or wal_g_install|bool) and (existing_pgcluster is not defined or not existing_pgcluster|bool) diff --git a/vars/main.yml b/vars/main.yml index 78142c2b9..0c1522df8 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -300,4 +300,7 @@ pgbackrest_patroni_cluster_restore_command: # 1) The database cluster directory will be cleaned (for "wal-g") or overwritten (for "pgbackrest" --delta restore). # 2) And also the patroni cluster "{{ patroni_cluster_name }}" will be removed from the DCS (if exist) before recovery. +disable_archive_command: true # or 'false' to not disable archive_command after restore +keep_patroni_dynamic_json: true # or 'false' to remove patroni.dynamic.json after restore (if exists) + ...