Toolvito

Calculates on this device. File exports run online.

Database Replication Lag Calculator

See how far a replica is behind and why: the bytes a PostgreSQL standby is behind from two WAL locations or from pg_stat_replication, what SHOW REPLICA STATUS says about a MySQL replica, how long a replica needs to catch up from a backlog, and, from a log of lag samples, the 95th and 99th percentiles and every spike above your threshold.

Enter your values

From WAL locations or pg_stat_replication.

Your values

SELECT pg_current_wal_lsn(); on the primary.

SELECT pg_last_wal_replay_lsn(); on the standby.

In psql on the primary: \x then SELECT * FROM pg_stat_replication;

To turn bytes into time. Measure it from two pg_current_wal_lsn() readings.

Your values are worked out in this browser. They are not sent to a server.

Your result will show here

Fill in the values, then choose the button below them.

Read large exports of lag samples

Read large exports of lag samples

Choose up to 20 CSV files of lag samples of up to 1 GB each, such as an export from your monitoring. Each is read with the same rules as above, and you get the percentiles of each replica and every spike as CSV files.

Or drop files here. CSV, TSV or TXT, up to 20 files, 1 GB each at most.

    More options

    Everything above is worked out in your browser. When you use this box, the files you choose are sent to the Toolvito server. Download the result within one hour after the job finishes. Choose Delete files now to request earlier removal. The hourly cleanup normally removes files within one to two hours after completion.

    How to use it

    1. PostgreSQL: run SELECT pg_current_wal_lsn(); on the primary and SELECT pg_last_wal_replay_lsn(); on the standby, or paste SELECT * FROM pg_stat_replication; after \x.
    2. MySQL: paste the output of SHOW REPLICA STATUS\G from the replica.
    3. Lag samples: paste or open a CSV with a lag column (and time and replica columns), set the threshold and press Find the spikes.

    How it is worked out

    • A WAL location X/Y is the byte position X × 2^32 + Y in hexadecimal; the bytes behind are the difference (as pg_wal_lsn_diff).
    • Catch-up time = backlog ÷ (apply rate − write rate); if the replica applies no faster than the primary writes, it never catches up.
    • Percentiles are nearest-rank: the 95th percentile is the value at rank ⌈0.95 × n⌉ of the sorted samples. A spike is a run of consecutive samples above the threshold.

    Related tools