xlog_location collector monitors the current transaction log (xlog) position on PostgreSQL servers.
Status
Default: Disabled Enable with:--collector.xlog-location
Metrics
pg_xlog_location_bytes
Type: GaugeDescription: PostgreSQL LSN (Log Sequence Number) being generated on primary or replayed on replica Labels: None Note: The LSN value is truncated to the low 52 bits to fit in a float64.
SQL Query
How It Works
The collector:- Checks if the server is in recovery (replica) or primary
- On primary: Returns current WAL write position (
pg_current_xlog_location()) - On replica: Returns last replayed WAL position (
pg_last_xlog_replay_location()) - Converts LSN to bytes and truncates to 52 bits
PostgreSQL Versions
Supported: PostgreSQL 9.x only PostgreSQL 10+ behavior: The collector detects PostgreSQL 10+ and logs a warning, skipping collection.Why Truncate to 52 Bits?
LSN values in PostgreSQL are 64-bit integers, but Prometheus stores metrics as float64. To avoid precision loss, the value is truncated using modulo2^52 (the mantissa size of float64).
This is sufficient for monitoring rate of change but may wrap around after ~4.5 petabytes of WAL.
Required Permissions
The monitoring user needs:- Execute permission on
pg_current_xlog_location()andpg_last_xlog_replay_location()functions - Granted to
PUBLICby default on PostgreSQL 9.x
Example Output
On Primary:Use Cases (PostgreSQL 9.x Only)
Monitor WAL Generation Rate
Estimate Replication Lag
Combine primary and replica metrics:Migration to PostgreSQL 10+
When upgrading from PostgreSQL 9.x to 10+:-
Disable this collector:
-
Use replacement collectors:
- WAL position monitoring: Built into
replicationcollector - WAL file monitoring: Use
walcollector - Replication lag: Use
replicationcollector
- WAL position monitoring: Built into
Function Name Changes in PostgreSQL 10
| PostgreSQL 9.x | PostgreSQL 10+ |
|---|---|
pg_current_xlog_location() | pg_current_wal_lsn() |
pg_last_xlog_replay_location() | pg_last_wal_replay_lsn() |
pg_xlog/ directory | pg_wal/ directory |
Example Migration
PostgreSQL 9.x configuration:Troubleshooting
Collector Skipped on PostgreSQL 10+
Expected behavior. The collector logs:wal and replication collectors instead.
Function Does Not Exist
On PostgreSQL 10+, you’ll see:Related
- wal collector (PostgreSQL 10+ replacement)
- replication collector
- PostgreSQL 10 xlog to wal renaming