This collector is enabled by default.
What It Monitors
The replication collector tracks:- Replication lag in seconds (how far behind the replica is)
- Whether the instance is a replica or primary
- Age of the last transaction replay on replicas
Metrics Exposed
pg_replication_lag_seconds
Replication lag behind the primary in seconds. Type: GaugeLabels: None Values:
0- No lag (or instance is the primary)> 0- Lag in seconds behind the primary
pg_replication_is_replica
Indicates whether the PostgreSQL instance is a replica. Type: GaugeLabels: None Values:
1- Instance is a replica0- Instance is the primary
pg_replication_last_replay_seconds
Age of the last replayed transaction in seconds. Type: GaugeLabels: None Example:
SQL Query Used
The collector executes the following query:Configuration
Enable/Disable the Collector
Use Cases
Alert on High Replication Lag
Create alerts when replicas fall behind:Monitor Replication Health
Track replication lag over time:Verify Replica Status
Ensure your replica instances are properly configured:Detect Stale Replicas
Alert when the last replay is too old:Behavior on Primary vs Replica
On Primary Instances
pg_replication_lag_seconds=0pg_replication_is_replica=0pg_replication_last_replay_secondsmay be0or undefined
On Replica Instances
pg_replication_lag_seconds= seconds behind primarypg_replication_is_replica=1pg_replication_last_replay_seconds= age of last transaction replayed
Permissions Required
The replication collector requires:CONNECTprivilege on the database- Access to replication functions:
pg_is_in_recovery()pg_last_wal_receive_lsn()pg_last_wal_replay_lsn()pg_last_xact_replay_timestamp()
- For PostgreSQL 10+:
pg_monitororpg_read_all_statsrole - For PostgreSQL <10: Read access to replication functions
Related Collectors
- WAL Collector - Monitors Write-Ahead Log segments
- Replication Slot Collector - Tracks replication slot usage (if enabled)
- WAL Receiver Collector - Statistics on WAL receiver process (if enabled)
Performance Considerations
The replication collector:- Executes a single lightweight query
- Has minimal performance impact
- Queries system functions, not user tables
- Safe to run on both primary and replica instances