Skip to content

Commit

Permalink
Add Upgrade Support for Standby Cluster (#830)
Browse files Browse the repository at this point in the history
We have now automated the upgrade process for the Patroni Standby Cluster. This allows us to perform upgrades on the cluster copy without impacting the main cluster.

However, this approach requires a preliminary (manual) shutdown of traffic to the main cluster to ensure no recent data changes are lost.
  • Loading branch information
vitabaks authored Dec 6, 2024
1 parent 68e13ad commit 03157f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 39 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/molecule_pg_upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@ jobs:
- distro: debian11
tag: latest
namespace: geerlingguy
- distro: debian10
- distro: ubuntu2404
tag: latest
namespace: geerlingguy
- distro: ubuntu2204
tag: latest
namespace: geerlingguy
- distro: ubuntu2004
tag: latest
namespace: geerlingguy
- distro: rockylinux8
tag: latest
namespace: geerlingguy
Expand Down
18 changes: 3 additions & 15 deletions automation/roles/upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,10 @@ Please see the variable file vars/[upgrade.yml](../../vars/upgrade.yml)
- Backup the patroni.yml configuration file
- Edit the patroni.yml configuration file
- **Update parameters**: `data_dir`, `bin_dir`, `config_dir`
- **Check if the 'standby_cluster' parameter is specified**
- Remove parameters: `standby_cluster` (if exists)
- **Prepare the PostgreSQL parameters**
- Notes: Removed or renamed parameters
- **Remove 'standby_cluster' parameter (if exists)**
- Notes: To support upgrades in the Patroni Standby Cluster
- **Prepare the PostgreSQL parameters** (removed or renamed parameters)
- Check if the '`replacement_sort_tuples`' parameter is specified (removed in PG 11)
- remove parameter: 'replacement_sort_tuples' (if exists)
- Check if the '`default_with_oids`' parameter is specified (removed in PG 12)
- remove parameter: 'default_with_oids' (if exists)
- Check if the '`wal_keep_segments`' parameter is specified (removed in PG 13)
- replace parameter: 'wal_keep_segments' to '`wal_keep_size`'
- Check if the '`operator_precedence_warning`' parameter is specified" (removed in PG 14)
- remove parameter: 'operator_precedence_warning' (if exists)
- Check if the '`vacuum_cleanup_index_scale_factor`' parameter is specified (removed in PG 14)
- remove parameter: 'vacuum_cleanup_index_scale_factor' (if exists)
- Check if the '`stats_temp_directory`' parameter is specified (removed in PG 15)
- remove parameter: 'stats_temp_directory' (if exists)
- **Copy pg_hba.conf to `pg_new_confdir`**
- Notes: to save pg_hba rules

Expand Down
31 changes: 11 additions & 20 deletions automation/roles/upgrade/tasks/update_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,6 @@
loop_control:
label: '{{ item.replace }}'

# To support upgrades in the Patroni Standby Cluster.
- block: # standby_cluster
- name: "Edit patroni.yml | check if the 'standby_cluster' parameter is specified"
ansible.builtin.command: grep standby_cluster {{ patroni_config_file }}
register: standby_cluster_output
changed_when: false
failed_when: false

# The standby_cluster parameter will be removed from the bootstrap.dcs section (if exists)
# along with all the text between 'standby_cluster' and the next 'initdb' parameter
- name: "Edit patroni.yml | remove parameters: standby_cluster (if exists)"
ansible.builtin.replace:
path: "{{ patroni_config_file }}"
regexp: '^\s*standby_cluster:[^\n]*\n(.|\n)*?initdb:'
replace: ' initdb:'
when: standby_cluster_output.stdout | length > 0
when:
- patroni_standby_cluster.host is defined
- patroni_standby_cluster.host | length > 0

# Prepare the parameters for PostgreSQL (removed or renamed parameters).

- block: # replacement_sort_tuples (removed in the PG 11)
Expand Down Expand Up @@ -269,6 +249,17 @@

# TODO: Prepare the parameters for PostgreSQL 18 and etc.

# To support upgrades in the Patroni Standby Cluster.
- name: "Edit patroni.yml | remove parameter: standby_cluster (if exists)"
ansible.builtin.replace:
path: "{{ patroni_config_file }}"
regexp: '^\s*standby_cluster:[^\n]*\n(.|\n)*?initdb:'
replace: ' initdb:'

- name: "Remove 'standby_cluster' parameter from DCS (if exists)"
ansible.builtin.command: patronictl -c {{ patroni_config_file }} edit-config -s standby_cluster=null --force
when: inventory_hostname in groups['primary']

# Copy the pg_hba.conf file to a new PostgreSQL to save pg_hba rules.
- name: "Copy pg_hba.conf to {{ pg_new_confdir }}"
ansible.builtin.copy:
Expand Down

0 comments on commit 03157f7

Please sign in to comment.