Skip to content

Commit 5f8c073

Browse files
authored
update_pgcluster.yml: Update pgBackRest package on the backup server (vitabaks#648)
1 parent fee979c commit 5f8c073

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed

roles/update/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Note: About the expected downtime of the database during the update:
5656

5757
When using load balancing for read-only traffic (the "Type A" and "Type C" schemes), zero downtime is expected (for read traffic), provided there is more than one replica in the cluster. For write traffic (to the Primary), the expected downtime is ~5-10 seconds.
5858

59-
#### 1. PRE-UPDATE: Perform Pre-Checks
59+
#### 1. PRE-UPDATE: Perform pre-update tasks
6060
- Test PostgreSQL DB Access
6161
- Make sure that physical replication is active
6262
- Stop, if there are no active replicas
@@ -66,6 +66,8 @@ When using load balancing for read-only traffic (the "Type A" and "Type C" schem
6666
- Make sure there are no long-running transactions
6767
- no more than `max_transaction_sec`
6868
- Stop, if long-running transactions detected
69+
- Update the pgBackRest package on the backup server (Dedicated Repository Host).
70+
- Note: This task runs only if the backup host is specified in the 'pgbackrest' group in the inventory file, and the variable `target` is set to '`system`'.
6971
#### 2. UPDATE: Secondary (one by one)
7072
- Stop read-only traffic
7173
- Enable `noloadbalance`, `nosync`, `nofailover` parameters in the patroni.yml
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
# Update pgbackrest package on the Dedicated Repository Host
3+
# if 'pgbackrest_repo_host' is defined and the host is specified in the 'pgbackrest' group in the inventory file.
4+
- block:
5+
- name: Gather facts from pgbackrest server
6+
ansible.builtin.setup:
7+
delegate_to: "{{ groups['pgbackrest'][0] }}"
8+
run_once: true
9+
10+
- name: Update yum cache
11+
delegate_to: "{{ groups['pgbackrest'][0] }}"
12+
run_once: true
13+
ansible.builtin.shell: yum clean all && yum -y makecache
14+
args:
15+
executable: /bin/bash
16+
when:
17+
- ansible_os_family == "RedHat"
18+
- ansible_distribution_major_version == '7'
19+
20+
- name: Update dnf cache
21+
delegate_to: "{{ groups['pgbackrest'][0] }}"
22+
run_once: true
23+
ansible.builtin.shell: dnf clean all && dnf -y makecache
24+
args:
25+
executable: /bin/bash
26+
when:
27+
- ansible_os_family == "RedHat"
28+
- ansible_distribution_major_version >= '8'
29+
30+
- name: Update apt cache
31+
delegate_to: "{{ groups['pgbackrest'][0] }}"
32+
run_once: true
33+
ansible.builtin.apt:
34+
update_cache: true
35+
cache_valid_time: 3600
36+
register: apt_status
37+
until: apt_status is success
38+
delay: 5
39+
retries: 3
40+
when: ansible_os_family == "Debian"
41+
42+
- name: Install the latest version of pgbackrest package
43+
delegate_to: "{{ groups['pgbackrest'][0] }}"
44+
run_once: true
45+
ansible.builtin.package:
46+
name: pgbackrest
47+
state: latest
48+
register: update_pgbackrest_package
49+
until: update_pgbackrest_package is success
50+
delay: 5
51+
retries: 3
52+
when:
53+
- pgbackrest_install | bool
54+
- pgbackrest_repo_host | default('') | length > 0
55+
- groups['pgbackrest'] | default([]) | length > 0
56+
57+
...

update_pgcluster.yml

+13-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
when: inventory_hostname in groups['primary']
5454
tags: always
5555

56-
- name: "(1/4) PRE-UPDATE: Perform Pre-Checks"
56+
- name: "(1/4) PRE-UPDATE: Perform pre-update tasks"
5757
hosts: "primary:secondary"
58-
gather_facts: false
58+
gather_facts: true
5959
become: true
6060
become_user: postgres
6161
any_errors_fatal: true
@@ -71,14 +71,22 @@
7171
ansible.builtin.include_role:
7272
name: update
7373
tasks_from: pre_checks
74+
75+
# This task updates the pgBackRest package on the backup server (Dedicated Repository Host).
76+
# It runs only if the 'pgbackrest' group is defined in the inventory and the update target is set to 'system'.
77+
- name: Update pgBackRest package (Dedicated Repository Host)
78+
ansible.builtin.include_role:
79+
name: update
80+
tasks_from: pgbackrest_host
81+
when: groups['pgbackrest'] | default([]) | length > 0 and target | lower == 'system'
7482
tags:
7583
- update
7684
- pre-checks
7785

7886
- name: "(2/4) UPDATE: Secondary"
7987
hosts: secondary
8088
serial: 1 # update replicas one by one
81-
gather_facts: false
89+
gather_facts: true
8290
become: true
8391
become_method: sudo
8492
any_errors_fatal: true
@@ -134,7 +142,7 @@
134142

135143
- name: "(3/4) UPDATE: Primary"
136144
hosts: primary
137-
gather_facts: false
145+
gather_facts: true
138146
become: true
139147
become_method: sudo
140148
any_errors_fatal: true
@@ -195,7 +203,7 @@
195203

196204
- name: "(4/4) POST-UPDATE: Update extensions"
197205
hosts: postgres_cluster
198-
gather_facts: false
206+
gather_facts: true
199207
become: true
200208
become_user: postgres
201209
any_errors_fatal: true

0 commit comments

Comments
 (0)