Skip to content

table-diff

This command compares the data in the specified table across nodes in a cluster and generates a diff report if any inconsistencies are found.

Syntax

./ace table-diff <cluster_name> <schema.table_name> [options]
  • cluster_name: The name of the pgEdge cluster in which the table resides.
  • schema.table_name: The schema‑qualified name of the table to compare across nodes.

Options

Option Alias Description
--dbname <name> -d Database name. Defaults to the first DB in the cluster config.
--block-size <int> -b Rows processed per comparison block. Default 100000. Honours ace.yaml limits unless --override-block-size is set.
--concurrency-factor <float> -c CPU ratio for the comparison of the blocks that differ (0.0–4.0, e.g. 0.5 uses half of available CPUs); the number of hash workers comes from --max-connections. Default 0.5.
--compare-unit-size <int> -u Deprecated: no longer used. ACE accepts it and writes a warning.
--output <json\|html> -o Report format. Default json. The result directory and the JSON report are always written; with html the HTML report is added. All of them share the same timestamped prefix.
--max-html-rows <int> Maximum number of rows for each node pair in the HTML report. Default 0, which means table_diff.max_html_rows from ace.yaml, or 10000 when that is not set either. There is no setting for "no limit"; set a large number instead. The JSON report contains every row that the diff collected. When max_diff_rows stops the diff before every block is compared, the summary of the report has diff_row_limit_reached, and more differences may exist.
--max-html-value-length <int> The number of characters of a value that the HTML report shows; a longer value is cut at the right side. Key values are never cut. Default 0, which means table_diff.max_html_value_length from ace.yaml, or 1024.
--nodes <list> -n Comma-separated node list or all. Up to three-way diffs are supported.
--table-filter <WHERE> -F Optional SQL WHERE clause applied on every node before hashing.
--against-origin <node> Limit the diff to rows whose node_origin matches this Spock node id or name (useful for failed-node recovery).
--until <timestamp> Optional commit timestamp fence (RFC3339) applied with --against-origin and --table-filter; excludes newer rows.
--max-connections <int> -M Number of connections that ACE opens to each node for one table-diff task. A value that you set, here or in the max_connections section of ace.yaml, is a strict limit for the whole task. 0 takes the value from ace.yaml; if it sets none, ACE opens 8 connections for cutting and hashing, and comparing the blocks that differ can use more (see Connections per node). Default: 0.
--block-timeout <int> Time limit in seconds for one query on one block: the hash of a block, or a key query or a row read of a block that differs. The sample query of --slicer is under this limit too; the cutter is not. When a query hits the limit, ACE cancels it on the server and the diff fails with an error that names the node and the range. 0 means no limit. Default: table_diff.block_timeout from ace.yaml, or 60.
--run-timeout <int> Time limit in seconds for the whole diff. When it is reached, ACE cancels all its queries on all nodes and the diff fails. 0 means no limit. Default: table_diff.run_timeout from ace.yaml, or 0.
--slicer <auto\|cutter\|sample> How to cut the table into blocks on the anchor node: cutter (exact blocks from the primary-key index; slow when many pages of the table are not all-visible), sample (block bounds from a TABLESAMPLE SYSTEM sample of about 10 keys per block, so the share of pages depends on --block-size: 0.01% for the default 100000, 1% for 1000; blocks are about --block-size rows only when the key does not follow the physical row order), or auto (ACE chooses from pg_stats and the visibility map, and takes the cutter if the sample shows that rows with near keys share heap pages). The result of the diff does not depend on it. sample cannot be used with --table-filter, --against-origin or --until, or with a partitioned table or a table with child tables. Default: table_diff.slicer from ace.yaml, or auto.
--override-block-size -B Skip block-size safety checks defined in ace.yaml.
--quiet -q Suppress progress output. Results still write to the diff file.
--debug -v Enable verbose logging.
--schedule -S Run the diff repeatedly on a timer (requires --every).
--every <duration> -e Go duration string (for example, 15m, 1h30m). Used with --schedule.

Example

Compare a table across all nodes and write a JSON report (add --output html to emit both JSON and HTML using the same <schema>_<table>_diffs-<timestamp> prefix):

./ace table-diff acctg public.customers_large

Sample Output (with differences)

2025/07/22 12:03:51 INFO Cluster acctg exists
2025/07/22 12:03:51 INFO Connections successful to nodes in cluster
2025/07/22 12:03:51 INFO Table public.customers_large is comparable across nodes
2025/07/22 12:03:51 INFO table-diff: 8 connections to node n1
2025/07/22 12:03:51 INFO table-diff: 8 connections to node n2
2025/07/22 12:03:51 INFO table-diff: 8 connections to node n3
2025/07/22 12:03:51 INFO Using 16 CPUs, up to 8 comparison tasks at the same time
Hashing initial ranges: 171 / 177 [=======================================================================>---] 1s | 0s
Analysing mismatches: 2 / 2 [=================================================================================] 0s | done
2025/07/22 12:03:53 INFO Table diff comparison completed for public.customers_large
2025/07/22 12:03:53 WARN ✘ TABLES DO NOT MATCH
2025/07/22 12:03:53 WARN Found 99 differences between n1/n2
2025/07/22 12:03:53 WARN Found 99 differences between n2/n3
2025/07/22 12:03:53 INFO Diff report written to public_customers_large_diffs-20250722120353.json

Sample Output (no differences)

2025/07/22 12:05:59 INFO Cluster acctg exists
2025/07/22 12:05:59 INFO Connections successful to nodes in cluster
2025/07/22 12:05:59 INFO Table public.customers_large is comparable across nodes
2025/07/22 12:05:59 INFO table-diff: 8 connections to node n1
2025/07/22 12:05:59 INFO table-diff: 8 connections to node n2
2025/07/22 12:05:59 INFO table-diff: 8 connections to node n3
2025/07/22 12:05:59 INFO Using 16 CPUs, up to 8 comparison tasks at the same time
Hashing initial ranges: 168 / 177 [======================================================================>----] 1s | 0s
2025/07/22 12:06:01 INFO Table diff comparison completed for public.customers_large
2025/07/22 12:06:01 INFO ✔ TABLES MATCH

How table-diff Works

ACE optimises comparisons with multiprocessing and block hashing:

  • It splits work into blocks (--block-size) and computes their hashes with several workers per node, one per connection (--max-connections). If hashes mismatch for a block, each node reads the key and a short hash of every row of the block once; the keys of the node with fewer rows go into a map, and the other node is checked against it. Only the rows that differ are then read in full, by primary key. The keys of one block may use at most table_diff.key_map_max_memory_mb of memory (default 512). --concurrency-factor sets how many such comparisons run at the same time.
  • Runtime factors include host resources (CPU/memory), allowed parallelism, table size and row width (e.g., large JSON/bytea/embedding columns can slow hashing), distribution of differences (widely scattered diffs trigger more block fetches), and network latency to database nodes.

Relations ACE does not compare

ACE compares heap tables, including partitioned tables whose partitions are all heap tables. It refuses everything else in the pre-checks, with a message saying why:

  • Foreign tables (file_fdw, postgres_fdw, and so on) are refused. schema-diff and repset-diff list the foreign tables they skip.
  • Views and materialized views are refused. schema-diff compares views as DDL only and lists the ones it skipped for data comparison. When a table with the same name and a leading underscore exists next to the view (for example public._events beside public.events), the message mentions it. That table may be the one behind the view: tiering extensions such as coldfront rename the real table this way and put a view in its place. If that is the case, compare the underscore table. The cold tier behind a coldfront view is a shared Iceberg catalog, so it has no per-node copies to compare, and a coldfront decoupled table has no PostgreSQL data at all.
  • Partitioned tables with foreign partitions, and inheritance parents with foreign children, are refused, naming the foreign relations. Comparing the heap parts of such a table while skipping the foreign parts is future work.
  • Sequences, indexes, composite types, and TOAST tables are refused with a message naming what the relation is.

If a view does stand in front of a coldfront tiered table, note that the archiver moves rows from the hot table into Iceberg on a schedule, and the drop of an archived partition reaches the other nodes through replicated DDL. In that window the hot table legitimately differs between nodes. To compare only rows still above the archive watermark, filter on the replicated watermark table:

ace table-diff my-cluster public._events \
  --table-filter "ts >= (SELECT cutoff_time FROM coldfront.archive_watermark WHERE schema_name = 'public' AND table_name = 'events')"

Tuning tips

  1. Tune --block-size, --max-connections and --concurrency-factor for your hardware and data profile.
  2. Use --table-filter/-F to narrow scope on very large tables.
    • Filters are applied inline (no temporary views) and recorded in the diff summary as both the raw filter and the effective filter (which also includes --against-origin/--until if set).
  3. Prefer --output html when you'll manually review diffs.
    • The HTML report shows at most max_html_rows rows for each node pair (default 10000). A row is one primary key: a value difference or a row missing on one node. Each row takes several kilobytes of markup, so a report with hundreds of thousands of rows is too large for a browser. When the diff has more rows, the report says so at the top and in each node pair section, and the full list stays in the JSON file. The report shows the blocks of the table in key order, and the rows of a block sorted by the text of the key, with all kinds of differences together. The last block shown can be cut.
    • The HTML report is built from the result directory, so you can build it again with other limits, without a database connection: see diff-report.
    • A repair plan that you build in a truncated report has rules only for the rows shown, and its default_action is skip. So when you run table-repair with that plan and the full diff file, the rows that the report did not show are not changed. The downloaded YAML starts with a comment that says this. To repair every row, run table-diff again with a larger --max-html-rows, or write the plan by hand.
    • Known limit: a plan rule matches a primary key and a kind of difference, not a node pair. With three or more nodes, a rule for a key shown in one pair also acts on the same key in another pair, even where the report hides it there. Check such keys before you run table-repair.
  4. Use --override-block-size sparingly; the guardrails in ace.yaml prevent allocations that can overwhelm memory.
  5. The max_diff_rows setting caps the number of differing rows that table-diff collects in a single run.
    • The cap applies globally across all node pairs combined, not to each pair individually. On a three-node cluster that diffs n1/n2 and n1/n3 at the same time, both pairs share the single cap. As a result, each pair can report fewer differences than the table actually contains. A row missing on one of three nodes counts once in each of its two pairs.
    • The cap is approximate. A block is compared completely or not at all, so the blocks that are in work when the cap is reached add their rows, and the result can have more rows than the cap. The blocks are compared in key order, so the result holds about the first differences by key.
    • The cap does not protect the memory of the client: the differing rows go to disk as soon as they are found. It limits the size of the result and the run time.
    • The table-diff stopped after reaching max_diff_rows warning indicates that the run hit the cap. Treat the reported result as partial whenever the warning appears. Re-run table-diff after each repair pass, and continue until the command reports TABLES MATCH.

Large divergence

When the number of differences between nodes is very large (approaching or exceeding max_diff_rows), table-diff emits a warning and stops enumeration early:

The diff result

When table-diff finds differences, it writes a result directory <schema>_<table>_diffs-<timestamp>/ next to the JSON report, with one file for each compared block that has differences. The JSON report is built from it. A run that fails, times out or is stopped writes no result. See diff-report for the layout. repset-diff and schema-diff write one result for each table.

Recovery-focused options

Use --against-origin when you need a diff scoped to transactions from a failed node; combine with --until to fence at a known commit timestamp. The diff summary records: - only_origin (raw id), only_origin_resolved (node name if known), origin_only (bool) - until (commit timestamp fence) - table_filter (raw) and effective_filter (combined predicates)

When running table-repair on an origin-only diff, you must pass --recovery-mode (see table-repair docs) or the repair will refuse to run.

Scheduling runs

Add --schedule --every=<duration> to keep the diff running on a loop. The command performs an initial comparison immediately, then repeats after each interval until you stop the process:

./ace table-diff --schedule --every=1h my-cluster public.orders

All other flags (--nodes, --block-size, --output, and so on) are reused for every iteration.