Skip to content

pg_streaming

Declarative stream processing engine inside PostgreSQL

pg_extensions · Declarative stream processing engine inside PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
101095pg_streamingpg_extensions0.3.6ETLMatroid-SAL-1.0Rust

PostgreSQL · 14, 15, 16, 17, 18

Usage

Sources:

pg_streaming version 0.3.4 is a declarative stream-processing engine whose pipelines, state, offsets, errors, and metrics remain queryable in PostgreSQL. Pipelines connect inputs to processor chains and outputs, then run under coordinator, executor, and timer background workers.

Core Workflow

Preload the library, restart PostgreSQL, create the extension in its configured database, and define a pipeline:

shared_preload_libraries = 'pg_streaming'
pg_streaming.database = 'postgres'
pg_streaming.worker_count = 2
CREATE EXTENSION pg_streaming;

SELECT pgstreams.create_pipeline(
    'active_orders',
    $json$
    {
      "input": {"table": {"name":"public.order_inbox", "offset_column":"id", "poll":"1s"}},
      "pipeline": {"processors": [{"filter":"value_json->>'active' = 'true'"}]},
      "output": {"table": {"name":"public.active_orders", "mode":"append"}}
    }
    $json$::jsonb
);

SELECT pgstreams.start('active_orders');
SELECT * FROM pgstreams.status();
SELECT * FROM pgstreams.metrics('active_orders');
SELECT pgstreams.stop('active_orders');

Lifecycle functions are create_pipeline, update_pipeline, drop_pipeline, start, stop, and restart. Observability includes status, errors, late_events, metrics, lag, and trace; secret and custom-connector registry functions support connector configuration. The DSL covers table, CDC, Kafka, paginated HTTP, OpenDAL, custom inputs/outputs, and processors such as filter, mapping, aggregate, window, join, dedupe, and CEP.

Operational Notes

The fixed pgstreams schema and background-worker registration require superuser installation and server planning. Adding the library or changing worker count requires a restart; reserve enough max_worker_processes capacity for one coordinator, the configured executors, and the timer worker. Pipeline expressions and connector definitions execute inside a privileged database service, so restrict pipeline and secret management. Test delivery guarantees, checkpoints, retries, late data, schema evolution, and failure recovery for each connector before production use.

Version 0.3.0 Boundary

This is an unsupported proof of concept under Matroid Source Available License 1.0. APIs may change. Version 0.3.0 is the new upgrade baseline: earlier 0.2.0 installations require a rehearsed data migration/recreation, not ordinary ALTER EXTENSION UPDATE. Back up data and dependencies before following that destructive upstream path.

The new call sink can assume a configured set_role for guarded execution. Modbus TCP and Siemens S7 inputs and write sinks can interact with external devices; restrict connector configuration and verify operational authorization before enabling them.

Current Release and Upgrade

Extension version 0.3.2 uses pg_streaming.database for background workers. Create the extension in that database; a worker now waits instead of repeatedly exiting when it is absent. Changing restart-sensitive worker configuration requires a restart. From extension 0.3.0 onward, install matching files and use ALTER EXTENSION UPDATE. Earlier versions still require the migration described above. Withdrawn repository 0.4.0 bottles must be replaced by 0.5.0; upstream bottles do not imply Pigsty package availability.

Worker Supervision

Version 0.3.2 adds pgstreams.worker_status() and the superuser-only pgstreams.reset_workers(). Status reports worker name, state, failures, restarts, PID, time of entry into the current state and last failure. pg_streaming.max_worker_failures defaults to 10 consecutive failures; 0 retries indefinitely. Restart delays back off from 5 to 60 seconds, and reaching the limit leaves a failed worker idle until reset.

Install matching libraries, restart PostgreSQL to initialize the new shared memory, and update the extension SQL in the configured worker database. Inspect the failure before resetting; a reset does not repair its cause.

ALTER EXTENSION pg_streaming UPDATE;
SELECT * FROM pgstreams.worker_status();

Raw-Zone Ingestion in 0.3.3

Repository release 0.6.0 contains extension 0.3.3. OpenDAL gains parse_as: parquet and parse_as: listing, with order: lexicographic resuming in the middle of a file. Unreadable files stop progress so later files cannot overtake them. Records include source_file and source_row for replay deduplication; pgstreams.replay(name, after) rewinds a stopped pipeline. Private S3 access for the arrays lane remains unsupported.

Idle Workers in 0.3.4

Repository release 0.7.2 contains extension 0.3.4. Read-only or empty-claim polls no longer allocate a transaction ID merely because they use the SPI bridge; an actual row write still does. This removes empty commit WAL from idle polling. Idle executor polls back off from pg_streaming.poll_interval_ms (default 10 ms) to pg_streaming.idle_poll_interval_ms (default 250 ms). Install matching libraries, restart the preloaded workers, and update the SQL extension. The existing privilege, external-service and pre-0.3.0 migration boundaries remain.

Table reader