Enable Log Parsing
This how-to turns on pgwatch's CSVLOG parsing so that PostgreSQL server log severities are counted per database and per instance.
For background, see Advanced features → PostgreSQL server log parsing.
Prerequisites
- The target PostgreSQL instance is configured to write logs in CSVLOG format (
log_destination = 'csvlog'inpostgresql.conf). - For local parsing mode: pgwatch runs on the same host as the database server and the OS user running pgwatch has read access to the log directory, plus the
pg_read_all_settingsrole. - For remote parsing mode: the monitoring user has the
pg_monitorrole andEXECUTEonpg_read_file(text, bigint, bigint).
Steps
-
Activate the
server_log_event_countsmetric on the source. The simplest way is to pick a preset that includes it (the built-infullpreset does) or to add it directly to the source's metrics list: -
Choose the parsing mode. pgwatch picks automatically:
- Local mode — used when the monitoring connection comes through a Unix socket or when the
data_directorysetting on the server matches whatpg_control_system()reports. - Remote mode — used otherwise; reads log blocks through
pg_read_file().
Local mode is preferred where possible — it avoids round-tripping log bytes through the SQL connection.
- Local mode — used when the monitoring connection comes through a Unix socket or when the
-
Tune the fetch interval. Each call reads up to 10 MB from a single log file. With high log volume, raise the interval to keep up; with low volume, lower it for finer-grained event counts.
-
Verify pgwatch is recording counts:
Look for rows in the
server_log_event_countsmetric family grouped by severity.
Notes
- The feature only stores counts, not log lines or usernames — safe for security-sensitive deployments.
- For binary PG upgrades via
pg_upgrade, helper functions that wrap log access may need to be re-installed afterwards.