Skip to content

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

ClickHouse 5 min read Announcement easyNovice

PostgreSQL + ClickHouse as the Open Source unified data stack

An open source stack pairs PostgreSQL as the transactional system of record with ClickHouse for analytics, connected by PeerDB for change data capture and the pg_clickhouse extension, which transparently offloads analytical queries from Postgres to ClickHouse. Two patterns are described: CDC replication for operational analytics on application data, and split-writes for high-volume logs, metrics and events that never need to live in Postgres. Adopting it involves creating a ClickHouse database, replicating via PeerDB, configuring pg_clickhouse and pointing queries at its tables, so application changes stay minimal. A managed version in ClickHouse Cloud swaps PeerDB for ClickPipes and preinstalls the extension.

Assumes: PostgreSQL basicsOLTP vs OLAP workloadschange data capture

Related posts

  • Postgres Meets Analytics: CDC From Neon to ClickHouse Via PeerDB

    Neon mediumAdept

    Neon serverless Postgres can serve as the transactional system of record while ClickHouse handles real-time analytics, with PeerDB streaming changes between them via Postgres logical replication. Setup involves creating a replication-capable user and a publication in Neon, enabling logical replication (wal_level=logical), creating a destination database and a user with insert/alter grants in ClickHouse, then defining peers and a CDC mirror in PeerDB with an initial snapshot and table selection. PeerDB, now owned by ClickHouse, is slated to power the Postgres CDC connector in ClickPipes.

  • 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.

  • 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.

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

    ClickHouse mediumAdept

    A Postgres-to-ClickHouse CDC pipeline is built with Debezium, Kafka Connect and a ClickHouse materialized view, keeping a ReplacingMergeTree table in sync with the 28M-row UK property price dataset under a mix of inserts, updates and deletes. Key configuration choices include REPLICA IDENTITY FULL (required for delete support), the pgoutput logical decoding plugin, per-row ordering via a single or hash-partitioned Kafka topic, and version/deleted columns in the ReplacingMergeTree engine. The ORDER BY is chosen for analytical access patterns, with the Postgres id appended last for uniqueness. The initial load uses the postgresql table function via INSERT INTO SELECT, which loads all 28M rows in about 80 seconds without tuning but requires pausing writes; Debezium's consistent snapshot is the alternative.

  • A universal interface: How QuintoAndar made ClickHouse plug-and-play with managed Postgres

    ClickHouse easyNovice

    QuintoAndar's customer data platform replaced a Lambda architecture (a Postgres hot layer plus Kafka Connect into a Delta landing zone processed by 24/7 Databricks jobs with costly MERGE INTO deduplication) by having its event gateway write about 900 million monthly events directly into ClickHouse Cloud, which also serves roughly 300 million API requests a month with sub-second reads. Hightouch's Customer Studio doesn't support ClickHouse as a source, so the team put ClickHouse Managed Postgres in front of it. The pg_clickhouse extension exposes ClickHouse tables as foreign tables, pushes joins and aggregations down to ClickHouse, and keeps Hightouch's Lightning Sync state tables in Postgres. The team reports negligible overhead from the extra hop, and any Postgres-compatible tool can now reach ClickHouse.

The quest for software engineering knowledge.

Look:
Layout: