How to Set Up PostgreSQL CDC with RisingWave

How to Set Up PostgreSQL CDC with RisingWave

Building a Real-Time Dashboard with RisingWave and Metabase

Set up PostgreSQL Change Data Capture with RisingWave in 5 steps. No Debezium, no Kafka, no middleware.

Prerequisites

  • PostgreSQL 10+ with logical replication enabled
  • RisingWave running

Steps

1. Enable Logical Replication on PostgreSQL

-- postgresql.conf
-- wal_level = logical

-- Create a publication
CREATE PUBLICATION my_pub FOR TABLE orders, customers;
-- Create a replication role
CREATE ROLE rw_replication WITH REPLICATION LOGIN PASSWORD 'password';
GRANT SELECT ON orders, customers TO rw_replication;

2. Create CDC Source in RisingWave

CREATE SOURCE pg_source WITH (
  connector = 'postgres-cdc',
  hostname = 'pg-host', port = '5432',
  username = 'rw_replication', password = 'password',
  database.name = 'mydb',
  slot.name = 'rw_slot',
  publication.name = 'my_pub'
);

3. Create CDC Tables

CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT, amount DECIMAL, status VARCHAR)
FROM pg_source TABLE 'public.orders';

4. Build Real-Time Views

CREATE MATERIALIZED VIEW order_stats AS
SELECT status, COUNT(*), SUM(amount) FROM orders GROUP BY status;

5. Query

SELECT * FROM order_stats; -- Always reflects current PostgreSQL state

Frequently Asked Questions

Does CDC affect PostgreSQL performance?

Minimal impact. CDC reads the WAL (write-ahead log) that PostgreSQL already writes. Typical overhead is <5%.

How do I handle schema changes?

Currently, schema changes require updating the RisingWave source definition. Automatic schema evolution support is improving.

Best-in-Class Event Streaming
for Agents, Apps, and Analytics
GitHubXLinkedInSlackYouTube
Sign up for our to stay updated.