pg_plan_feedback
pg_plan_feedback · Learn per-query row-count corrections from execution feedback
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102261 | pg_plan_feedback | pg_plan_feedback | 1.0 | FEAT | PostgreSQL | C |
Usage
Sources:
pg_plan_feedback learns per-query, per-relation row-count corrections from execution and can feed them into later planning. It requires an upstream PostgreSQL core patch; stock PostgreSQL compatibility is not established. Upstream marks this experimental and unsuitable for production.
Observe Before Applying
On a server with the required core hooks and installed library:
The viewing role must have pg_read_all_stats or equivalent explicitly granted privileges. observe records feedback without changing estimates; apply uses learned corrections; off disables the feature. Exercise representative queries and inspect feedback before switching modes.
Objects and Limits
pg_plan_feedback_reset(queryid) clears corrections; omitting its argument resets all. pg_plan_feedback_set(queryid, relation, correction) installs a manual factor. Both are restricted by default because they affect planning for other users. pg_plan_feedback_stats() reports counts, and the view exposes estimates, observed rows and correction factors across databases.
The library may be loaded through shared or session preload, or explicit LOAD; shared preload is not mandatory for its dynamic shared memory. The SQL extension is relocatable and requires a superuser to install. It learns base-relation row counts, not a forced join order or full plan. Incomplete scans do not supply reliable feedback; cached plans require replanning before estimates change. Do not assume stable storage or interfaces across experimental revisions.