Technologies/PostgreSQL/postgresql.replication.replay_lag
PostgreSQLPostgreSQLMetric

postgresql.replication.replay_lag

Replication replay lag
Dimensions:None
Available on:Native (1)DatadogDatadog (1)
Interface Metrics (2)
Native
replay_lag statistic from pg_stat_replication
Dimensions:None
DatadogDatadog
Time elapsed between flushing recent WAL locally and receiving notification that this standby server has written, flushed and applied it. This can be used to gauge the delay that synchronous_commit level remote_apply incurred while committing if this server was configured as a synchronous standby. Only available with postgresql 10 and newer.
Dimensions:None

Technical Annotations (30)

Configuration Parameters (8)
wal_keep_segmentsrecommended: increase from default
number of WAL segments to retain in pg_xlog directory
max_wal_sendersrecommended: increase from default
maximum concurrent WAL sender processes allowed
archive_moderecommended: on
enable WAL archiving to preserve segments
archive_commandrecommended: configured to alternate path
command to archive WAL files to backup location
max_replication_slotsrecommended: 10
maximum replication slots for lag tracking
wal_compressionrecommended: on
reduces WAL size and network transfer for replication
max_standby_streaming_delayrecommended: 30s
maximum time standby waits before canceling queries during replay
hot_standby_feedbackrecommended: on
prevents query cancellations on standby by informing primary
CLI Commands (7)
SELECT client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, pg_wal_lsn_diff(sent_lsn, replay_lsn) AS replay_lag_bytes FROM pg_stat_replication;diagnostic
SELECT client_addr, state, sent_lsn, write_lsn, flush_lsn, replay_lsn, pg_wal_lsn_diff(sent_lsn, replay_lsn) AS lag_bytes FROM pg_stat_replication;monitoring
SELECT now() - pg_last_xact_replay_timestamp() AS replication_lag;monitoring
ALTER SYSTEM SET max_wal_senders = 10;remediation
ALTER SYSTEM SET wal_keep_segments = 64;remediation
ALTER SYSTEM SET max_standby_streaming_delay = '30s';remediation
ALTER SYSTEM SET hot_standby_feedback = on;remediation
Technical References (15)
WALcomponentWrite-Ahead Loggingconceptpg_xlogfile pathcheckpointconceptpostgres_exportercomponentpgwatchcomponentpg_stat_replicationcomponentWAL applicationconceptfailoverconceptstreaming replicationconceptWAL sendercomponentreplication slotcomponentWAL replayconceptreplication lagconceptclustering architecturesconcept
Related Insights (9)
WAL segment deletion causes replication lag and requires replica rebuildcritical
Replication lag causes replica data staleness and read inconsistencieswarning
Replication lag triggered by CPU saturation from bad query planscritical
Replication lag causes stale replica datacritical
Missing data on UPDATE/DELETE operations silently skipped in logical replicationwarning
Replication lag causing stale reads on standbywarning
Replication lag causes stale reads on replicaswarning

Streaming replication lag between primary and replica nodes increases, causing replicas to serve stale data. High lag indicates replica cannot keep up with primary write volume, network issues, or resource constraints on replica.

Replication lag threatens high availability and data consistencywarning
Long-running queries on read replica with hot_standby_feedback cause periodic CPU spikes on primarywarning