Skip to content

Commit

Permalink
pg_upgrade: Provide support for upgrading to PostgreSQL 16 (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks authored Sep 24, 2023
1 parent 5517e91 commit b59f129
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
8 changes: 4 additions & 4 deletions molecule/pg_upgrade/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion roles/upgrade/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
56 changes: 55 additions & 1 deletion roles/upgrade/tasks/update_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down

0 comments on commit b59f129

Please sign in to comment.