add pending restart feature and bump postgresql default version to 15.4

This commit is contained in:
ace 2023-08-11 12:56:00 +03:00
parent 00856ecbd3
commit 43c8d3baa4
Signed by: ace
GPG Key ID: 2C08973DD37A76FD
4 changed files with 58 additions and 9 deletions

View File

@ -1,13 +1,14 @@
# Patroni common options
patroni_version: "3.0.4"
patroni_install_official_repo: true
patroni_play_group: "patroni"
# Patroni cluster options
patroni_cluster_name: "patroni-cluster"
patroni_namespace: "/service/"
# Patroni PostgreSQL common options
patroni_postgresql_version: "15.3"
patroni_postgresql_version: "15.4"
patroni_postgresql_install_repo: true
patroni_postgresql_system_locale: "en_US.UTF-8"
patroni_postgresql_system_language: "{{ patroni_postgresql_system_locale }}"
@ -31,7 +32,6 @@ patroni_ssl: false
patroni_ssl_path: "/etc/patroni/ssl"
patroni_self_signed_cert: false
patroni_self_signed_cert_name: "cert"
patroni_play_group: "patroni"
## DCS options. Consul or Etcd
patroni_dcs_exists: false
@ -113,7 +113,6 @@ patroni_postgresql_default_parameters:
superuser_reserved_connections: "5"
password_encryption: "{{ patroni_postgresql_password_encryption_algorithm }}"
max_locks_per_transaction: "64"
max_prepared_transactions: "0"
huge_pages: "try"
shared_buffers: "{{ (ansible_memory_mb.real.total * 0.25) | round | int }}MB"
max_worker_processes: "{{ ansible_processor_vcpus }}"

View File

@ -77,3 +77,7 @@
- name: Dynamic Patroni configuration
include_tasks: dynamic_config.yaml
tags: patroni_dynamic_configure
- name: Patroni restart if pending restart
include_tasks: restart_pending.yaml
tags: patroni_restart_pending

View File

@ -0,0 +1,46 @@
---
- name: Pending restart for Patroni
block:
- name: Wait for Patroni leader
vars:
_query: 'json.members[].role'
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/cluster"
method: GET
body_format: json
status_code:
- 200
- 503
register: patroni_role
until: patroni_role | json_query(_query) | regex_findall('leader') | count > 0
retries: 100
delay: 10
- name: Get Patroni nodes roles
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}"
method: GET
body_format: json
status_code:
- 200
- 503
register: patroni_role
- name: Set fact about roles
set_fact:
role: "{{ patroni_role.json.role }}"
- name: Restart if pending restart
throttle: 1
ansible.builtin.uri:
url: "{{ 'https://' if patroni_ssl else 'http://' }}{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}:{{ patroni_restapi_listen_port }}/restart"
user: "{{ patroni_restapi_username }}"
password: "{{ patroni_restapi_password }}"
method: POST
body: '{ "restart_pending": true }'
force_basic_auth: yes
status_code:
- 200
- 503
#when:
# - "hostvars[inventory_hostname]['role'] == 'master'"

View File

@ -104,15 +104,15 @@ bootstrap:
pg_hba: # Add following lines to pg_hba.conf after running 'initdb'
{% if patroni_ssl|bool %}
{% for host in groups.patroni %}
{% for host in groups[patroni_play_group] %}
- hostssl all all {{ hostvars[host]['ansible_host'] }}/32 {{ patroni_postgresql_password_encryption_algorithm }}
{% endfor %}
{% else %}
{% for host in groups.patroni %}
{% for host in groups[patroni_play_group] %}
- host all all {{ hostvars[host]['ansible_host'] }}/32 {{ patroni_postgresql_password_encryption_algorithm }}
{% endfor %}
{% endif %}
{% for host in groups.patroni %}
{% for host in groups[patroni_play_group] %}
- host replication {{ patroni_replication_username }} {{ hostvars[host]['ansible_host'] }}/32 {{ patroni_postgresql_password_encryption_algorithm }}
{% endfor %}
- host all all 127.0.0.1/32 {{ patroni_postgresql_password_encryption_algorithm }}
@ -150,9 +150,9 @@ postgresql:
# password: rewind_password
parameters:
unix_socket_directories: {{ patroni_postgresql_unix_socket_dir }}
{% if patroni_postgresql_stats_temp_directory_path is defined and patroni_postgresql_stats_temp_directory_path != 'none' %}
stats_temp_directory: {{ patroni_postgresql_stats_temp_directory_path }}
{% endif %}
#{% if patroni_postgresql_stats_temp_directory_path is defined and patroni_postgresql_stats_temp_directory_path != 'none' %}
# stats_temp_directory: {{ patroni_postgresql_stats_temp_directory_path }}
#{% endif %}
{% if patroni_ssl|bool %}
ssl: on
ssl_cert_file: {{ patroni_ssl_path }}/{{ patroni_self_signed_cert_name }}.crt