pgpi
pg_plan_inspector · Record query plans and test external cardinality estimates
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102447 | pgpi | pg_plan_inspector | 0.4 | STAT | C |
PostgreSQL · 19
Usage
Sources:
pgpi is the PostgreSQL extension in the pg_plan_inspector research framework. Its control file and installation SQL use version 0.4; the framework calls this line 2.0. It records execution telemetry and can replace planner cardinality estimates with directives or answers from an external estimator.
Enable and Inspect
The current source requires PostgreSQL 19. It supports Linux and macOS on x86_64/ARM64; runtime function detours are available only on Linux. On macOS the official hook route remains available. Enable preload and select the database that stores logs, then restart PostgreSQL:
Append to any existing preload list. Install the extension as a superuser in each database where it is needed:
The worker creates pgpi.plans and pgpi.stats in the logging database. SQL functions are relocatable, while these log tables remain in their own schema.
Capture and Test Estimates
Intervention defaults to off and plan capture is separate. A privileged test session can capture a workload and flush the buffer before collecting it:
pgpi.log_plans requires superuser permission or an explicit parameter grant. The Python client needs Python 3.10+ and dependencies for the selected estimator. It collects logs into a Parquet dataset, then serves estimates over a UNIX socket. Point pgpi.callback at that socket and use pgpi.mode = 'shadow' to record answers without applying them; enforce applies them. Static answers can instead be supplied through pgpi.directives.
Objects and Boundaries
pgpi_requestsandpgpi_clearinspect or clear the current backend’s request log.pgpi_statusreports installed detours;pgpi_log_statusexposes shared-buffer and worker statistics.pgpi_log_flushreturns false on timeout or when not preloaded.pgpi_stats_reset_seenresets remembered statistics versions and is not executable byPUBLICby default.- The callback timeout defaults to 2000 ms. On failure, requests are suspended for five seconds and PostgreSQL estimates are used. An estimator can also abstain.
- The default retention is unlimited: configure
pgpi.log_retentionorpgpi.log_max_rowsfor bounded plan storage.pgpi.log_database,pgpi.log_buffer_size, andpgpi.stats_maxrequire restart when changed. - Logs can include SQL, bind parameters, and statistics. Restrict access accordingly. Capture adds execution instrumentation; estimates and detours are experimental and can change plans or performance. The project does not claim that better cardinality accuracy always makes queries faster.