Configure with YAML Files
This how-to shows how to run pgwatch with YAML files instead of the PostgreSQL configuration database. Use it when you prefer to keep configuration in version control, manage it with Ansible or another config-management tool, or simply avoid standing up an extra database.
For the PostgreSQL-based alternative, see Tutorial: Custom installation — single happy path. For background on the two modes, see Concept: Installation options.
Prerequisites
- A running PostgreSQL instance to host the metrics sink (any version 14+)
- An OS user that owns the YAML files and the systemd unit
Steps
-
Create the configuration directory and write a
sources.yaml:sudo mkdir -p /etc/pgwatch sudo chown pgwatch:pgwatch /etc/pgwatch sudo -u pgwatch tee /etc/pgwatch/sources.yaml > /dev/null <<'YAML' - name: my_database kind: postgres conn_str: postgresql://pgwatch:secret@db-host:5432/mydb preset_metrics: exhaustive is_enabled: true group: default # - name: the_second_monitored_database # kind: postgres # conn_str: postgresql://... # ... YAML -
Create the sink database:
pgwatch creates the schema in this database automatically on first start. To do it explicitly:
-
Start pgwatch, pointing it at the YAML file:
-
Wait up to two minutes for the refresh loop to pick up the new sources (tune via
--refresh).
Managing many sources
A folder of YAML files works just as well as a single file. Drop one file per monitored cluster into /etc/pgwatch/sources.d/ and pass the directory to --sources:
Environment variables can be referenced from inside YAML values, which keeps secrets out of source control:
Verifying the configuration
List the sources pgwatch has loaded:
You should see every entry from sources.yaml (or every YAML file in the sources directory).
Caveats
- The Web UI runs in read-only mode for sources/metrics/presets when pgwatch is configured from YAML — see Reference: REST API — note on YAML mode.
- The metric definitions file is separate from the sources file. Pass it with
--metrics=/path/to/metrics.yaml(or a directory). The defaults ship with the package.
See also
- Concept: Installation options — Config-DB vs YAML trade-offs
- Reference: CLI & environment variables — every
--sources,--metrics, and--sinkflag