NEW RasterizedDB 1.1.0 is out: sharding and the gateway, the message broker, roles and row-level security, compression, .NET on NuGet, and the enterprise edition. What's new ›
DOCS / ENTERPRISE / VERIFYING A LEDGER

Verifying a ledger

Verification checks that a database's hash chain is unbroken, that every anchor still matches it, and that every row of every ledger table is exactly what was committed. Run it from SQL on a live server with VERIFY LEDGER, or offline with the rdb-ledger-verify tool, as an auditor would, without trusting the running server. Run one of them on a schedule.

For what ledger tables, chains and anchors are, see Ledger tables.

From SQL

sql
VERIFY LEDGER;            -- the chain, its anchors, and every ledger table and vault
VERIFY LEDGER payments;   -- the chain, its anchors, and one table

Any role may run it. The answer is one text row per finding. Every line starts with its verdict, padded to ten characters:

VerdictMeaning
OKThis part is intact.
WARNINGNot a fault, but the check is weaker than it could be: no anchors are configured, or a sink holds no anchor yet.
UNKNOWNIt could not be checked: an anchor sink could not be read (unreachable, no credentials, a bad signature).
TAMPEREDIt does not match. Details follow on indented lines.

An intact database with one anchor:

text
OK        chain: 412 entries, head 9f2c4b0e5a17c3d2e8f9016b4a3c5d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1ad71a
OK        anchor dir:/mnt/worm/ledger: newest entry 412 matches the chain
OK        payments: 1250 row(s) match the chain
OK        accounts: 18 row(s) match the chain

With no anchor sink configured, the second line is:

text
WARNING   no anchors: the chain proves entries were not edited one by one, not that the whole chain was not rewritten (set ANCHOR TO, RDB_LEDGER_ANCHORS or ledger_anchor)

What is checked

  • The chain. Every entry's hash is recomputed from the one before it. The first bad entry is reported, with why.
  • Each anchor sink (the table's own ANCHOR TO sinks and every server-wide sink): every anchor it holds must name an entry the chain still has, with the same hash, unless an acknowledged rollback covers it.
  • Each table's rows. Every visible row is hashed again and matched, by its __ledger_ts stamp, against the digest the chain recorded when it was committed. Every row the chain says was inserted and not deleted must be present. An entry whose transaction failed after the entry was written is passed over.

What a finding looks like

A row that was changed, removed or added past the server:

text
TAMPERED  payments: 3 problem(s), 1247 row(s) match
          row stamped 1795701600000123 differs from what was committed
          row stamped 1795701600000456 is missing, and the chain records no deletion of it
          row stamped 1795701600000789 is not in the chain: written past the guard

The other row findings are row stamped … was deleted in the chain but is present and row stamped … appears more than once: a copy written past the guard. Up to 50 problems are listed per table, then … and N more.

An edited chain file:

text
TAMPERED  chain: entry 7's hash does not follow from the one before it (first bad entry 7)

A chain that was recomputed after an edit, or cut back to an older state (a rollback), still links up, but no longer matches what was anchored:

text
TAMPERED  anchor dir:/mnt/worm/ledger: entries [398, 399, 400] were anchored with other hashes or are gone from the chain: it was rewritten or rolled back (ACKNOWLEDGE LEDGER ROLLBACK records a restore)

When the server finds the chain damaged as it opens a database, it stops ledger writes, and VERIFY LEDGER fails with the same reason instead of answering:

text
ERROR:  the ledger chain /mnt/ledger/var_lib_rasterizeddb/chain.log is broken at entry 7: entry 7's hash does not follow from the one before it; ledger writes stop until it is examined

After a restore

Restoring a backup puts the data, and the chain if it lives in the data directory, back to an older state. Anchors written after that point then name entries the restored chain does not have, and VERIFY LEDGER reports them as TAMPERED, exactly as it would a rollback by an intruder.

Once you have confirmed the restore was yours, record it. A superuser runs:

sql
ACKNOWLEDGE LEDGER ROLLBACK 'restored the 2026-11-20 backup after the disk failure, ticket OPS-311';
text
rollback acknowledged by admin: 3 anchored head(s) past the restored chain; reason: restored the 2026-11-20 backup after the disk failure, ticket OPS-311

The acknowledgement is added to the chain itself, with the role and the reason, and is anchored like any entry, so it stays on record for good. From then on VERIFY LEDGER accepts those anchors. If every anchor already matches, the answer is nothing to acknowledge: every anchor matches the chain. The reason is required.

With rdb-ledger-verify

rdb-ledger-verify checks a chain and its anchors without a running server, and with --data also opens a copy of the data directory and checks every ledger table's rows. It ships in the enterprise archive (see Installing).

text
rdb-ledger-verify --store <data directory as the server ran with it>
                  [--data <a copy of it, or the directory of a stopped server>]
                  [--default-db <name>] [--ledger-dir <dir>] [--anchor <sink>]…

Flags

FlagDefaultWhat it does
--store <path>requiredThe data directory's path exactly as the server ran with it (its --location). The chain and the anchors are found by this name, so give the served path even when checking a copy elsewhere.
--data <path>noneOpens this data directory and checks every ledger table and vault of every database in it against that database's chain. Give a copy (a restored backup, a snapshot) or the directory of a stopped server: opening takes the directory's lock, so a running server's directory is refused, and opening may replay its write-ahead log.
--default-db <name>rasterizeddbThe name the database in the directory itself is opened as. Pass the server's --pg-default-db (postgres unless you changed it) so the names in the report match. Used only with --data.
--ledger-dir <dir>RDB_LEDGER_DIRThe ledger directory the server used (its ledger_dir or RDB_LEDGER_DIR). Without either, the chain is read from <store>/rdb_ledger/chain.log.
--anchor <sink>RDB_LEDGER_ANCHORSAn anchor sink to check, dir:<path> or s3://<bucket>/<prefix>. Repeat it for several. Sinks in RDB_LEDGER_ANCHORS are checked too. With --data, each table's own ANCHOR TO sinks are checked as well.
-h, --helpPrints the usage line and exits with code 2.

Flag values are separate arguments: write --store /var/lib/rasterizeddb, not --store=/var/lib/rasterizeddb.

S3 sinks use the same environment as the server: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN, AWS_REGION, and RDB_LEDGER_S3_ENDPOINT or AWS_ENDPOINT_URL (see Anchor settings). Read-only credentials are enough.

Examples

The chain and anchors of the default database, on the server host, with the chain on its own disk:

sh
rdb-ledger-verify \
  --store /var/lib/rasterizeddb \
  --ledger-dir /mnt/ledger \
  --anchor dir:/mnt/worm/ledger \
  --anchor s3://audit-anchors/rasterizeddb
text
OK        chain /mnt/ledger/var_lib_rasterizeddb/chain.log: 412 entries, head 9f2c4b0e5a17c3d2e8f9016b4a3c5d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1ad71a
OK        anchor dir:/mnt/worm/ledger: newest entry 412 matches the chain
OK        anchor s3://audit-anchors/rasterizeddb: newest entry 412 matches the chain

A database other than the default lives in <location>/<name>: check its chain with --store /var/lib/rasterizeddb/shop.

Every row too, from a restored copy of the data directory:

sh
rdb-ledger-verify \
  --store /var/lib/rasterizeddb \
  --ledger-dir /mnt/ledger \
  --data /srv/restore/rasterizeddb \
  --default-db postgres \
  --anchor dir:/mnt/worm/ledger

The chain and anchor lines come first. Then each table's line, with its database in brackets; passing chain and anchor lines are not repeated:

text
OK        payments: 1250 row(s) match the chain   [postgres]
OK        orders: 88 row(s) match the chain   [shop]

Each database found under --data is checked against the chain of the same database under --store: the copy's path with its root replaced by the served one.

Output and exit codes

The lines are those of VERIFY LEDGER, except that the chain line names the file it read, and a last entry cut short by a crash is noted as (a torn last append, ignored).

Exit codeMeaning
0Everything checked is intact. WARNING lines do not change this.
1At least one TAMPERED or UNKNOWN line.
2A usage error, an unknown argument, or a chain file, data directory or runtime that could not be opened. The reason is printed on standard error.

Signed anchors

When the server signs its anchors (see Signed anchors), give the verifier the public key SHOW LEDGER printed after verify key, in hexadecimal. Here it was saved to a file:

sh
export RDB_LEDGER_VERIFY_KEY="$(cat /etc/rasterizeddb/ledger-verify-key.hex)"
rdb-ledger-verify --store /var/lib/rasterizeddb --anchor dir:/mnt/worm/ledger

An anchor whose signature does not verify against it is reported as UNKNOWN anchor …: could not be read: an anchor's ML-DSA signature does not verify: it was not written by this database's key, and the exit code is 1. Without RDB_LEDGER_VERIFY_KEY (and without RDB_LEDGER_SIGNING_KEY in the verifier's environment) signatures are not checked. The server checks them the same way during VERIFY LEDGER.

On a schedule

Run the offline check from cron or a systemd timer, and alert on a non-zero exit code. A nightly cron job, as the user the anchors and chain are readable by:

text
# /etc/cron.d/rasterizeddb-ledger
30 2 * * * rasterizeddb /usr/local/bin/rdb-ledger-verify --store /var/lib/rasterizeddb --ledger-dir /mnt/ledger --anchor dir:/mnt/worm/ledger > /var/log/rasterizeddb/ledger-verify.log 2>&1 || logger -p user.err "ledger verification failed, see /var/log/rasterizeddb/ledger-verify.log"

To check the rows as well without stopping the server, restore the newest backup to a scratch directory and point --data at it (see Backup and restore).

From SQL, through psql, fail when any line is not OK or WARNING:

sh
psql -h db.example.com -U auditor -d postgres -At -c 'VERIFY LEDGER' \
  | grep -E '^(TAMPERED|UNKNOWN)' && echo 'ledger verification failed' >&2

The Studio LEDGER page runs VERIFY LEDGER from its VERIFY ALL button and shows the result as INTACT or PROBLEMS FOUND: see Secret vaults and keys.

Limits

  • VERIFY LEDGER and rdb-ledger-verify --data read every row of the checked tables into memory.
  • --data cannot open the directory of a running server. Check a copy, or stop the server.
  • rdb-ledger-verify without --data checks one chain, the one --store names. Run it once per database.
  • --data has no record of which transactions rolled back. A transaction that failed after its chain entry was written (a crash at commit) can make its rows read as missing offline, while VERIFY LEDGER on the server, which knows the outcome, passes over them. Confirm such a finding with VERIFY LEDGER.
  • Partitioned tables cannot be ledger tables, so they are never checked.
✓ page rendered in 136 µs axum + tera + htmx · no other javascript