Pcornel
Databases · Replication & High Availability

Read Replicas and Replication Lag

Cheat sheet · https://pcornel.dk/topic.php?topic=6189

Back to the Topic

Answer

Read replicas serve read queries from asynchronous copies; replication lag means they may return stale data.

Remember

Route only lag-tolerant reads to replicas. Monitor lag and remove lagging replicas from the pool. Long queries on replicas can delay replay or be cancelled.

First checks

  • now()-pg_last_xact_replay_timestamp() — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

write on primary → shipped → applied on replica after lag → read

Where it usually breaks

Seconds_Behind_Source shows 0 when replication is stopped on some versions; check thread status too.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6189

Confirmation

Confirm action

Continue?