Skip to content
For the complete DHIS2 documentation index, see llms.txt.

Manual PostgreSQL Overrides in an Automated Setup

Manually Override PostgreSQL Parameters

In this setup, PostgreSQL configuration is partially managed by Ansible. Some configuration files are automatically generated during playbook runs. This guide explains how to safely override PostgreSQL settings without having your changes lost during future deployments.

Note:

This example assumes you are using PostgreSQL version 16, so all paths reference /etc/postgresql/16/main/. The actual version depends on the value of the postgresql_version variable defined in your Ansible inventory or host vars.


Configuration File Structure

  • Ansible-managed file: /etc/postgresql/16/main/conf.d/dhispg.conf → Automatically generated by Ansible. → Do not edit directly — changes will be overwritten on each Ansible run.

  • User-managed override file: /etc/postgresql/16/main/conf.d/customSafe to edit manually. → Included at the end of dhispg.conf, so it takes precedence.


Inclusion Order and Override Behavior

PostgreSQL processes configuration files in the following sequence:

  1. postgresql.conf
  2. → includes dhispg.conf (Ansible-managed)
  3. → which includes custom (user-managed)

The last defined value for any parameter wins. Any setting in custom will override values from both dhispg.conf and postgresql.conf.


Steps to Safely Override Settings

  1. Open or create the custom config file:
sudo nano /etc/postgresql/16/main/conf.d/custom
  1. Add or override parameters. For example:
work_mem = '32MB'
max_connections = 200
  1. Save and exit the file.

  2. Reload PostgreSQL for changes to take effect:

sudo systemctl reload postgresql

Summary Table

File Path Managed By Editable? Notes
/etc/postgresql/16/main/postgresql.conf PostgreSQL No Includes Ansible-managed configs
/etc/postgresql/16/main/conf.d/dhispg.conf Ansible No Automatically overwritten on every playbook run
/etc/postgresql/16/main/conf.d/custom User (you) Yes Safely used for manual overrides