When pt-table-checksum reaches its limits
For many years, pt-table-checksum was a mandatory tool for anyone running MySQL and MariaDB replication, and it did a great job: it found silent drift between a source and its replicas that nothing else could see. I remember so many customers being 100% sure their replicas were fully identical, and after a pt-table-checksum run, their faces literally changed, especially when it was related to financial columns!
But this tool relies on statement-based replication because the checksum query itself has to be replicated and run again on every replica. Today most topologies replicate rows, not statements, and that dependency has become a real limitation.
MySQL deprecated binlog_format in 8.0.34, with row-based replication as the only format left in the future.
One particularly dangerous limitation of pt-table-checksum becomes apparent in chained replication topologies using row-based replication.
While the tool can successfully calculate checksums on first-level replicas by forcing statement-based logging on the primary (while still available), these statements are converted into row events by intermediate replicas configured with binlog_format=ROW.
As a consequence, downstream replicas do not calculate checksums against their own data. Instead, they inherit the checksum results of their upstream replica.
This is worse than simply being unable to detect data drift: the tool may report inconsistencies on perfectly consistent replicas, miss genuine data drift, or incorrectly attribute an upstream replica’s differences to downstream replicas.
In other words, a successful checksum report does not necessarily mean that the entire replication topology is consistent.
Let’s test it
Here is a run on a small MariaDB 11.8 lab: a source, a replica r1, and a replica r2 that replicates from r1. All three use binlog_format=ROW and GTIDs, and r1 has log_slave_updates on, which a chain needs.
I changed a few rows directly on the replicas, with sql_log_bin=0 so nothing replicates:
- on r1: one row of test.t1 gets ‘ ‘ instead of NULL, and test.t2 gets an extra row;
- on r2: two rows of test.t1 get other values, and one row of test.t2 is deleted.
So test.t2 has 10,000 rows on the source, 10,001 on r1 and 9,999 on r2.

With Percona Toolkit 3.7.2, pt-table-checksum first refuses to run:
$ pt-table-checksum h=127.0.0.1,P=23306,u=root --databases test \
--tables t1,t2 --recursion-method=hosts
Replica 1ed770c99d6b has binlog_format ROW which could cause
pt-table-checksum to break replication.
Please read "Replicas using row-based replication" in the LIMITATIONS
section of the tool's documentation. If you understand the risks,
specify --no-check-binlog-format to disable this check.
That’s an honest warning. Most people then add the option the message suggests:
$ pt-table-checksum ... --no-check-binlog-format
TS ERRORS DIFFS ROWS DIFF_ROWS CHUNKS SKIPPED TIME TABLE
12-02T06:45:35 0 1 100000 0 4 0 0.347 test.t1
12-02T06:45:35 0 1 10000 1 1 0 0.031 test.t2
Differences found, so far so good. The results live in the percona.checksums table of each replica. The query from the documentation returns the same rows on both:
r1> SELECT tbl, chunk, this_cnt, source_cnt, this_crc, source_crc
FROM percona.checksums WHERE ...;
+-----+-------+----------+------------+----------+------------+
| tbl | chunk | this_cnt | source_cnt | this_crc | source_crc |
+-----+-------+----------+------------+----------+------------+
| t1 | 2 | 99000 | 99000 | 1e2ffea9 | 97bde01a |
| t2 | 1 | 10001 | 10000 | 1c00893e | 0 |
+-----+-------+----------+------------+----------+------------+
r2> (same query)
+-----+-------+----------+------------+----------+------------+
| tbl | chunk | this_cnt | source_cnt | this_crc | source_crc |
+-----+-------+----------+------------+----------+------------+
| t1 | 2 | 99000 | 99000 | 1e2ffea9 | 97bde01a |
| t2 | 1 | 10001 | 10000 | 1c00893e | 0 |
+-----+-------+----------+------------+----------+------------+
r2> SELECT COUNT(*) FROM test.t2;
+----------+
| COUNT(*) |
+----------+
| 9999 |
+----------+
r2 claims 10,001 rows in test.t2, but it has 9,999. Its this_cnt and this_crc are r1‘s values, copied. So r2 shows r1‘s extra row, which r2 doesn’t even have, and hides its own missing row and its two changed rows. A DBA reading this would “fix” the wrong thing on r2 and miss the real damage.
m-table-checksum
Before introducing this new tool, let’s have a look at the result using it on the same lab scenario:
$ m-table-checksum --source 127.0.0.1:23306 --discover --tables test.t1,test.t2
DIFF test.t1 chunk 1 on r1: rows 20000 vs 20000 (exact sync point)
different id=1234
DIFF test.t1 chunk 1 on r2: rows 20000 vs 20000 (exact sync point)
different id=999
different id=4242
DIFF test.t2 chunk 1 on r1: rows 10000 vs 10001 (exact sync point)
extra a=8,b="zz-extra"
DIFF test.t2 chunk 1 on r2: rows 10000 vs 9999 (exact sync point)
missing a=7,b="b-3"
2 table(s), 2 difference(s), 0 warning(s), 0 error(s), 1 sync point(s)
Every difference is reported on the right replica, down to the row. The rest of this post explains why pt-table-checksum can’t do this under row-based replication, and how m-table-checksum does it instead. (Output shortened: hashes and the per-table summary lines are cut.)
Why: the checksum travels through replication
pt-table-checksum never connects to a replica to compute anything. It runs the checksum on the source and lets replication carry the query to the replicas:
SET SESSION binlog_format = 'STATEMENT';
REPLACE INTO percona.checksums (db, tbl, chunk, this_cnt, this_crc, ...)
SELECT 'test', 't2', 1, COUNT(*), COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(...) AS UNSIGNED)), 10, 16)), 0)
FROM test.t2 ...;
In STATEMENT format, the binlog carries the query text. Each replica runs it again against its own rows and stores its own this_crc. pt-table-checksum then compares it with source_crc, the source’s value. That is the whole trick, and it only works while every hop carries the statement.
In ROW format, the binlog carries the rows the statement wrote, not the statement itself. That is exactly what happens on the second hop of a chain. r1 runs the statement, but its own binlog is in ROW format, so it logs the resulting row of percona.checksums. r2 receives that row and writes it as is: its this_crc is r1‘s checksum. r2‘s data is never read.

Only the first hop carries the query. From the second hop on, replicas receive results.
That’s why pt-table-checksum checks the binlog format of the replicas and refuses to run by default. The old workaround was to set every server to STATEMENT or MIXED format. That’s getting harder:
- MySQL deprecated binlog_format in 8.0.34, with row-based replication as the only format left in the future.
- Changing it, even for a session, needs a privilege that managed services often don’t give.
- MariaDB keeps both formats, but many MariaDB sites use ROW for the safety it brings: no unsafe statements, and the same rows everywhere.
I wanted a checksum tool that works because of row-based replication, not in spite of it.
The idea: read, don’t replicate
m-table-checksum connects to the source and to every replica, and each server computes its own checksums. Nothing goes through replication, so the binlog format is irrelevant.
The difficult bit is knowing when to read. As replication continues to run and the source keeps committing, two servers reading at slightly different times will always be slightly out of sync. The solution is InnoDB consistent snapshots: the tool takes a snapshot on each server, each snapshot being at the same GTID set G. Each server then checksums the same logical point at its own pace whilst replication continues.
A few things come for free:
- Nothing on the source. No checksum table. Super_read_only all over the place is perfectly acceptable.
- Every server is checked directly against the source. In a chain r2 is checked against the source, not against what r1 wrote.
- The row level answer is in the same snapshots. If a chunk differs, the tool compares that chunk row by row within the snapshots that identified the mismatch, so the answer is the same on two reads.

A sync point: one GTID set on every server
Putting every snapshot at G is what I call a sync point. It takes four steps:
- Catch up. Wait (with replication still running) until each replica has the source’s current position (MASTER_GTIDWAIT() on MariaDB, WAIT_FOR_EXECUTED_GTID_SET() on MySQL). That keeps the next step short.
- Stop the replicas. STOP SLAVE on MariaDB, STOP REPLICA SQL_THREAD on MySQL.
- Open the snapshot on the source and read G.
- Let each replica run exactly to G. START SLAVE UNTIL master_gtid_pos = G on MariaDB, START REPLICA SQL_THREAD UNTIL SQL_AFTER_GTIDS = G on MySQL. Once it’s stopped there, the tool takes the snapshot of the replica and restarts replication.
The order is critical: the replicas stop before G is read. A replica can therefore only ever have what the source had already committed and so can never be past G. In the lab we’ve seen a replica applier stopped 50 to 400ms per sync point under tens of thousands of transactions per second. Chains work too: r1 stops after G, G is already in r1’s binlog so r2 can get to it.
How exact is G?
Step 3 requires the snapshot and G to describe the same moment. That depends on the server.
| Source | How G is read | Exact? |
|---|---|---|
| MariaDB | BINLOG_GTID_POS(binlog_snapshot_file, binlog_snapshot_position) right after the snapshot | yes, lock-free |
| MariaDB 12.3+, binlog in InnoDB | snapshot position, then the first GTID after it in SHOW BINLOG EVENTS | yes, lock-free |
| Percona Server | Binlog_snapshot_gtid_executed | yes, lock-free |
MySQL, with --source-lock | LOCK TABLES t READ, snapshot, gtid_executed, unlock | yes, with a table lock |
| MySQL, default | snapshot and @@GLOBAL.gtid_executed in one round trip | no, a window of microseconds |
MariaDB is exact by design. The group commit leader holds LOCK_commit_ordered as it advances the binlog position and makes the group visible in InnoDB. Taking a consistent snapshot takes the same mutex. A snapshot therefore always sees complete commit groups, and its binlog position is precisely at the end of them. MariaDB 13.0 with the binlog in InnoDB will refuse BINLOG_GTID_POS(), but the snapshot position is still consistent: it reads the first GTID after it and steps back one per domain.
MySQL doesn’t. It makes the group visible in InnoDB first and then adds it to gtid_executed just afterward. For a moment the transaction is in the snapshot but not in G. On MySQL, a mismatch is only suspect until it’s confirmed, as described below. Percona Server closes that window with its Binlog_snapshot_gtid_executed status variable and the tool uses it automatically.
MariaDB replicas are also checked. A sync point is only exact if every replica has stopped at exactly G’s seq_no in every domain. If a replica stops just prior to a seq_no gap then the sync point is not exact and its mismatches are then confirmed as such in the same way as on MySQL.
Chunks, rows, and confirmation
The tool splits each table into key ranges (lo, hi] on the primary key or on the first unique index where all the columns are NOT NULL). The source snapshot provides the boundaries. Then the same query is run on every server in parallel:
SELECT COUNT(*),
BIT_XOR(CAST(CONV(SUBSTRING(MD5(CONCAT(
COALESCE(CONCAT(LENGTH(a),':',a),'N'),
COALESCE(CONCAT(LENGTH(b),':',b),'N')
)),1,16),16,10) AS UNSIGNED))
FROM app.t
WHERE ((a > ?) OR (a = ? AND b > ?))
AND ((a < ?) OR (a = ? AND b <= ?));
Each column is prefixed with its length, and NULL becomes N, so (‘ab’,’c’) and (‘a’,’bc’) hash differently, and so do NULL and ”. That’s how the lab’s ” instead of NULL on r1 was found. Bound values keep their type, so a DECIMAL or binary key is never compared as a lossy double. The chunk size adapts so a chunk takes about –chunk-time (0.5 s by default) on the slowest server.
When a chunk differs, the tool will hash each row of that chunk on both sides (still within the same snapshots).
In the initial example, each missing, extra, or differing row was identified by its key. Tables without a suitable key are checksummed as a single chunk, without the possibility of drilling down to individual row differences.
Confirmation, when G isn’t exact. On MySQL without –source-lock, a transaction caught in the window between visibility and gtid_executed makes a chunk look different. So a mismatch is re-checked at –confirm new, independent sync points (2 by default). Only rows that differ every time are reported. Real drift is still there next time; a transaction caught in flight is not. In the lab, the hot end of a table taking thousands of inserts per second was flagged once, then cleared by confirmation, while every injected row was confirmed.
Fixing the replicas
Finding drift is half the job. With --fix-dir DIR, the tool writes one SQL file per replica, with the statements that turn its differing rows into the source’s rows. It never runs them itself.
Here is the file for r2 from the opening example, shortened:
-- m-table-checksum fix SQL for replica 127.0.0.1:23308 (source 127.0.0.1:23306)
SET SESSION sql_log_bin = 0;
SET SESSION time_zone = '+00:00';
SET NAMES utf8mb4;
-- test.t1 chunk 1 ∞..(10000): 2 row(s), values at sync point GTID 0-1-34
UPDATE `test`.`t1` SET `k` = 83573, `c` = _utf8mb4 X'726F772D383939303020C3A920C3BC20E6BCA2', ...,
`n` = 0 WHERE `id` = 999 AND MD5(...) = '0860fe9c2743cfc6209064bf7739d9fb';
UPDATE `test`.`t1` SET ... WHERE `id` = 4242 AND MD5(...) = '...';
-- test.t2 chunk 1 ∞..(999,b-9): 1 row(s), values at sync point GTID 0-1-34
INSERT INTO `test`.`t2` (`a`, `b`, `v`) SELECT 7, _utf8mb4 X'622D33', _utf8mb4 X'767676' FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `test`.`t2` WHERE `a` = 7 AND `b` = _utf8mb4 X'622D33');
Running it in production
A checksum tool which is meant to stop replication has to be very careful. That’s what production sees.
Short, infrequent stops. Replicas only stop when they’ve caught up, so the stop duration is simply the time taken to read G and apply the final few transactions (50 to 400ms in the lab, reported per table as MAX_STALL). An InnoDB snapshot covers the entire instance, so a single sync point serves table after table until it is –max-snapshot-age old (30s by default). The age limit keeps undo and purge in check. On 200 small tables under load, this reduced the time from 158s to 1.3s on MariaDB and from 89s to 14s on MySQL.
MariaDB sync points are more expensive. On MariaDB, the UNTIL master_gtid_pos is evaluated by the source’s dump thread, so every sync point is a full STOP SLAVE and a reconnect. That’s another reason to reuse them (one sync point per table) as a lab replica fell 49s behind under load.
A trade-off: metadata locks. A snapshot transaction holds a shared metadata lock on every table it has read. A DDL on one of those tables will wait until the sync point is released (at most –max-snapshot-age). The tool itself never waits for DDL: its sessions have a 2s lock_wait_timeout and a table that hits that is simply rechecked on the next sync point. If DDL is very frequent, then you’ll want to use –reuse-sync-points=false or a shorter age.
Parallelism. –parallel N runs N workers, each with its own sync point. Once no table is left to start, idle workers will help with the big tables still running, provided the rest of the work would take at least 10s.
Load protection, as in pt-table-checksum, but checked on every server, since the checksum queries run on the replicas too:
- –max-lag (1s) causes a pause when a replica is lagging. The lag is measured between sync points so the tool’s own pauses don’t count.
- –max-load (Threads_running=25) will cause a pause whilst any server is above that level and –critical-load will cause an abort.
- –pause-file pauses whilst a file exists.
A paused worker releases its sync point so a long pause doesn’t hold a metadata lock or keep an old snapshot.
Interruptions: on an error, timeout, Ctrl-C or SIGTERM the replicas are restarted and any UNTIL is cleared. If the tool is killed with SIGKILL during a sync point the next run will find a marker indicating which replicas were stopped and will restart them. A lock per source prevents two runs from stopping the same replicas at the same time. With –resume FILE an interrupted run will simply resume from where it left off, from its last batch of chunks.
Output. One line per table in text, or –output json for JSON Lines. Exit code is 0 in sync, 1 when differences are found, 2 on errors, so it’s perfectly suited to a monitoring job.
Try it
m-table-checksum is a single Go binary. Credentials come from the command line, then ~/.my.cnf (or –defaults-file), then $MYSQL_PWD, and TLS takes the same –ssl-mode values as the client:
# find the replicas through SHOW SLAVE HOSTS / SHOW REPLICAS
# (needs report_host on them)
$ m-table-checksum --source db1:3306 --discover --parallel 4 \
--fix-dir /tmp/fix --resume /tmp/mtc.state
# or list them
$ m-table-checksum --source db1:3306 --replica db2:3306,db3:3306 \
--ssl-ca /etc/mysql/ca.pem --databases app --output json
Requirements and limits:
- GTIDs are required. On MariaDB, replicas must use MASTER_USE_GTID, and every server needs gtid_strict_mode=ON. Every sync point reconnects the replicas, and without strict mode a domain can go backward, so a reconnect can resend transactions already applied. I reproduced that in the lab without the tool: plain STOP SLAVE; START SLAVE broke replication with a duplicate key after 18 reconnects. The tool refuses to run without strict mode, unless you pass –allow-non-strict-gtid.
- Same flavor everywhere: MariaDB to MariaDB, or MySQL to MySQL. Default channel only: no multi-source, no Galera.
- InnoDB tables only. Replication filters show up as differences, and delayed replicas time out.
- Replicas must accept a stop of a few hundred milliseconds.
- Privileges are documented but not yet verified with a minimal account.
Conclusion
pt-table-checksum has served us well over the years, but its architecture is predicated on statement-based replication, and that’s going away. With row-based binlogs, it either won’t run at all or, on a chain, it will report the wrong replica. m-table-checksum works by reading rather than replicating: each server takes a snapshot of its own data and checksums that at the same GTID set. On MariaDB and Percona Server that GTID set is exact without any locking required. On MySQL a mismatch is confirmed before it is reported.
The code, the lab, and an illustrated walkthrough of every step are all at https://github.com/lefred/m-table-checksum. I’d be very interested to know how it works on your topologies (if you’re using MariaDB or MySQL). Open an issue or leave a comment below.