pg_reactive
pg_reactive · Live SQL query subscriptions with result deltas over LISTEN/NOTIFY
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 101987 | pg_reactive | pg_reactive | 0.1.8 | FEAT | PostgreSQL | C |
PostgreSQL · 15, 16, 17, 18
| Relationships | |
|---|---|
| Requires | plpgsql |
Usage
Sources:
- PGXN 0.1.8 README
- Control file
- Versioned extension SQL
- Module initialization
- Current standalone extension guide
- Current extension control
- Project changelog
pg_reactive turns PostgreSQL SELECT queries into subscriptions and sends changed result rows through LISTEN/NOTIFY. Version 0.1.8 supports PostgreSQL 15–18, requires preloading and a restart, and exposes privileged subscription APIs in the pgr schema.
Enable and Subscribe
Add the library to the existing preload list, then restart PostgreSQL. The installation SQL also uses plpgsql, normally installed by default.
Run this example as the extension owner or a trusted administrator, with each statement committed normally:
The extension tracks table and column dependencies, installs statement triggers, and computes set differences against UNLOGGED snapshots. The delta mode returns inserted/deleted rows; notify sends invalidation messages so the client can fetch results itself.
Interfaces and Configuration
pgr.subscribe(query_id, query, mode, audience)validates a SELECT and records its subscription; the last two arguments default to delta mode and a null audience.pgr.unsubscribe(query_id)removes the subscription, triggers, snapshot and durable catalog entry.pgr.get_subscriptions()andpgr.subscriptionsexpose active shared-memory state;pgr.stats()reports counters.pgr.subscription_meta(query_id)reads committed mode, audience and generation metadata for a proxy.pgr.persisted_subscriptionsis the durable subscription catalog.
pg_reactive.max_subscriptions, pg_reactive.async_recompute and pg_reactive.database require restart. Asynchronous recomputation is off by default; its worker uses the configured database. pg_reactive.batch_invalidation defaults to on and batches recomputation at transaction pre-commit. pg_reactive.notify_channel defaults to pgr; these last two settings are superuser-controlled at runtime.
Recovery and Security Boundaries
Shared memory is lost on restart. A trusted startup procedure must run the following once in each affected database; inspect warnings for subscriptions that could not be restored:
The 0.1.8 SQL script revokes public access to subscription functions and the view. Granting only pgr.subscribe() is insufficient because it calls restricted helpers and a restricted sequence. Do not expose arbitrary subscription SQL to untrusted roles; upstream specifies a purpose-built wrapper with fixed query templates and server-derived identifiers. Audience metadata is for enforcement by a trusted proxy, not per-subscription authorization on the shared notification channel.
Clients must re-fetch after an overflow or snapshot-layout change, a missed sequence, or reconnection. Notifications share one channel and are not a durable delivery queue. Registration generations identify re-subscriptions; clients/proxies must discard obsolete generations. Recomputing a large result set adds work to writes even when few result rows change.
The GitHub repository is now accessible. Its pgStack platform release 0.3.5 includes a lock-order fix for concurrent pgr.unsubscribe() calls, while the extension’s SQL version remains 0.1.8. This is a source/library fix, not an extension SQL-version bump; the older PGXN 0.1.8 archive is a separate artifact. Verify which source revision supplied the installed library before assuming the fix is present.