-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
custom WAL location ("postgresql_wal_dir" variable)
New variable: postgresql_wal_dir (in vars/Debian.yml or RedHat.yml) if custom path to WAL directory is specified in "postgresql_wal_dir" variable: 1. make sure the custom WAL directory exists # create directory if doesn't exist if variable patroni_create_replica_methods = "basebackup" and postgresql_version >= 10: 2. the "waldir" option will be specified in the postgresql.create_replica_methods.basebackup parameter in the patroni.yml configuration file. # and pg_basebackup will take care about creating symlink. either do the following tasks (after cluster init): 1. Make sure pg_xlog/pg_wal is symlink # if wal dir exist and is not symlink: 1.2 Make sure rsync is installed (for synchronize wal dir) 1.3 Stop patroni service (for create symlink) 1.4 Make sure PostgreSQL is stopped 1.5 Synchronize pg_xlog/pg_wal to postgresql_wal_dir 1.6 Rename pg_xlog/pg_wal to pg_xlog_old/pg_wal_old 2. Create symlink pg_xlog/pg_wal -> postgresql_wal_dir 3. Start patroni service (if was stopped) 3.2 Check that the patroni is runnig and healthy 4. Remove pg_xlog_old/pg_wal_old directory (if patroni is healthy) Issue #75
- Loading branch information
Showing
6 changed files
with
129 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
--- | ||
# yamllint disable rule:line-length | ||
# yamllint disable rule:comments-indentation | ||
|
||
- name: "Make sure {{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }} is symlink" # noqa 204 | ||
stat: | ||
path: "{{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}" | ||
register: sym | ||
|
||
- block: # synchronize WAL`s if wal dir exist (and is not symlink) | ||
- name: Make sure rsync is installed (for synchronize wal dir) | ||
package: | ||
name: | ||
- rsync | ||
- sshpass | ||
state: present | ||
environment: "{{ proxy_env | default({}) }}" | ||
|
||
- name: Stop patroni service (for create symlink) | ||
systemd: | ||
name: patroni | ||
state: stopped | ||
register: patroni_stop_result | ||
|
||
- name: Make sure PostgreSQL is stopped | ||
become: true | ||
become_user: postgres | ||
command: "{{ postgresql_bin_dir }}/pg_ctl status -D {{ postgresql_data_dir }}" | ||
register: stop_result | ||
changed_when: false | ||
failed_when: false | ||
until: stop_result.rc == 3 | ||
retries: 100 | ||
delay: 6 | ||
|
||
- name: "Synchronize {{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }} to {{ postgresql_wal_dir }}" # noqa 204 | ||
become: true | ||
become_user: postgres | ||
synchronize: | ||
src: "{{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}/" | ||
dest: "{{ postgresql_wal_dir }}/" | ||
delegate_to: "{{ inventory_hostname }}" | ||
|
||
- name: "Rename {{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }} to {{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}_old" # noqa 204 | ||
command: mv {{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }} {{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}_old # noqa 204 | ||
register: mv_result | ||
when: sym.stat.exists and not sym.stat.islnk|bool | ||
|
||
- name: "Create symlink {{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }} -> {{ postgresql_wal_dir }}" # noqa 204 | ||
become: true | ||
become_user: postgres | ||
file: | ||
src: "{{ postgresql_wal_dir }}" | ||
dest: "{{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}" | ||
state: link | ||
when: sym.stat.islnk is not defined or not sym.stat.islnk|bool | ||
|
||
- block: # start patroni | ||
- name: Start patroni service | ||
systemd: | ||
name: patroni | ||
state: started | ||
|
||
- name: Wait for port 8008 to become open on the host | ||
wait_for: | ||
port: 8008 | ||
host: "{{ hostvars[inventory_hostname]['inventory_hostname'] }}" | ||
state: started | ||
timeout: 120 | ||
delay: 10 | ||
ignore_errors: false | ||
|
||
- name: Check that the patroni is healthy | ||
uri: | ||
url: "http://{{ hostvars[inventory_hostname]['inventory_hostname'] }}:8008/health" | ||
status_code: 200 | ||
register: replica_result | ||
until: replica_result.status == 200 | ||
retries: 120 | ||
delay: 10 | ||
when: patroni_stop_result is changed | ||
|
||
- name: "Remove {{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}_old directory" | ||
file: | ||
path: "{{ postgresql_data_dir }}/{{ 'pg_wal' if postgresql_version is version('10', '>=') else 'pg_xlog' }}_old" | ||
state: absent | ||
when: | ||
- replica_result.status is defined | ||
- replica_result.status == 200 | ||
|
||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters