pg_plansight
pg-plansight · Capture and analyze cumulative query plans and execution statistics
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102483 | pg_plansight | pg-plansight | 0.2.0 | STAT | MIT | Rust |
PostgreSQL · 12, 13, 14, 15, 16, 17, 18
Usage
Sources:
- crates/pg_extension/README.md
- crates/pg_extension/pg_plansight.control
- crates/pg_extension/Cargo.toml
- crates/pg_extension/sql/schema.sql
- crates/pg_extension/sql/privileges.sql
- docs/CONFIGURATION.md
pg_plansight 0.2.0 captures query plans and cumulative execution statistics in PostgreSQL. The release documents PostgreSQL12–18 packages and end-to-end capture validation on16. Its Cargo manifest also has a PG19 feature; that alone does not qualify a PG19 release package.
Manual Analysis
A superuser installs the nonrelocatable extension. Manual ingestion and SQL helpers work without preload:
plansight_ingest(text) accepts auto_explain log text and returns the number of distinct query groups written. plansight.statements stores representative SQL, plans and JSON analysis; plansight.top_by_total_time ranks cumulative time and plansight.query_timeline exposes hourly aggregates.
Automatic Capture
Automatic capture requires preload, a background worker and restart. Install the SQL extension in the database selected by plansight.database:
plansight.capture_mode defaults to off. The hook mode captures directly through executor hooks; log mode tails an auto_explain log and additionally needs auto_explain configured for analyzed text plans. These modes are mutually exclusive. Changing the worker database requires a worker or server restart.
Limits and Access
plansight_capture_stats() reports ring backlog, captured/dropped records and the last drain. Rising dropped counts mean the bounded sampler is losing records. plansight.capture_plan and plansight.track_timing control plan and timing overhead; measure overhead for the chosen sampling rate. Monitoring privileges are granted to pg_read_all_stats, while mutation/reset functions are revoked from PUBLIC. SQL and plan text can contain sensitive values.
plansight_reset() clears stored statistics; plansight_reset_stats() clears the extension’s own counters. plansight_pgss_view() creates an optional pg_stat_statements join view and must be called again after dump/restore. Back up retained tables and review version-specific upgrade instructions before replacing libraries. Captured totals are sampled statistics, not an audit log.