Ansible role for deploying High Availability PostgreSQL
Go to file
Jakub Sokołowski 9142511e51
backup: add port flag to handle changed ports
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2024-07-17 22:56:24 +02:00
defaults rename postgres_ha_alter_system_settings 2024-06-25 16:04:56 +02:00
meta meta: add missing infra roles to dependencies 2023-11-23 12:50:00 +01:00
tasks docker: switch compose to v2 2024-05-30 16:29:14 +02:00
templates backup: add port flag to handle changed ports 2024-07-17 22:56:24 +02:00
README.md rename postgres_ha_alter_system_settings 2024-06-25 16:04:56 +02:00

README.md

Description

This role configures a High-Availability PostgreSQL Database with replication from master to slaves.

Configuration

To run just one instance without actual High-Availability use:

postgres_ha_db_name: 'example-db'
postgres_ha_admin_user: 'admin'
postgres_ha_admin_pass: 'super-secret-password'

For replicaton other settings

postgres_ha_is_master: '{{ hostname == "node-01.example.org" }}'
postgres_ha_replica_host: 'node-01.example.org'
postgres_ha_replica_port: 5043
postgres_ha_replica_allowed_addresses: ['11.12.13.15']

You can create additional databases using:

# Databases to init
postgres_ha_databases:
  - name: my-db
    user: my-user
    pass: my-pass
    script: 'CREATE SCHEMA IF NOT EXIST example;' 

  - name: my-other-db
    user: my-other-user
    pass: my-other-pass

The user field is optional. DB name is used by default. The field script is optional and allow to add commands to run when creating the database.

Backup settings can be adjusted using:

postgres_ha_backup: false
postgres_ha_backup_frequency: 'weekly'
postgres_ha_backup_timeout: 1200

And database settings can be modified using the ALTER SYSTEM configuration:

postgres_ha_alter_system_settings:
  checkpoint_timeout: '5min'
  max_wal_size: '1GB'
  min_wal_size: '80MB'

Management

The service is managed using Docker Compose:

admin@node-01.example.org:/docker/postgres-ha % docker-compose ps
   Name                 Command                 State                    Ports
--------------------------------------------------------------------------------------------
postgres-ha   docker-entrypoint.sh -p 5433   Up (healthy)   5432/tcp, 0.0.0.0:5433->5433/tcp