Skip to content

Commit

Permalink
Postgres recovery fix (#1339)
Browse files Browse the repository at this point in the history
* merge, modify postgres to use new setup

* recovery fix
  • Loading branch information
plirglo authored Jun 8, 2020
1 parent 8c6c460 commit d6461ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
# Ansible playbook for recovering Postgresql database

- hosts: postgresql[0]
- hosts: postgresql
become: true
become_method: sudo
serial: 1
tasks:
- when: specification.components.postgresql.enabled | default(false)
block:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
- groups['postgresql'][0] == inventory_hostname

when:
- specification.extensions.replication.enabled is defined
- specification.extensions.replication.enabled
- specification.extensions.replication.use_repmgr is defined
- specification.extensions.replication.use_repmgr
- component_vars.specification.extensions.replication.enabled is defined
- component_vars.specification.extensions.replication.enabled
- component_vars.specification.extensions.replication.use_repmgr is defined
- component_vars.specification.extensions.replication.use_repmgr

- name: Copy and restore backup files

Expand All @@ -32,7 +32,7 @@
snapshot_name: "{{ specification.components.postgresql.snapshot_name }}"

- name: Transfer database backup via rsync
import_tasks: upload_via_rsync.yml
import_tasks: common/upload_via_rsync.yml
vars:
artifacts:
- "{{ snapshot_path }}"
Expand Down Expand Up @@ -122,12 +122,12 @@
become: yes
become_user: postgres
shell: "{{ repmgr_bindir[ansible_os_family] }}/repmgr -f {{ repmgr_config_dir[ansible_os_family] }}/repmgr.conf
--force --superuser={{ specification.extensions.replication.priviledged_user_name }} primary register -F"
--force --superuser={{ component_vars.specification.extensions.replication.priviledged_user_name }} primary register -F"
when:
- specification.extensions.replication.enabled is defined
- specification.extensions.replication.enabled
- specification.extensions.replication.use_repmgr is defined
- specification.extensions.replication.use_repmgr
- component_vars.specification.extensions.replication.enabled is defined
- component_vars.specification.extensions.replication.enabled
- component_vars.specification.extensions.replication.use_repmgr is defined
- component_vars.specification.extensions.replication.use_repmgr

- name: Remove temporary files
file:
Expand Down Expand Up @@ -189,7 +189,7 @@

- name: Clone content from primary node using repmgr
become_user: postgres
shell: "{{ repmgr_bindir[ansible_os_family] }}/repmgr -f {{ repmgr_config_dir[ansible_os_family] }}/repmgr.conf -h {{ hostvars[groups['postgresql'][0]]['ansible_default_ipv4']['address'] }} -U {{ specification.extensions.replication.priviledged_user_name }} -d {{ specification.extensions.replication.repmgr_database }} -p 5432 -F standby clone"
shell: "{{ repmgr_bindir[ansible_os_family] }}/repmgr -f {{ repmgr_config_dir[ansible_os_family] }}/repmgr.conf -h {{ hostvars[groups['postgresql'][0]]['ansible_default_ipv4']['address'] }} -U {{ component_vars.specification.extensions.replication.priviledged_user_name }} -d {{ component_vars.specification.extensions.replication.repmgr_database }} -p 5432 -F standby clone"

- name: Start postgresql service
service:
Expand All @@ -205,18 +205,18 @@
shell: "{{ repmgr_bindir[ansible_os_family] }}/repmgr -f {{ repmgr_config_dir[ansible_os_family] }}/repmgr.conf standby follow -F"
when:
- groups['postgresql'][1] == inventory_hostname
- specification.extensions.replication.enabled is defined
- specification.extensions.replication.enabled
- specification.extensions.replication.use_repmgr is defined
- specification.extensions.replication.use_repmgr
- component_vars.specification.extensions.replication.enabled is defined
- component_vars.specification.extensions.replication.enabled
- component_vars.specification.extensions.replication.use_repmgr is defined
- component_vars.specification.extensions.replication.use_repmgr

- name: Restart repmgrd service
service:
name: "{{ repmgr_service_name[ansible_os_family] }}"
state: restarted
when:
- specification.extensions.replication.enabled is defined
- specification.extensions.replication.enabled
- specification.extensions.replication.use_repmgr is defined
- specification.extensions.replication.use_repmgr
- component_vars.specification.extensions.replication.enabled is defined
- component_vars.specification.extensions.replication.enabled
- component_vars.specification.extensions.replication.use_repmgr is defined
- component_vars.specification.extensions.replication.use_repmgr

0 comments on commit d6461ae

Please sign in to comment.