Skip to content

pg_qi

Experimental evidence-qualified query routing to pg_duckdb

pg_qi · Experimental evidence-qualified query routing to pg_duckdb

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102365pg_qipg_qi0.0.1OLAPApache-2.0C

PostgreSQL · 16, 17, 18, 19

Relationships
Requirespg_duckdb

Usage

Sources:

pg_qi is an experimental policy layer for query execution through pg_duckdb. The public 0.1.0-beta.1 release retains SQL version0.0.1. It adds qualified routing, disabled by default; the beta evaluation target is Linux x86_64, PostgreSQL18.7 and a pinned patched provider.

Install and Observe

Append pg_duckdb before pg_qi in the preload list and restart. Install both extensions as an administrator:

shared_preload_libraries = 'pg_duckdb,pg_qi'
CREATE EXTENSION pg_duckdb;
CREATE EXTENSION pg_qi;
SELECT qi.version(), qi.is_preloaded();
SHOW pg_qi.routing_mode;
SET pg_qi.routing_mode = 'shadow';
SELECT count(*) FROM pg_catalog.pg_class;
SHOW pg_qi.decision_snapshot;
SHOW pg_qi.select_evidence;

pg_qi.routing_mode supports off, shadow and qualified. Shadow observes the retained downstream plan without delegating it. Read both snapshots on the same connection and match backend incarnation, generation and event sequence; a record from another statement does not prove this execution’s behavior.

Qualified Execution

Stock pg_duckdb1.2.2 lacks the provider interface. Delegation needs the upstream patched pg_duckdb1.2.2/DuckDB2.0.1 stack plus a site module calibrated for the exact binaries. All eligibility, correctness and measured-benefit gates must pass for each execution; missing provider, calibration or capacity keeps the PostgreSQL plan.

The documented configuration uses duckdb.threads = 1, duckdb.async_threads = 0, a finite process address-space limit, a DuckDB memory limit and a site capacity lease. pg_qi must be last among preloaded libraries; competing planner/path hooks prevent delegation. Queries require the privileges of duckdb.postgres_role, and cursors must be NO SCROLL.

pg_qi.qualified_evidence exposes the latest decision to a superuser session. General hook/CI compatibility covers PostgreSQL16–19, with19 pinned to the final release, but that is broader than the beta’s qualified execution target. The test-only pg_qi_spike_test companion is excluded from production installation.

Failure and Upgrade Boundaries

Disable routing before replacing any component, then repeat the exact-build qualification. A delegated query can fail while spilling to disk; granting server-file roles changes the security boundary and is not a routine workaround. Inspect the reported error and roll back before retrying. Retaining a native plan for admission fallback does not authorize replaying arbitrary partially executed statements.

Table reader