This collector is enabled by default.
What It Monitors
The WAL collector tracks:- Number of WAL segment files
- Total size of WAL segments in bytes
- Replication delays
- Archive command failures
wal_keep_size/wal_keep_segmentsconfiguration issues- Checkpoint configuration problems
Metrics Exposed
pg_wal_segments
Number of WAL segment files in the WAL directory. Type: GaugeLabels: None Example:
pg_wal_size_bytes
Total size of all WAL segment files in bytes. Type: GaugeLabels: None Example:
SQL Query Used
The collector uses thepg_ls_waldir() function:
The regex filter ensures only valid WAL segment files are counted, excluding archive status files and other metadata.
Configuration
Enable/Disable the Collector
Use Cases
Alert on WAL Accumulation
Detect when WAL segments are accumulating faster than they’re being recycled:Monitor WAL Disk Usage
Track WAL directory size growth:Detect Replication Issues
WAL accumulation often indicates replication problems:Capacity Planning
Ensure adequate disk space for WAL:Understanding WAL Segment Counts
Normal Ranges
Typical WAL segment counts depend on:- Database write activity
checkpoint_timeoutandmax_wal_sizesettings- Replication configuration
- Archive mode settings
- Low activity: 3-10 segments
- Moderate activity: 10-50 segments
- High activity: 50-100 segments
Concerning Patterns
- Constantly increasing: Archive command failures or stuck replication
- Sudden spikes: Large batch operations or checkpoint issues
- Hundreds of segments: Serious replication lag or misconfiguration
WAL Segment Size
WAL segment size is configurable at compile time (default: 16 MB):Permissions Required
The WAL collector requires:CONNECTprivilege on the database- Access to the
pg_ls_waldir()function - For PostgreSQL 10+:
pg_monitorrole - For PostgreSQL <10: This collector may not be available (check PostgreSQL version)
PostgreSQL Version Compatibility
This collector requires:- PostgreSQL 10 or later for
pg_ls_waldir()function - Earlier versions should use the
xlog_locationcollector instead
Related Collectors
- Replication - Monitor replication lag
- WAL Receiver Collector - Statistics on WAL receiver process (if enabled)
- Replication Slot Collector - Track replication slot usage (if enabled)
- X-Log Location Collector - Alternative WAL monitoring for older PostgreSQL versions (if enabled)
Troubleshooting WAL Accumulation
Check Archive Command Status
If archiving is enabled:Check Replication Slots
retained_bytes values indicate problems.
Review WAL Configuration
Check PostgreSQL settings:Remove Unused Replication Slots
Inactive replication slots prevent WAL recycling:Performance Considerations
The WAL collector:- Queries the WAL directory via
pg_ls_waldir() - Performs filesystem operations
- Has minimal performance impact
- Safe to query frequently
- Does not interfere with WAL writing or replication
Important Notes
WAL accumulation is normal during high write activity or planned replication delays. Only sustained growth or excessive counts indicate problems.