DBAtlas · Database operations atlas

Show replication status and lag

Oracle

-- Role and mode:
SELECT database_role, open_mode FROM v$database;
-- Data Guard lag:
SELECT name, value, unit FROM v$dataguard_stats
WHERE name LIKE '%lag%';

Apply lag and transport lag are the main Data Guard lag metrics; run this on the standby.

PostgreSQL

-- On the PRIMARY:
SELECT client_addr, state, sync_state,
       write_lag, flush_lag, replay_lag
FROM pg_stat_replication;
-- On the STANDBY:
SELECT now() - pg_last_xact_replay_timestamp() AS replay_lag;

replay_lag is the replay delay; sync_state = 'sync' indicates a synchronous replica.

MySQL

SHOW REPLICA STATUS\G
-- Before 8.0.22: SHOW SLAVE STATUS\G

Seconds_Behind_Source gives the lag; Replica_IO_Running and Replica_SQL_Running must be 'Yes'. SHOW SLAVE STATUS is an alias in 8.0.22–8.3 and was removed in 8.4.

SQL Server

SELECT ar.replica_server_name, drs.synchronization_state_desc,
       drs.log_send_queue_size, drs.redo_queue_size
FROM sys.dm_hadr_database_replica_states drs
JOIN sys.availability_replicas ar ON drs.replica_id = ar.replica_id;

For Always On. A large redo_queue_size means the secondary replica is falling behind.

MongoDB

rs.printSecondaryReplicationInfo()
// Detailed status: rs.status()

Shows how many seconds each secondary is behind the primary; optimeDate values are compared.

Redis

INFO replication
# Check the role, connected_slaves, master_repl_offset,
# and slaveN:...,offset=... lines

The difference between master_repl_offset and the slave offset gives the lag; master_link_status must be 'up'.

Open in DBAtlas →