From b59f129a2bfa66323a2030de80d900065c11810f Mon Sep 17 00:00:00 2001 From: Vitaliy Kukharik <37010174+vitabaks@users.noreply.github.com> Date: Sun, 24 Sep 2023 16:38:07 +0300 Subject: [PATCH] pg_upgrade: Provide support for upgrading to PostgreSQL 16 (#472) --- molecule/pg_upgrade/converge.yml | 8 ++-- roles/upgrade/README.md | 2 +- roles/upgrade/tasks/update_config.yml | 56 ++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/molecule/pg_upgrade/converge.yml b/molecule/pg_upgrade/converge.yml index 9e76007e0..ec4de182b 100644 --- a/molecule/pg_upgrade/converge.yml +++ b/molecule/pg_upgrade/converge.yml @@ -15,7 +15,7 @@ with_haproxy_load_balancing: true consul_node_role: server # if dcs_type: "consul" consul_bootstrap_expect: true # if dcs_type: "consul" - postgresql_version: "12" # redefine the version to install for the upgrade test + postgresql_version: "14" # redefine the version to install for the upgrade test cacheable: true - name: Set variables for custom PostgreSQL data and WAL directory test @@ -25,15 +25,15 @@ - name: Set variables for TimescaleDB cluster deployment test ansible.builtin.set_fact: - enable_timescale: true + enable_timescale: false # TODO (enable when adding PostgreSQL 16 support) when: - not (ansible_distribution == 'Ubuntu' and ansible_distribution_version is version('20.04', '<')) - not (ansible_distribution == 'Debian' and ansible_distribution_version is version('11', '>')) # TODO Debian 12 - name: Set variables for PostgreSQL upgrade test ansible.builtin.set_fact: - pg_old_version: "12" - pg_new_version: "15" + pg_old_version: "14" + pg_new_version: "16" - name: Clean yum cache (molecule containers) ansible.builtin.command: yum clean all diff --git a/roles/upgrade/README.md b/roles/upgrade/README.md index 637be66ea..dc696ab2f 100644 --- a/roles/upgrade/README.md +++ b/roles/upgrade/README.md @@ -1,6 +1,6 @@ ## PostgreSQL in-place major upgrade -This role is designed for in-place major upgrades of PostgreSQL, e.g., from version 14 to 15. +This role is designed for in-place major upgrades of PostgreSQL (e.g., from version 15 to 16). #### Compatibility diff --git a/roles/upgrade/tasks/update_config.yml b/roles/upgrade/tasks/update_config.yml index c67812fae..dee1b48e2 100644 --- a/roles/upgrade/tasks/update_config.yml +++ b/roles/upgrade/tasks/update_config.yml @@ -147,7 +147,61 @@ when: - pg_old_version|int <= 14 and pg_new_version|int >= 15 -# TODO: Prepare the parameters for PostgreSQL 16 and etc. +- block: # force_parallel_mode (removed in the PG 16) + # check if the force_parallel_mode parameter is specified in the patroni.yml + - name: "Edit patroni.yml | check if the 'force_parallel_mode' parameter is specified" + ansible.builtin.command: grep force_parallel_mode {{ patroni_config_file }} + register: force_parallel_mode_output + changed_when: false + failed_when: false + + # if defined, remove the force_parallel_mode parameter from the patroni.yml + - name: "Edit patroni.yml | remove parameter: 'force_parallel_mode'" + ansible.builtin.lineinfile: + path: "{{ patroni_config_file }}" + regexp: '^(\s*)force_parallel_mode:.*' + state: absent + when: force_parallel_mode_output.stdout | length > 0 + when: + - pg_old_version|int <= 15 and pg_new_version|int >= 16 + +- block: # promote_trigger_file (removed in the PG 16) + # check if the promote_trigger_file parameter is specified in the patroni.yml + - name: "Edit patroni.yml | check if the 'promote_trigger_file' parameter is specified" + ansible.builtin.command: grep promote_trigger_file {{ patroni_config_file }} + register: promote_trigger_file_output + changed_when: false + failed_when: false + + # if defined, remove the promote_trigger_file parameter from the patroni.yml + - name: "Edit patroni.yml | remove parameter: 'promote_trigger_file'" + ansible.builtin.lineinfile: + path: "{{ patroni_config_file }}" + regexp: '^(\s*)promote_trigger_file:.*' + state: absent + when: promote_trigger_file_output.stdout | length > 0 + when: + - pg_old_version|int <= 15 and pg_new_version|int >= 16 + +- block: # vacuum_defer_cleanup_age (removed in the PG 16) + # check if the vacuum_defer_cleanup_age parameter is specified in the patroni.yml + - name: "Edit patroni.yml | check if the 'vacuum_defer_cleanup_age' parameter is specified" + ansible.builtin.command: grep vacuum_defer_cleanup_age {{ patroni_config_file }} + register: vacuum_defer_cleanup_age_output + changed_when: false + failed_when: false + + # if defined, remove the vacuum_defer_cleanup_age parameter from the patroni.yml + - name: "Edit patroni.yml | remove parameter: 'vacuum_defer_cleanup_age'" + ansible.builtin.lineinfile: + path: "{{ patroni_config_file }}" + regexp: '^(\s*)vacuum_defer_cleanup_age:.*' + state: absent + when: vacuum_defer_cleanup_age_output.stdout | length > 0 + when: + - pg_old_version|int <= 15 and pg_new_version|int >= 16 + +# TODO: Prepare the parameters for PostgreSQL 17 and etc. # Copy the pg_hba.conf file to a new PostgreSQL to save pg_hba rules. - name: "Copy pg_hba.conf to {{ pg_new_confdir }}"