Back to blog

Replicating PostgreSQL To ClickHouse With WalShadow Part 2 - Performance And Operational Comparison Of WalShadow, PeerDB And Debezium

Lukáš Kozelnický
2026-11-26
18 min read
Featured image for Replicating PostgreSQL To ClickHouse With WalShadow Part 2 - Performance And Operational Comparison Of WalShadow, PeerDB And Debezium

This is part two of a three part series: part one: WalShadow open source · part two (this article) · part three: the fully managed stack on ClickHouse Cloud (coming soon).

In part one we explained why and how WalShadow reads the physical WAL, and walked through running the open source container against PostgreSQL with a practical example.

In this article we compare WalShadow with the two tools that use logical replication and are the popular ways to replicate data from PostgreSQL to ClickHouse: PeerDB, which is also what ClickPipes (ClickHouse's managed solution) runs, and Debezium with Kafka. All three ran from the same PostgreSQL into the same ClickHouse. We also measured recovery speed after failures.

In summary, WalShadow's physical replication was much cheaper on resources and faster to run. But the real differences show up from an operational perspective, in the tests for schema changes, large values and edge cases.

Testing Environment

Everything ran in Docker on one AWS m6a.large instance (2 vCPU, 8 GB RAM). We tested with PostgreSQL 18 and ClickHouse 26.9.

We tested several scenarios and workloads.

  • Initial load: an initial load of the orders table with 500,000 rows with different data types plus a big text value field that is TOASTed on PostgreSQL. No live traffic during this test.
  • Live traffic replication: 50 transactions per second, each with 40 rows (24 inserts, 12 updates, 4 deletes). That makes 1,200 inserts, 600 updates and 200 deletes per second, and about 120,000 rows in total.
  • Latency probe (runs during the live traffic replication test): one insert every 250 ms into a separate table, with ClickHouse polled every 20 ms.
  • Burst test: 1,000,000 inserts in 10 transactions, with no other traffic running.
  • Failure scenarios: the replicator stopped for 60 s under load, ClickHouse stopped for 60 s under load, and the replicator SIGKILLed 10 s into a 20 s load. Every replicator ran under restart: unless-stopped.
  • It is important to note that correctness was checked on values, not on row counts. After each window a verifier compared every column of every row against ClickHouse FINAL, counting missing, extra and mismatched rows as bad_rows.

Figure 1. The three replication pipelines from PostgreSQL to ClickHouse.

The three pipelines: WalShadow is one container decoding the physical WAL off the primary with no intermediate format; PeerDB is eight containers decoding on the primary with files in S3 and a raw table in between; Debezium to Kafka is two containers decoding on the primary with JSON in Kafka in between
The three pipelines: WalShadow is one container decoding the physical WAL off the primary with no intermediate format; PeerDB is eight containers decoding on the primary with files in S3 and a raw table in between; Debezium to Kafka is two containers decoding on the primary with JSON in Kafka in between

Throughput, Latency And Cost Results

Every tool ran the prepared scenarios and workloads one after another, on the same VM. The measurements are:

  • Latency (p50 / p99): the time from a row's commit in PostgreSQL until it is visible in ClickHouse. We measured it with the default settings and again with tuned settings (explained below the table).
  • Replicator CPU: the replication tool itself (for Kafka with Debezium it is Connect plus Kafka).
  • Source walsender CPU: the CPU used by the PostgreSQL process that sends changes to the replication tool (the walsender).
  • ClickHouse CPU: ClickHouse's own load.
  • WAL generated: what PostgreSQL wrote for the same load.
  • Burst visible: the total time from the start of the first commit until all 1M rows are in ClickHouse. After PG commit: the last part of that time, after PostgreSQL had finished its last commit. It shows how far behind the source the tool still was when the source finished.
  • Replicator RSS: the tool's memory after the burst.
  • Containers: a property of the deployment, not of a workload.

All CPU figures are averages over the 60 s, in % of one vCPU core.

MeasurementWorkloadWalShadowPeerDBDebezium → Kafka
Initial load500k row snapshot20.0 s26.5 s59.6 s
Live traffic latency p50 / p99, defaults2,000 rows/s, 60 s756 / 1,034 ms6,289 / 16,116 ms4,347 / 8,174 ms
Live traffic latency p50 / p99, tuned2,000 rows/s, 60 s120 / 140 ms689 / 1,283 ms399 / 787 ms
Replicator CPU, % of one core2,000 rows/s, 60 s3.923.231.2 (Connect 20.1 + Kafka 11.1)
Source walsender CPU, % of one core2,000 rows/s, 60 s0.34.23.9
ClickHouse CPU, % of one core2,000 rows/s, 60 s28.528.838.1
WAL generated2,000 rows/s, 60 s33.9 MB33.9 MB35.3 MB
Burst visible1M rows, 10 transactions8.8 s36.8 s49.6 s
… after PG commit1M rows, 10 transactions1.9 s31.2 s44.3 s
Replicator RSS after burst1M rows, 10 transactions359 MiB651 MiB1,251 MiB
Containersn/a182

What "tuned" means. Every tool collects changes into batches before it writes to ClickHouse, and the batch interval impacts its latency. Tuning lowered that one setting and nothing else:

  • WalShadow: flush_timeout_ms from 1,000 to 100 ms.
  • PeerDB: sync_interval from 10 s to 1 s.
  • Kafka with Debezium: Debezium polls PostgreSQL every 100 ms (poll.interval.ms, default 500 ms), and the ClickHouse Kafka engine flushes every 500 ms (kafka_flush_interval_ms, default 7.5 s).

Figure 2. CPU at 2,000 rows/s, % of one core.

CPU utilisation at 2,000 rows per second: WalShadow uses 3.9% of a core with the walsender at 0.3%, PeerDB 23.2% with the walsender at 4.2%, and Debezium with Kafka 31.2% with the walsender at 3.9%, while ClickHouse itself uses between 28.5% and 38.1%
CPU utilisation at 2,000 rows per second: WalShadow uses 3.9% of a core with the walsender at 0.3%, PeerDB 23.2% with the walsender at 4.2%, and Debezium with Kafka 31.2% with the walsender at 3.9%, while ClickHouse itself uses between 28.5% and 38.1%

Three things stand out from the performance results:

Default latency reflects batching rather than architecture. With default settings, each p50 is below the tool's own batch interval. Once tuned, WalShadow reached 120 ms p50. But this latency is not free. For a real production workload it makes more sense to leave the WalShadow defaults, because creating a lot of small parts in ClickHouse can cause more problems than the lower latency is worth.

The burst test is where the architecture shows its benefit for WalShadow. WalShadow had all one million rows visible 1.9 seconds after the last PostgreSQL commit, 8.8 seconds end to end. PeerDB needed 36.8 seconds and Debezium 49.6 seconds end to end.

WAL volume is the same for all three. What differs is the walsender, which used only 0.3% of a core for WalShadow compared to 3.9% to 4.2% when it runs logical decoding for PeerDB or Debezium.

Figure 3. Median latency at the 2,000 rows/s workload.

Visible latency with defaults versus tuned settings on a log scale: WalShadow 756 ms down to 120 ms, PeerDB 6,289 ms down to 689 ms, Debezium to Kafka 4,347 ms down to 399 ms
Visible latency with defaults versus tuned settings on a log scale: WalShadow 756 ms down to 120 ms, PeerDB 6,289 ms down to 689 ms, Debezium to Kafka 4,347 ms down to 399 ms

Why WalShadow Beats The Other Tools On Performance

The performance difference is the part that is really caused by physical versus logical replication. A logical walsender on PostgreSQL decodes every change, holds it until commit and runs an output plugin. In physical replication the walsender copies bytes that PostgreSQL already wrote.

Each of the tested tools has a different design:

  • WalShadow decodes heap tuples in parallel Rust decoders, and builds native ClickHouse blocks in one process. There is no intermediate format.
  • PeerDB pulls changes, stages batches as files in S3, loads them into a raw table, and then normalises them into the destination with INSERT … SELECT. Orchestration runs on Temporal.
  • Debezium serialises each change to JSON, Kafka stores it, and ClickHouse parses it again through a Kafka engine table and a materialised view into the target table.

Schema Changes And Other Operations

This is the part we were most curious about, because this is where CDC pipelines in general tend to drift without anyone noticing. A tool that mishandles an operation rarely stops. It keeps running with wrong data in ClickHouse. We tested 34 cases in three different groups for each tool, as much to understand the boundaries of each design as to score them.

  • 21 DDL schema changes: changes to the structure of a table that is already being replicated.
  • 8 daily operations: ordinary traffic with upserts, savepoints and updates of rows that hold large values.
  • 5 other operational cases: maintenance and utility commands.

Each case used its own small table, created before the pipeline started. We applied the change, wrote a few rows, and compared every column with ClickHouse FINAL, waiting up to 90 s for schema changes and 45 s for everyday operations.

Large values (TOAST) show up in several of the tested cases. In PostgreSQL, when a value is larger than 2 KB it is not stored in the table row but in a separate TOAST table. The original row keeps only a pointer to it. The table's replica identity configuration determines how replication tools handle this.

In the tables below, bold marks a case where the destination ended up different from the source while the pipeline kept running without reporting it.

DDL Schema Changes

We tested 21 structural DDL changes made on PostgreSQL and how the changes propagated to ClickHouse. For some tests we recorded convergence times.

#PostgreSQL changeWalShadowPeerDBDebezium → Kafka
1CREATE TABLE after startexact, 1.1 snot replicatednot replicated
2ADD COLUMN c textexact, 1.1 sexact, 10.3 scolumn never appears
3ADD COLUMN c int NOT NULL DEFAULT 42exact (old rows show 42), 1.1 sexact, 10.2 scolumn never appears
4RENAME COLUMN s TO s2exact, 1.1 ss2 added as a new column, old rows NULL in it, s frozens2 never appears, s NULL for new rows
5DROP COLUMN bexact (column dropped), 1.1 ssource columns exact, stale b keptsource columns exact, stale b kept
6ALTER COLUMN a TYPE bigintexact (column becomes Int64), 1.4 s2^40 stored as 0 (column stays Int32)2^40 stored as NULL
7ALTER COLUMN s TYPE int USING s::intexact (column becomes Nullable(Int32)), 1.7 svalues match, column stays Stringvalues match, column stays String
8ALTER COLUMN s DROP NOT NULLexact (column becomes Nullable), 1.1 sNULL stored as ''exact (only because our hand written DDL was Nullable up front)
9TRUNCATEexact (applied in source order), 1.1 signored, 3 stale rows remainignored, 3 stale rows remain
10ALTER TABLE … RENAME TO …_newlater rows not yet replicated (no warning logged)rows keep flowing (correct)rows go to a new topic nothing consumes
11ALTER COLUMN id TYPE bigint on the primary keyid 4294967296 stored as 0 (with or without a stop and supervisor restart)id 4294967296 stored as 0id 4294967296 stored as 0
12SET NOT NULL after backfillingexactexactexact
13DROP NOT NULL, then NULL valuesexactNULL stored as ''exact (only because our hand written DDL was Nullable up front)
14varchar(10) → varchar(100)exactexactexact
15numeric(6,2) → numeric(14,4) (rewrite)exact1234567890.1234 stored as NULLexact (only because our DDL used Decimal(38,10) up front)
16ALTER TYPE enum ADD VALUE, then use itexactexactexact
17Table with a GENERATED ALWAYS AS … STORED columnexactgenerated column NULL for rows changed by CDCgenerated column NULL for rows changed by CDC
18ADD COLUMN … GENERATED ALWAYS AS … STOREDexactcolumn never appearscolumn never appears
19New partition, DETACH PARTITION, writes to the detached tabledetached rows stay in the root's destination; the detached table gets only later rowsdetached rows stay; the detached table is not replicatedonly the initial load reaches the root's table; every later change goes to a per partition topic nothing consumes
20ALTER TABLE … SET SCHEMA otherlater rows not yet replicated (same as a rename)rows keep flowinglater rows go to a new topic nothing consumes
21SET UNLOGGED, write, SET LOGGED, writeexactnot applicable: PostgreSQL refuses SET UNLOGGED on a published tablerows written while unlogged never arrive (PostgreSQL allows SET UNLOGGED here, because Debezium's publication is FOR ALL TABLES)
Exact with no operator action17 of 219 of 21 (1 not applicable)8 of 21

We did not test DROP TABLE because what happens to the destination is a policy setting. All three keep the ClickHouse table by default.

WalShadow's four misses have a pattern: they are the cases where a table changes its identity (a rename, a move to another schema, a detached partition) or where the primary key changes type, which the v0.1 preview does not yet track. The primary key case caught all three tools. None of these are inherent to the physical approach, since the catalog change is right there in the WAL, so we expect them to be straightforward to close as the project matures. We are sharing the test cases and results with the WalShadow team so they can be turned into fixes and regression tests.

What Each Tool Does With DDL

WalShadow applies DDL itself in stream order. A CREATE or ALTER TABLE is a catalog change in the WAL, so it arrives between the rows exactly where it happened. Rows before it land in the old shape and rows after it in the new one.

PeerDB propagates only added columns. Everything else is not propagated by design, and the change becomes visible after the next sync interval.

Debezium does not propagate anything. The DDL on the ClickHouse side needs to be written manually. There is a setting, input_format_skip_unknown_fields: when 1, a new field disappears silently; when 0, the Kafka engine stops consuming at the first unknown field instead.

Daily Operations

Schema changes are relatively rare, but everyday operations like those in this test happen on every production database. When a CDC tool mishandles one, it usually does not stop. It keeps running and leaves ClickHouse with wrong or missing data.

OperationWalShadowPeerDB (two settings)Debezium → Kafka
INSERT … ON CONFLICT DO UPDATE / DO NOTHINGexactexactexact
SAVEPOINT + ROLLBACK TO in a committed transactionexactexactexact
DELETE parent with ON DELETE CASCADEexactexactexact
UPDATE parent key with ON UPDATE CASCADEexactexactexact
UPDATE … SET id = … (primary key change)exactexactexact
Large value written and updated in the same transaction (default replica identity)exactexact__debezium_unavailable_value
UPDATE leaving an older large value untouched (default replica identity)exactNULL__debezium_unavailable_value
The same UPDATE, after REPLICA IDENTITY FULL is switched onexactexactexact
Total8 exact7 exact, 1 silently wrong6 exact, 2 silently wrong

The PeerDB column was run with two non default settings that fix some of its failures. Both settings below are off by default. The tests "UPDATE with ON UPDATE CASCADE", "primary key change" and "large value written and updated in the same transaction" are exact only because of these settings.

  • PEERDB_CLICKHOUSE_ENABLE_PRIMARY_UPDATE=true, which fixed the primary key update and the update cascade. However, ClickPipes (managed PeerDB on ClickHouse Cloud) considers this setting experimental and not recommended for production.
  • PEERDB_CLICKHOUSE_CDC_STORE_ENABLED=true, which fixed the large value written and updated in the same transaction.

Kafka with Debezium uses the same manually written ClickHouse DDL and materialised views as the schema matrix, created once when the pipeline started, so it is only as exact as that DDL.

Other Operational Cases

These are maintenance and utility commands that run less often, but that every production database meets sooner or later. PeerDB ran with both settings off for these cases.

OperationWalShadowPeerDBDebezium → Kafka
TRUNCATE parent CASCADEexact on both tablesignored on both tables (3 + 6 stale rows)ignored on both tables (3 + 6 stale rows)
CREATE INDEX CONCURRENTLY + REINDEXexactexactexact
DELETE half the table + VACUUM FULL, then DMLexactexactexact
CLUSTER … USING, then DMLexactexactexact
REFRESH MATERIALIZED VIEWreplicated as a keyless table, with a duplicate row after refreshnot replicated (logical replication does not carry views)not replicated (logical replication does not carry views)
Total4 exact, 1 silently wrong3 exact, 1 silently wrong, 1 not applicable3 exact, 1 silently wrong, 1 not applicable

The materialised view case is an interesting one. Because WalShadow reads the physical WAL it can see the view's storage, which logical replication cannot, so it is the only tool that replicates it at all. The refresh is a full rewrite in PostgreSQL, and in the preview that arrives as a second copy of the rows rather than a replacement. It is another case we have passed on to the WalShadow team.

Recovery

Any component in the pipeline can fail for many reasons, so measuring robustness and recovery time is important.

Failure scenarioWalShadowPeerDBDebezium → Kafka
Replicator stopped 60 s: catch up36.6 s40.9 s106.2 s
ClickHouse stopped 60 s: catch up46.6 s157.6 s40.7 s
Replicator SIGKILL: catch up35.0 s269.8 s98.3 s
Slot retained after the replicator was down 60 s202 MB198 MB226 MB
Slot retained after ClickHouse was down 60 s168 MB367 MB378 MB
Raw / live row versions after SIGKILL2,357,735 / 1,700,8081,857,314 / 1,700,8081,874,469 / 1,700,808
Kafka stopped 60 s: catch up, defaultsn/an/a76.5 s, and 368.9 s in another run
Same, scheduled.rebalance.max.delay.ms=0n/an/a76.8 s

Every drill on every tool ended with bad_rows = 0. No tool lost data. The only differences are in recovery time.

Figure 4. Recovery time after each failure scenario.

Catch up time after each failure: replicator stopped 60 s, WalShadow 36.6 s, PeerDB 40.9 s, Debezium 106.2 s; ClickHouse stopped 60 s, WalShadow 46.6 s, PeerDB 157.6 s, Debezium 40.7 s; replicator SIGKILL, WalShadow 35.0 s, PeerDB 269.8 s, Debezium 98.3 s
Catch up time after each failure: replicator stopped 60 s, WalShadow 36.6 s, PeerDB 40.9 s, Debezium 106.2 s; ClickHouse stopped 60 s, WalShadow 46.6 s, PeerDB 157.6 s, Debezium 40.7 s; replicator SIGKILL, WalShadow 35.0 s, PeerDB 269.8 s, Debezium 98.3 s

WalShadow recovered in under a minute in every failure scenario. One operational note: the container exits roughly 40 to 50 s after ClickHouse becomes unreachable and relies on being restarted, so run it under a restart policy, which is the one line we added to the compose file in part one. With that in place recovery was fully automatic.

Conclusion

Under steady load all three tools were correct. WalShadow was the cheapest on resources by a wide margin, as it is only one container and about 4% of a core at a steady 2,000 rows/s. A million row burst finished less than two seconds behind the source commit. Its real advantage is schema handling. It applied 29 of 34 cases exactly, with no operator action: 17 of 21 DDL changes, all 8 daily operations and 4 of 5 other operational cases. For PeerDB and Debezium, schema change is the main ongoing operational cost. The handful of cases WalShadow does not yet cover are well defined, and we have shared them with the WalShadow team.

There are still things in the other tools' favour that matter: PeerDB's maturity and managed availability, and Kafka's fan out and replay.

In part three we move to ClickHouse Cloud, where ClickHouse runs managed WalShadow against its own Managed Postgres. We run it next to a ClickPipe on the same instance, so both see exactly the same writes.

Written by

Lukáš Kozelnický

ClickHouse Engineer, New Cadence

We are an independent ClickHouse consultancy. We help businesses deploy ClickHouse open source and ClickHouse Cloud, build solutions on top of ClickHouse for real-time analytics, observability and AI, and resolve performance and reliability issues with their existing deployments.

End of article Share