refactor, add postgresql 16 as supported and fix pitr

This commit is contained in:
ace
2024-05-26 17:56:35 +03:00
parent 0b74982f90
commit b6e14c2de3
8 changed files with 87 additions and 48 deletions

View File

@ -1,18 +1,4 @@
---
- name: Create data directory
file:
path: "{{ postgresql_data_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
- name: Create configuration directory
file:
path: "{{ postgresql_config_dir }}/{{ postgresql_major_version }}/{{ postgresql_cluster_name }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
- name: Merge user options for PostgreSQL config
set_fact:
postgresql_combined_parameters: "{{ postgresql_default_parameters | combine(postgresql_custom_parameters|default({}), recursive=true) }}"
@ -25,6 +11,13 @@
set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_parameters, recursive=true) }}"
- name: Merge PITR restore options for PostgreSQL config
set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_pitr_parameters, recursive=true) }}"
when:
- postgresql_wal_g_restore_from_backup
- postgresql_wal_g_pitr | length > 0
- name: Propagate PostgreSQL configs
block:
- name: Template PostgreSQL pg_hba configuration

View File

@ -0,0 +1,13 @@
- name: Create data directory
file:
path: "{{ postgresql_data_dir }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory
- name: Create configuration directory
file:
path: "{{ postgresql_config_dir }}/{{ postgresql_major_version }}/{{ postgresql_cluster_name }}"
owner: "{{ postgresql_user }}"
group: "{{ postgresql_group }}"
state: directory

View File

@ -2,9 +2,8 @@
include_tasks: install.yaml
tags: postgresql_installation
- name: "Configure PostgreSQL"
include_tasks: config.yaml
tags: postgresql_configuration
- name: Include data direcory
include_tasks: data_dir.yaml
- name: "Manage TLS/SSL certificates"
#include_tasks: cacert.yaml
@ -25,6 +24,10 @@
include_tasks: restore.yaml
when: postgresql_wal_g_restore_from_backup
- name: "Configure PostgreSQL"
include_tasks: config.yaml
tags: postgresql_configuration
- name: "PostgreSQL initdb"
become_user: "{{ postgresql_superuser_username }}"
shell: "/usr/lib/postgresql/{{ postgresql_major_version }}/bin/initdb -D {{ postgresql_data_dir }} --username {{ postgresql_superuser_username }} --auth-local peer --auth-host {{ postgresql_password_encryption_algorithm }} --no-instructions"

View File

@ -9,7 +9,14 @@
- name: Merge restore options for PostgreSQL config
set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_parameters|default({}), recursive=true) }}"
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_parameters, recursive=true) }}"
- name: Merge PITR restore options for PostgreSQL config
set_fact:
postgresql_combined_parameters: "{{ postgresql_combined_parameters | combine(postgresql_restore_pitr_parameters, recursive=true) }}"
when:
- postgresql_wal_g_restore_from_backup
- postgresql_wal_g_pitr | length > 0
- name: Propagate PostgreSQL configs
block:

View File

@ -37,6 +37,6 @@
register: postgresql_enable_and_start
tags: postgresql, postgresql_start
- name: "Configure PostgreSQL"
- name: "Configure initial PostgreSQL user"
include_tasks: user.yaml
tags: postgresql_postgres_user

View File

@ -36,6 +36,7 @@
vars:
postgresql_archive_command: "cd ."
postgresql_restore_command: "{{ postgresql_restore_wals_from_backup_command }}"
recovery_target_time: "{{ postgresql_wal_g_pitr }}"
include_tasks: config.yaml
- name: Create recovery.signal file
@ -44,12 +45,6 @@
state: touch
become_user: postgres
#- name: Create standby.signal file
# file:
# name: "{{ postgresql_data_dir }}/standby.signal"
# state: touch
# become_user: postgres
- name: Start PostgreSQL for recovery
systemd:
daemon_reload: true
@ -59,21 +54,23 @@
register: postgresql_start_for_recovery
- name: Ping PostgreSQL server
vars:
ansible_python_interpreter: '/usr/bin/env python3'
community.postgresql.postgresql_ping:
db: "{{ postgresql_superuser_db }}"
login_user: "{{ postgresql_superuser_username }}"
login_password: "{{ postgresql_superuser_password }}"
register: postgresql_ping
until: postgresql_ping.is_available
retries: 60
retries: 100
delay: 20
- name: debug
debug:
msg: "{{ postgresql_ping }}"
- name: Reset {{ postgresql_superuser_username }} password after restore
become_user: "{{ postgresql_user }}"
community.postgresql.postgresql_query:
db: "{{ postgresql_superuser_db }}"
query: ALTER USER {{ postgresql_superuser_username }} with password '{{ postgresql_superuser_password }}';
- name: Stop PostgreSQL
systemd:
daemon_reload: true
@ -82,11 +79,5 @@
masked: no
register: postgresql_stop
- name: Create promote trigger file
file:
name: "{{ postgresql_promote_trigger_file }}"
state: touch
become_user: postgres
- name: Include PostgreSQL configuration
include_tasks: config.yaml