Skip to content

Commit

Permalink
PITR: "disable_archive_command" and "keep_patroni_dynamic_json" varia…
Browse files Browse the repository at this point in the history
…bles

* 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
  • Loading branch information
vitabaks committed Dec 28, 2020
1 parent fdf405c commit 61bf839
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</p></details>


Expand Down
10 changes: 9 additions & 1 deletion roles/patroni/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

...

0 comments on commit 61bf839

Please sign in to comment.