vitabaks / postgresql_cluster

PostgreSQL High-Availability Cluster (based on Patroni). Automating with Ansible.
https://postgresql-cluster.org
MIT License
1.69k stars 411 forks source link

custom_wal_dir: Refactoring custom WAL directory setup #425

Closed vitabaks closed 1 year ago

vitabaks commented 1 year ago

This PR includes a refactoring of the Ansible playbook that manages PostgreSQL's WAL directory, as well as an update to the Patroni configuration template.

Main Changes:

  1. Refactoring the Ansible playbook for managing Postgresql WAL:
    • Defined the name of the base WAL directory at the start of the script. This improves readability and simplifies the handling of the variable later in the script.
    • Updated the WAL synchronization block. Now, it first ensures the custom WAL directory exists and is empty. Execute CHECKPOINT before stopping PostgreSQL.
    • Modified the order of certain actions to enhance script reliability.
  2. Updating the Patroni configuration template:
    • Removed the PostgreSQL version check and the condition for defining waldir in the template.
    • Added a new option In 'basebackup' variable which allows users to specify 'waldir' setting. By default, this option is disabled.
  3. Additional tag added for point-in-time recovery operations:
    • An extra tag point_in_time_recovery has been introduced for tasks in custom_wall_dir.yml. This tag allows the execution of these tasks specifically after restore from backup to ensure that a symlink to a separate WAL directory set up after the recovery.
  4. Added molecule test for custom PostgreSQL data and WAL directory.
    • It makes sense when custom paths are set in the variables postgresql_data_dir and postgresql_wal_dir
    • This test verifies that our setup can accommodate non-standard directory paths and supports relocating the WAL directory to a separate disk (using a symlink).

These changes will make the playbook more robust and user-friendly for configuration and maintenance.