|
| 1 | +#!/usr/bin/ansible-playbook |
| 2 | +--- |
| 3 | + |
| 4 | +- name: operations after updating pg_wal dir |
| 5 | + vars: |
| 6 | + tmp_wal_dir: "pg_wal.tmp-backup" |
| 7 | + pg_data_lock: "{{ pg_data }}.locked" |
| 8 | + pg_wal_src_tmp: "{{ pg_data_lock }}/{{ tmp_wal_dir }}" |
| 9 | + dbsu: "{{ pg_dbsu|default('postgres') }}" |
| 10 | + block: |
| 11 | + - name: check if postmaster.pid exists and is not empty |
| 12 | + stat: |
| 13 | + path: "{{ pg_data }}/postmaster.pid" |
| 14 | + register: postmaster_pid_stat |
| 15 | + |
| 16 | + - name: start postgres primary after modifying pg_wal |
| 17 | + become_user: "{{ dbsu }}" |
| 18 | + when: (pg_role == 'primary') and (postmaster_pid_stat.stat.exists == false or postmaster_pid_stat.stat.size == 0) |
| 19 | + args: { executable: /bin/bash } |
| 20 | + shell: | |
| 21 | + {{ pg_bin_dir }}/pg_ctl -D {{ pg_data }} start |
| 22 | +
|
| 23 | + - name: start postgres replica after modifying pg_wal |
| 24 | + become_user: "{{ dbsu }}" |
| 25 | + when: (pg_role != 'primary') and (postmaster_pid_stat.stat.exists == false or postmaster_pid_stat.stat.size == 0) |
| 26 | + args: { executable: /bin/bash } |
| 27 | + shell: | |
| 28 | + {{ pg_bin_dir }}/pg_ctl -D {{ pg_data }} start |
| 29 | +
|
| 30 | + - name: wait for postgres primary after modifying pg_wal |
| 31 | + when: pg_role == 'primary' |
| 32 | + wait_for: host={{ inventory_hostname }} port={{ pg_port }} state=started timeout=60 |
| 33 | + |
| 34 | + - name: check postgres primary ready after modifying pg_wal |
| 35 | + become_user: "{{ dbsu }}" |
| 36 | + when: pg_role == 'primary' |
| 37 | + shell: | |
| 38 | + {{ pg_bin_dir }}/pg_isready -t 5 -p {{ pg_port }} |
| 39 | + register: result |
| 40 | + retries: 6 |
| 41 | + until: result.rc == 0 |
| 42 | + delay: 5 |
| 43 | + |
| 44 | + - name: start patroni after modifying pg_wal |
| 45 | + args: { executable: /bin/bash } |
| 46 | + shell: | |
| 47 | + systemctl start patroni |
| 48 | +
|
| 49 | + - name: resume patroni after modifying pg_wal |
| 50 | + become_user: "{{ dbsu }}" |
| 51 | + when: pg_role == 'primary' |
| 52 | + command: /usr/bin/patronictl -c /pg/bin/patroni.yml resume |
| 53 | + |
| 54 | + - name: resume replica patroni after modifying pg_wal (should fail) |
| 55 | + become_user: "{{ dbsu }}" |
| 56 | + when: pg_role != 'primary' |
| 57 | + command: /usr/bin/patronictl -c /pg/bin/patroni.yml resume |
| 58 | + ignore_errors: yes |
| 59 | + |
| 60 | + - name: restart postgres via patroni after modifying pg_wal |
| 61 | + become_user: "{{ dbsu }}" |
| 62 | + when: pg_role == 'primary' |
| 63 | + args: { executable: /bin/bash } |
| 64 | + shell: | |
| 65 | + {% if pg_mode|default('pgsql') == 'citus' %} |
| 66 | + /usr/bin/patronictl -c /etc/patroni/patroni.yml restart {{ pg_shard }} --group {{ pg_group }} --force |
| 67 | + {% else %} |
| 68 | + /usr/bin/patronictl -c /etc/patroni/patroni.yml restart {{ pg_cluster }} --force |
| 69 | + {% endif %} |
| 70 | +
|
| 71 | + - name: clean tmp directory after modifying pg_wal |
| 72 | + ignore_errors: yes |
| 73 | + file: path={{ item }} state=absent |
| 74 | + with_items: |
| 75 | + - "{{ pg_data }}/{{ tmp_wal_dir }}" |
| 76 | + - "{{ pg_wal_src_tmp }}" |
| 77 | + |
| 78 | + - name: clean tmp directory after modifying pg_wal |
| 79 | + ignore_errors: yes |
| 80 | + when: (real_curr_pg_wal != pg_wal_dst) and (real_curr_pg_wal_is_link == true) |
| 81 | + file: path={{ item }} state=absent |
| 82 | + with_items: |
| 83 | + - "{{ real_curr_pg_wal }}" |
| 84 | + |
| 85 | +... |
0 commit comments