Hacker News new | ask | show | jobs
Show HN: pg_stream – incremental view maintenance for PostgreSQL in Rust (github.com)
3 points by grove 115 days ago
pg_stream is a PostgreSQL 18 extension that keeps materialized views current incrementally — no external infrastructure, no separate streaming pipeline.

You define a stream table (a SQL query + a freshness bound) and the extension derives a delta query that processes only changed rows on each refresh cycle:

    SELECT pgstream.create_stream_table(
        'regional_totals',
        'SELECT region, SUM(amount) AS total, COUNT(*) AS cnt
         FROM orders GROUP BY region',
        '1m',
        'DIFFERENTIAL'
    );
One INSERT into a million-row table → pg_stream touches one row's worth of computation. Query it like any regular table.

How it works: - Trigger-based CDC captures row changes into buffer tables inside the same transaction (no wal_level = logical required) - A background worker walks a topological DAG of stream tables and fires refreshes in dependency order - The DVM engine (differential view maintenance, DBSP framework) rewrites your SQL into a delta query at definition time — JOINs, GROUP BY, CTEs, window functions, LATERAL, subqueries all supported - Stream tables can depend on other stream tables; a change to a base table cascades automatically through the entire chain

Written in Rust using pgrx. 1,300+ tests (unit + integration + E2E). dbt macro package included.

GitHub: https://github.com/grove/pg-stream Docs: https://grove.github.io/pg-stream

1 comments

This sounds cool, adding to my list of things to try out.

One note, this shouldn't be confused with https://github.com/xataio/pgstream which does logical replication/CDC with DDL changes.

We've renamed the project to pg_trickle: https://github.com/grove/pg-trickle
Thanks. Naming is hard, but we'll look into it.