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 thepostgresql_versionvariable 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/custom→ Safe to edit manually. → Included at the end ofdhispg.conf, so it takes precedence.
Inclusion Order and Override Behavior¶
PostgreSQL processes configuration files in the following sequence:
postgresql.conf- → includes
dhispg.conf(Ansible-managed) - → 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¶
- Open or create the custom config file:
sudo nano /etc/postgresql/16/main/conf.d/custom
- Add or override parameters. For example:
work_mem = '32MB'
max_connections = 200
-
Save and exit the file.
-
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 |