Skip to content

Commit

Permalink
PITR: clear data directory for replicas before restore if patroni_cre…
Browse files Browse the repository at this point in the history
…ate_replica_method does not contain pgbackrest

in this case, if another method is defined (e.q. "basebackup") then bootstrap the replica from the wizard will be executed using pg_basebackup. Otherwise, in the replica will be left with data that does not match the data on the master that was restored from the backup.
  • Loading branch information
vitabaks committed Feb 20, 2023
1 parent a4f8b56 commit 9313991
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions roles/patroni/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,8 @@
loop:
- absent
- directory
when: patroni_cluster_bootstrap_method != "pgbackrest" # --delta restore
when: (is_master == "true" and patroni_cluster_bootstrap_method != "pgbackrest")
or (is_master != "true" and 'pgbackrest' not in patroni_create_replica_methods) # --delta restore

- name: Prepare PostgreSQL | make sure the custom WAL directory "{{ postgresql_wal_dir }}" is empty
file:
Expand All @@ -439,7 +440,8 @@
- absent
- directory
when: (postgresql_wal_dir is defined and postgresql_wal_dir | length > 0) and
patroni_cluster_bootstrap_method != "pgbackrest" # --delta restore
((is_master == "true" and patroni_cluster_bootstrap_method != "pgbackrest")
or (is_master != "true" and 'pgbackrest' not in patroni_create_replica_methods)) # --delta restore
when: postgresql_exists != "true" or patroni_cluster_bootstrap_method != "initdb"
tags: patroni, point_in_time_recovery

Expand Down

2 comments on commit 9313991

@vitabaks
Copy link
Owner Author

@vitabaks vitabaks commented on 9313991 Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"master", not "wizard", here is a typo in the commit description.

@vitabaks
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed:

TASK [deploy-finish : PostgreSQL Cluster health] *******************************
ok: [10.129.8.80] => {
    "patronictl_result.stdout_lines": [
        "+ Cluster: mdsdb-cluster ------------+---------+---------+----+-----------+",
        "| Member          | Host             | Role    | State   | TL | Lag in MB |",
        "+-----------------+------------------+---------+---------+----+-----------+",
        "| hl-drm-pgnode02 | 10.129.8.80:5433 | Leader  | running |  5 |           |",
        "| hl-drm-pgnode03 | 10.129.8.81:5433 | Replica | running | 10 |   2197913 |",
        "| hl-drm-pgnode04 | 10.129.8.77:5433 | Replica | running | 10 |   2197928 |",
        "+-----------------+------------------+---------+---------+----+-----------+"
    ]
}

Here the replicas have a different TL because the data remained the same and the master was restored from a backup.

Please sign in to comment.