Search code examples
postgresqldatabase-replicationpostgresql-11

PostgreSQL — measure logical replication lag


Is there a way to measure logical replication lag in PostgreSQL?


Solution

  • 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.