pg_index_steward
pg_index_steward · Workload-based index advice with an external concurrent-DDL executor
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102451 | pg_index_steward | pg_index_steward | 4.9.0 | ADMIN | MIT | C |
PostgreSQL · 14, 15, 16, 17, 18, 19
| Relationships | |
|---|---|
| Requires | pg_stat_statements |
Usage
Sources:
- README.md
- CHANGELOG.md
- pg_index_steward.control
- LICENSE
- Makefile
- pg_index_steward–0.1.0.sql
- pg_index_steward–4.8.0–4.9.0.sql
- steward.c
- pg-index-steward
- install.sh
pg_index_steward 4.9.0 derives index advice from natural workload statistics and uses a separate Python 3/libpq executor for controlled DDL. The PGXS C extension supports PostgreSQL 14–19 and requires pg_stat_statements. It compiles bundled HypoPG 1.4.5 into its own library; a separate HypoPG extension is not required.
Observe Before Enabling Changes
Preserve existing preload entries, preload both libraries and restart. The following configuration deliberately disables automatic index changes:
Installation is superuser-only in the fixed index_steward schema. The installed pg-index-steward --observe-only --once executor records observations without executing changes. Use protected libpq connection settings; --libpq selects the local client library. SQL objects alone do not schedule work. The executor needs workload-reading and target-table DDL privileges; upstream’s initial setup uses an instance administrator. PUBLIC access is restricted, with explicit grants available for the read-only status function.
Code defaults differ from this example: pg_index_steward.auto_create and pg_index_steward.auto_drop_managed are on; pg_index_steward.auto_drop_existing is off. Settings are reloadable. The default window is 23:00–06:00 in the database session time zone, and polling is every 15 minutes.
Candidates, Queue and Evidence
The parser analyzes supported schema-qualified single-table SELECTs and UNION branches. Eligible ordinary tables default to 1 MiB–5 GiB in the default tablespace. Native single-level partitioned tables can be explicitly queued with index_steward.queue_partition_index; parent definitions, concurrent child indexes and attachments proceed in steps. Explicit TimescaleDB index jobs now support approved local hypertables, including qualified single-column BRIN candidates. policy.timescale_discovery defaults to advice; automatic execution requires an explicit execute policy. Chunk-by-chunk creation can block writes on the chunk being processed.
Each instance serializes maintenance and defaults to one DDL action per cycle; policy.ddl_per_cycle can be set from 1 to 10 within the same window and daily quotas. The persistent queue rechecks objects, overlap, free space, transactions, replication and remaining window time; blocked jobs retain retry times. index_steward.retry_job retries a reviewed failure. index_steward.policy controls pause, allowed schemas/tables, daily limits and timeouts.
Hypothetical plans use ordinary EXPLAIN in the executor’s connection and are cleaned up after evaluation. Register only trusted queries and bindings in index_steward.plan_samples. index_steward.index_portfolio, index_steward.relation_hotspots and index_steward.table_health expose candidate coverage, workload and table health. Verdicts compare natural traffic and do not prove causation. index_steward.approve_rollback queues a reviewed rollback; policy.auto_rollback defaults off. A completed rollback pauses the database’s automatic queue.
TimescaleDB and Hypercore Boundaries
The documented combinations are PG14 with TimescaleDB 2.8.0/2.19.3, PG15 with 2.19.3, and PG16–18 with 2.32.1. PG19 needs an experimental TimescaleDB build and policy.timescale_experimental. Use index_steward.timescale_pair_status() to inspect the pair and index_steward.queue_timescale_index to approve a candidate. Legacy mixed-compression handling requires its own explicit policy and review.
Hypercore changes on PG16–18 with TimescaleDB 2.32.1 require an allowlisted hypertable and policy.hypercore_changes. Sparse settings, metadata rebuilds and layout changes use separate queue operations. Optional staged validation waits for comparable natural traffic before continuing; insufficient samples keep the job waiting. index_steward.approve_hypercore_rollback requests a reviewed layout rollback, not an extension downgrade.
Timescale retirement has independent policy gates, resets observation when the chunk set changes, and can include only registered directly connected physical replicas with complete evidence. These paths still require maintenance-window, lock, disk, replication and workload checks.
Cluster Scheduling and Additional Policies
Version 4.0.0 supports one executor rotating across databases in the same instance. Cluster mode persists UTC daily quotas and rotation state in PGDATA and uses a local instance lock; it is not cross-instance failover fencing. Review its cluster configuration and retain the state files across executor restarts. Instance-wide data/WAL free-space and replication-slot thresholds still gate DDL.
Repeated periodic use can protect an index from retirement for up to 730 days. Optional covering-index proposals require a table allowlist, hypothetical generic/custom Index Only Scan evidence, at least 20% estimated cost improvement and a write-rate limit. Neither planner estimates nor recent silence prove a safe production benefit. Transiently blocked jobs continue retrying; retry_limit is an alert threshold rather than a permanent abandonment count.
Automatic/batch Hypercore validation and rollback are separate opt-in policies and default off. Existing explicit approval, workload comparison and rollback-pause safeguards still apply. The full sequential SQL chain ends with 4.8.0--4.9.0; do not invent a direct 3.28.0-to-4.9.0 script.
Retirement, Recovery and Upgrade
Deletion needs at least 60 days of uninterrupted idle observation. Gaps over 24 hours, increased scans, restarts, statistics resets or changed definitions restart the clock. Protection covers constraints, unique/primary indexes, foreign-key lookup paths, replica identity, expression/partial and non-B-tree indexes. If replication exists, directly connected read-serving physical replicas must all be observed through policy.replica_services; disable automatic deletion for topologies whose read traffic cannot be fully observed.
Keep recreation DDL from index_steward.jobs before deletion. index_steward.set_paused(true) pauses new database changes; stopping the executor stops new work, while in-flight DDL under application name pg-index-steward needs separate inspection. Failover still needs the application’s old-primary fencing; a new WAL timeline introduces a grace period and resets idle observations.
For an upgrade, stop the executor, back up, install matching files, restart PostgreSQL to load the new library, then update each target database:
The supplied sequential SQL chain starts at 0.1.0 and preserves existing policies and jobs. Confirm configuration and status before resuming the executor. Downgrading the whole extension requires the prior database backup and matching installation files.
Policies and Validation in 4.1–4.9
Later releases extend join, sort and covering-index advice and automatic creation paths, still requiring explicit execution policy, at least 20% estimated improvement and table-write budgets. A covering index does not automatically justify dropping an older index; old-index protection and the existing retirement observation period remain. Cluster scheduling persists fair rotation state, and time-series paths improve retry and budget handling.
Version 4.9.0 is the highest numeric release reviewed in this run. Upstream reports passing pre-tag CI, but the tag workflow failed twice on a PG14 x86_64 queue assertion with the cause unresolved; large-scale and 72-hour validation are also unfinished. Observe first and test explicitly enabled DDL; publication is not acceptance of every supported combination.