Ansible

The Ansible role to install a PostgreSQL comes in two flavors:

  • standalone for single node installations
  • cluster featuring a primary/standby setup, supporting failover

Common Concepts

Both variants are built similarly, and share a common set of configuration options and tooling that is described here, for detailed information about each variant, visit the documentation for standalone and cluster.

To prevent service interruption, the standalone, as well as the cluster role, will only stop/restart the PostgreSQL service if explicitly told to do so. Otherwise, it will just start the service after the initial provisioning and otherwise not touch the running instance to avoid potential data loss or interference with manual processes.

Naming

To support running multiple instances per host, all names for services, folders, backups, etc. are prefixed with the concatenation of the variables environment_name and instance_name (<environment_name>-<instance_name>). Data is stored in the directory /storage/data/<environment_name>/<instance_name>

Backup

The database instance is backed up using pgBackRest. If started without any local data, restore will automatically be started if a remote backup is available.

Backups can be written to any S3 compatible bucket and are configured using the backup_s3_* variables. All backups are encrypted using the backup_password.

Warning

Make sure you never loose the backup_password which is used to encrypt all backups. Without this password, restore will not work.

Per default full and incremental backups are enabled, the schedules can be tuned using the backup_<full|incr>_schedule variables.

Superuser

The name as well as the password of the database superuser can be configured using the superuser_<username|password> variables.

Extensions

Several PostgreSQL extensions are available for installation by switching on the extension_*_enabled variables.

postgresql.conf

The roles manage all PostgreSQL configuration options needed to configure backup and clustering. Additional configuration options can be supplied using the variable extra_configuration.

- name: "database1"
  hosts: database1
  roles:
    - role: blcks.rds_postgresql.standalone
      #[...]
      extra_configuration:
        debug_pretty_print: "on"