Is there a way to measure logical replication lag in PostgreSQL?
Asked
Active
Viewed 3,563 times
1 Answers
8
You can check pg_catalog.pg_replication_slots
. Run this code on the master (publisher) server:
SELECT
slot_name,
confirmed_flush_lsn,
pg_current_wal_lsn(),
(pg_current_wal_lsn() - confirmed_flush_lsn) AS lsn_distance
FROM pg_replication_slots;
lsn_distance
is the measure of the replication lag.

Max Malysh
- 29,384
- 19
- 111
- 115
-
1FWIW, this appears to have been discussed here: https://www.postgresql.org/message-id/CY1PR17MB04587C36946F2C2BBA45B2B3DA560%40CY1PR17MB0458.namprd17.prod.outlook.com. I just almost created a Q&A identical to this one for my own work. Thank you! – mlissner Apr 25 '19 at 00:22
-
5what is the unit of this lag? Byte? – noobie2023 Jun 07 '22 at 06:25