Skip to content

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

Supabase 7 min read Announcement easyNovice

pg_crdt - an experimental CRDT extension for Postgres

pg_crdt is an experimental, open-source Postgres extension that adds CRDT column types (wrapping the Yjs and Automerge Rust libraries via pgx), so a column like a post's content can be a Yjs Doc whose updates are commutative and idempotent. Supabase argues for storing CRDTs in the database rather than making Realtime the authoritative server, to avoid coupling and enable tools like Debezium, while allowing per-column choice between last-write-wins and CRDT merging. Known limitations block production use: WAL-based broadcast sends the whole document on small edits, frequent updates generate heavy WAL and dead tuples, and large documents incur serialization overhead.

Related posts

  • Comparing local-first frameworks and approaches

    Neon easyNovice

    Local-first software keeps data on the user's device and syncs opportunistically, and three representative approaches take different routes to it. Automerge uses CRDTs to merge concurrent edits without a coordinating server. PouchDB is a browser-side document database that syncs with CouchDB and resolves conflicts by deterministically picking a winning revision while keeping the losers for manual resolution. ElectricSQL is a server-side sync engine that reads Postgres logical replication and streams subsets of data ("shapes") to clients. Short code samples show each API, framed by the seven ideals of the Ink & Switch local-first manifesto.

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

  • Postgres to ClickHouse: Data Modeling Tips V2

    ClickHouse mediumAdept

    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.

  • Introducing chdb Postgres extension: High-performance imports from cloud storage

    ClickHouse mediumAdept

    chdb is a new Postgres extension that uses the in-process ClickHouse engine chDB to import and export data in dozens of formats (CSV, JSON, Parquet, Avro, Arrow, ORC, Protobuf and more) from S3, GCS, Azure, HDFS, HTTP and local files, via a chdb_query() function and a chdb_hook module that extends COPY and CREATE TABLE. Importing a 1M-row NYC Taxi dataset from S3, pg_duckdb and pg_lake took 2-3x longer than chdb, and only aws_s3, which supports far fewer formats, came close. Rather than linking chDB into the backend or running a persistent service, chdb starts a helper process on demand and streams ClickHouse Native-format results over file descriptors, then exits, so the Postgres server pays no lasting memory cost and is isolated from out-of-memory failures. Type mapping goes through pg-clickhouse-c, with a structure option to override mappings such as Postgres JSON to ClickHouse JSON.

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