Documentationpg_stat_insights Documentation

WAL Activity Monitoring

Rank WAL-Hungry Queries

Monitor queries that generate the highest WAL volume to spot bulk writes, inefficient updates, or missing HOT optimisations.

Top WAL generators

SELECT queryid,
       LEFT(query, 120) AS query_preview,
       calls,
       wal_records,
       wal_fpi,
       wal_bytes,
       wal_bytes / NULLIF(calls, 0) AS wal_bytes_per_call
  FROM pg_stat_insights
 WHERE wal_bytes > 0
 ORDER BY wal_bytes DESC
 LIMIT 20;

Analyse WAL by Relation

Determine which tables or indexes contribute most to WAL traffic and evaluate whether autovacuum or fillfactor adjustments are needed.

Relation WAL usage

SELECT relid::regclass AS relation,
       wal_bytes,
       wal_fpi,
       shared_blks_dirtied
  FROM pg_stat_insights_relation
 ORDER BY wal_bytes DESC
 LIMIT 15;

Remediation Checklist

Configuration

  • Enable wal_compression = on for workloads with frequent full page images.
  • Review checkpoint_timeout and max_wal_size to avoid checkpoint storms.
  • Consider synchronous_commit = off for bulk ETL operations where durability trade-offs are acceptable.

Application tuning

  • Batch writes and use COPY to reduce per-row wal_bytes.
  • Use HOT updates (unchanged indexed columns) to minimise FPI generation.
  • Rebuild bloated indexes and adjust fillfactor to lessen page rewrites.