---
title: "Postgres to ClickHouse: Data Modeling Tips V2"
description: "Postgres CDC into ClickHouse (via PeerDB or ClickPipes) uses logical decoding and maps tables to ReplacingMergeTree."
url: "https://swe.quest/articles/postgres-to-clickhouse-data-modeling-tips-v2-421af33ac59693d5"
canonical: "https://clickhouse.com/blog/postgres-to-clickhouse-data-modeling-tips-v2"
source: "ClickHouse"
published: "2025-03-06"
difficulty: "medium"
kind: "How-to"
reading_minutes: 21
tags: ["analytics","postgres","event-driven","replication","sql"]
---

# Postgres to ClickHouse: Data Modeling Tips V2

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2025-03-06, 21 min read, How-to. Original: [https://clickhouse.com/blog/postgres-to-clickhouse-data-modeling-tips-v2](https://clickhouse.com/blog/postgres-to-clickhouse-data-modeling-tips-v2)

## Summary

Postgres CDC into ClickHouse (via PeerDB or ClickPipes) uses logical decoding and maps tables to ReplacingMergeTree. Updates and deletes arrive as versioned inserts, so queries can see duplicate or deleted rows until background merges run. The guide shows several ways to get Postgres-consistent results: the FINAL modifier or setting with \_peerdb\_is\_deleted filters, row policies, views, refreshable materialized views, and tuning force-merge settings. It also covers custom ordering keys, recommending immutable columns like tenant\_id and setting REPLICA IDENTITY to include them, plus JOIN optimization and denormalization.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Event-driven architecture](https://swe.quest/tags/event-driven.md) (Backend & APIs)
- [Replication](https://swe.quest/tags/replication.md) (Distributed systems)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- SQL ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))
- PostgreSQL basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- ClickHouse MergeTree tables ([easy posts on Analytics & OLAP](https://swe.quest/tags/analytics.md?difficulty=easy))
- change data capture

## Keywords

ClickHouse, PostgreSQL, ReplacingMergeTree, ClickPipes, PeerDB, logical decoding, refreshable materialized views, FINAL

## Related posts

- [Postgres to ClickHouse: Data Modeling Tips](https://swe.quest/articles/postgres-to-clickhouse-data-modeling-tips-aec1f81e14af15d4.md): ClickHouse · 2024-08-28 · Medium · 9 min read · Analytics & OLAP, PostgreSQL, Event-driven architecture, SQL, Replication
  Postgres tables replicated to ClickHouse via PeerDB land in ReplacingMergeTree tables where updates and deletes arrive as versioned inserts (\_peerdb\_version, \_peerdb\_is\_deleted), so duplicates persist until background merges run.
- [Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 2](https://swe.quest/articles/change-data-capture-cdc-with-postgresql-and-clickhouse-part-2-2123f803752f2e9d.md): ClickHouse · 2023-06-15 · Medium · 22 min read · Event-driven architecture, PostgreSQL, Analytics & OLAP, Data pipelines, Replication
  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.
- [Change Data Capture (CDC) with PostgreSQL and ClickHouse - Part 1](https://swe.quest/articles/change-data-capture-cdc-with-postgresql-and-clickhouse-part-1-10e3d601e2748dab.md): ClickHouse · 2023-06-15 · Medium · 23 min read · Event-driven architecture, PostgreSQL, Analytics & OLAP, Replication, Queues & messaging
  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.
- [Postgres CDC in ClickHouse, A year in review](https://swe.quest/articles/postgres-cdc-in-clickhouse-a-year-in-review-6b9d350bcade98d4.md): ClickHouse · 2025-12-03 · Medium · 13 min read · PostgreSQL, Event-driven architecture, Data pipelines, Analytics & OLAP, Replication
  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.
- [PostgreSQL + ClickHouse as the Open Source unified data stack](https://swe.quest/articles/postgresql-clickhouse-as-the-open-source-unified-data-stack-2760f19ba52907df.md): ClickHouse · 2026-01-27 · Easy · 5 min read · PostgreSQL, Analytics & OLAP, Event-driven architecture, Replication
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
