Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 5 min read Announcement mediumAdept

Introducing WalShadow: Sub-second Postgres replication to ClickHouse from physical WAL

WalShadow is an open-source engine that replicates Postgres to ClickHouse by decoding the physical WAL stream outside the source database, instead of using logical replication slots. It replays catalog records into a schema-only shadow Postgres to track schema changes, decodes heap records in parallel with Rust workers, batches rows into ClickHouse-native blocks and inserts them concurrently. Out-of-order arrival is handled by tagging rows with the source LSN, with barriers for schema changes and truncations. In a single-table benchmark on c8i.2xlarge instances it reached about 200 ms commit-to-visible latency and 289K rows/sec, versus about 10 s and 120K rows/sec for the logical-replication-based PeerDB.

Related posts

  • What I learned from a month with WalShadow on ClickHouse Managed Postgres

    ClickHouse mediumAdept

    WalShadow, which decodes physical Postgres WAL outside the database and writes blocks directly to ClickHouse, held median replication latency near 0.4 s from 1 to 200,000 rows/s on a 16 vCPU source. ClickPipes, which uses logical replication, tracked its Sync interval (about 31 s median at the 60 s default) and saturated around 50,000–55,000 rows/s regardless of interval or pipe compute size. Data matched exactly across source and both destinations, and schema changes, restarts, resizes and destination stops needed no manual action. Caveats include temporary cross-table inconsistency from parallel per-table writes, fixed `_commit_ts`/`_lsn` on initially loaded rows that can break TTLs, materialized views seeing raw row versions, and commit-ordered delays behind large transactions.

  • Postgres at Open House NYC

    ClickHouse easyNovice

    ClickHouse used its Open House NYC keynote to launch WalShadow, an open-source engine that replicates Postgres into ClickHouse from the physical WAL instead of logical replication. It decodes WAL outside the source and uses a schema-only shadow Postgres to track DDL, effectively making ClickHouse an analytical physical standby. On 8-vCPU instances it showed about 200 ms commit-to-visible latency and 300K rows/s, versus about 10 s and 120K rows/s for PeerDB. The keynote also opened a Google Cloud private preview of ClickHouse Managed Postgres and released a chdb Postgres extension that extends COPY to import from S3, GCS and Azure and outperformed DuckDB-based extensions on the NYC Taxi import benchmark.

  • Postgres CDC in ClickHouse, A year in review

    ClickHouse mediumAdept

    A year after PeerDB's acquisition, Postgres CDC into ClickHouse via ClickPipes has grown to 400+ companies replicating over 200 TB per month, driven by real-time customer-facing analytics and data warehousing workloads. Key engineering changes include keeping logical replication connections open, because reconnects re-read WAL from restart_lsn and spiked lag. CTID block-based partitioning cut initial-load partition generation from 7+ hours to under a second, and 50+ pre-flight checks plus bucketed user-facing alerts cut on-call load by orders of magnitude. The biggest remaining gap is data modeling overhead from ReplacingMergeTree's asynchronous deduplication, which ClickHouse plans to address with lightweight UPDATEs and unique indexes.

  • OLTP is expensive, you can ClickHouse it.

    ClickHouse easyNovice

    Data that has stopped changing doesn't need Postgres's ACID machinery, so it can be offloaded to ClickHouse for roughly an order of magnitude better unit economics. Postgres pays for durability, MVCC isolation and synchronous index maintenance on every write: a ~100-byte change touches several 8 KB pages and tens of KB of WAL. It also stores data in uncompressed row pages that thrash the cache once data outgrows RAM. The proposed pattern keeps writes and fresh-row reads in Postgres and replicates settled data to ClickHouse via CDC to serve reads and aggregations, with claimed 10–30× compression and ~100× cheaper aggregations. The cost is slower single-row reads and about a second of eventual consistency. ClickHouse Cloud features (NVMe Postgres, WalShadow CDC, the pg_clickhouse FDW) are pitched as the way to implement it.

  • Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 1

    ClickHouse mediumAdept

    Postgres-to-ClickHouse CDC can be built by streaming row changes from Postgres logical decoding (pgoutput plugin, replication slots, LSN ordering) through Debezium and Kafka, then applying them in ClickHouse with the ReplacingMergeTree engine. Updates and deletes become immutable inserts carrying a version column and a deleted flag, and background merges collapse duplicates. Correct results before a merge require FINAL at query time. Consumers must tolerate duplicate events after restarts, and deleted rows are only purged when clean_deleted_rows is set to Always, a setting with a known bug as of 23.5. The post also compares pull-based and push-based CDC and explains why a Kafka queue protects the Postgres WAL from growing when ClickHouse is unavailable.

The quest for software engineering knowledge.

Look:
Layout: