Skip to content

pg_prism

Asynchronous DuckDB mirrors of PostgreSQL Heap tables for analytic queries

pg_prism · Asynchronous DuckDB mirrors of PostgreSQL Heap tables for analytic queries

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102454pg_prismpg_prism0.1.11OLAPPostgreSQLC

PostgreSQL · 18, 19

Relationships
Requirespg_duckdb

Usage

Sources:

pg_prism maintains asynchronous DuckDB mirrors of PostgreSQL Heap tables. Reports use the existing connection, names and SQL while writes remain in PostgreSQL. Release 0.1.11 intentionally contains extension SQL version 0.1.8. This initial release requires its patched pg_duckdb 1.2.2 Prism adapter, DuckDB 2.0.1 and signed Quack/httpfs components; an arbitrary stock adapter is not interchangeable.

Enable a Mirror

The reviewed builds cover PostgreSQL 18.7 and 19.0. Preserve existing preload entries and restart with both modules loaded. PostgreSQL 18 requires logical WAL; allocate one replication slot per activated database and worker capacity for each database plus the launcher.

shared_preload_libraries = 'pg_duckdb,pg_prism'
wal_level = logical

Connect as a superuser to a UTF-8 database:

CREATE EXTENSION pg_prism CASCADE;
CREATE TABLE public.orders (id bigint PRIMARY KEY, amount bigint NOT NULL);
INSERT INTO public.orders VALUES (1, 10), (2, 20);
SELECT prism.create_mirror('public.orders');
SELECT source, state, reason FROM prism.status;

Wait until the mirror reports ready, then use a separate autocommit reporting connection:

SET prism.enabled = on;
EXPLAIN SELECT sum(amount) FROM public.orders;
SELECT sum(amount) FROM public.orders;

A routed plan reports PrismMirrorScan. prism.enabled defaults off and permits PostgreSQL fallback. prism.require_mirror makes unsupported or unavailable mirror reads fail instead. Experimental prism.cost_based_routing is also off by default. Ordinary readers need source-table permissions and membership in the role selected by duckdb.postgres_role; grant the wait function separately when needed.

Consistency and Eligibility

Mirrors support permanent standalone Heap tables with supported types, a nondeferrable primary key and default replica identity. Business commits do not wait for mirror apply. Transaction-sensitive and row-security-sensitive reads stay on PostgreSQL; mirrors are not a substitute for the transaction’s snapshot.

For read-after-commit reporting, capture a WAL position after commit and use prism.wait_until_applied(pg_lsn, integer) on the reporting connection, with a timeout in milliseconds. Check its boolean result. Session settings, prepared plans and prism.min_lsn belong to the physical connection; reset request-specific state before returning it to a pool.

Monitoring and Recovery

prism.status reports per-table state; prism.node_status shows workers and retained WAL. The default slot limit is 10 GB: exceeding it pauses the worker and releases its slot, requiring the documented explicit resume or rebuild path. Changes to source definitions can also require rebuilding.

Mirror files default to a sibling directory outside PGDATA. The PostgreSQL OS user needs write access; these files are outside normal PostgreSQL base backups. Physical standbys can build independent local mirrors when logical decoding and feedback requirements are met. Treat mirrors as rebuildable analytical copies and verify readiness after restart, recovery or failover.

Release 0.1.10

Eligible reporting queries can aggregate a mirrored fact table in DuckDB before joining an unmirrored lookup table in PostgreSQL. The supported rewrite preserves aggregate filters, HAVING, exact averages and left-join NULL groups; it also extends selected percentile, calendar and case-insensitive reporting expressions. This does not make every join or expression eligible; inspect EXPLAIN and the routing reference.

To upgrade from 0.1.9, stop PostgreSQL, install the matching package that replaces both modules together, then restart and verify mirror readiness. The SQL extension version remains 0.1.8; a SQL-only update does not replace the native modules.

Release 0.1.11

CDC applies batches per source table with INSERT, DELETE or full-primary-key MERGE operations. For real and double precision columns, positive and negative zero compare equal, so an update changing only the sign of zero may retain the previous sign in the mirror. The SQL version remains 0.1.8 and the patched adapter remains 1.2.2. Upgrade by replacing the paired native modules during a server stop/restart, then verify mirror readiness and routing; a SQL-only update does not install these changes.

Table reader