Skip to content

Commit 61bf839

Browse files
committed
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 vitabaks#82
1 parent fdf405c commit 61bf839

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ Recovery steps with pgBackRest:
342342
17. Check that the patroni is healthy on the replica server (timeout 10 hours);
343343
18. Check postgresql cluster health (finish).
344344
```
345+
346+
**Why disable archive_command?**
347+
348+
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. \
349+
For example, when you make multiple clones of a cluster from one backup.
350+
351+
You can change this parameter using `patronictl edit-config` after restore. \
352+
Or set `disable_archive_command: false` to not disable archive_command after restore.
345353
</p></details>
346354

347355

roles/patroni/tasks/main.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,12 @@
699699
path: "{{ postgresql_data_dir }}/patroni.dynamic.json"
700700
register: patroni_dynamic_json
701701

702+
- name: Remove patroni.dynamic.json file
703+
file:
704+
path: "{{ postgresql_data_dir }}/patroni.dynamic.json"
705+
state: absent
706+
when: not keep_patroni_dynamic_json|bool
707+
702708
- name: Edit patroni.dynamic.json | disable archive_command (if enabled)
703709
yedit:
704710
src: "{{ postgresql_data_dir }}/patroni.dynamic.json"
@@ -707,7 +713,8 @@
707713
content_type: json
708714
vars:
709715
ansible_python_interpreter: /usr/bin/python3
710-
when: patroni_dynamic_json.stat.exists
716+
when: patroni_dynamic_json.stat.exists and
717+
keep_patroni_dynamic_json|bool and disable_archive_command|bool
711718

712719
- name: Edit patroni.yml | disable archive_command (if enabled)
713720
yedit:
@@ -716,6 +723,7 @@
716723
value: "cd ." # not doing anything yet with WAL-s
717724
vars:
718725
ansible_python_interpreter: /usr/bin/python3
726+
when: disable_archive_command|bool
719727
when: patroni_cluster_bootstrap_method != "initdb" and
720728
(pgbackrest_install|bool or wal_g_install|bool) and
721729
(existing_pgcluster is not defined or not existing_pgcluster|bool)

vars/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,7 @@ pgbackrest_patroni_cluster_restore_command:
300300
# 1) The database cluster directory will be cleaned (for "wal-g") or overwritten (for "pgbackrest" --delta restore).
301301
# 2) And also the patroni cluster "{{ patroni_cluster_name }}" will be removed from the DCS (if exist) before recovery.
302302

303+
disable_archive_command: true # or 'false' to not disable archive_command after restore
304+
keep_patroni_dynamic_json: true # or 'false' to remove patroni.dynamic.json after restore (if exists)
305+
303306
...

0 commit comments

Comments
 (0)