PostgreSQL plan advice

PostgreSQL 실행 계획 조언

The PostgreSQL 19 beta pg_plan_advice extension can stabilize or influence planner choices.

···
html
<div class="demo"><div class="head"><b>PLAN ADVICE</b><span>same query</span></div><div class="stage advice"><div class="plan"><strong>planner</strong><div class="cell" id="plain">Seq Scan</div><small>orders</small></div><div class="switch">→</div><div class="plan"><strong>with advice</strong><div class="cell on" id="advised">Index Scan</div><small>orders_idx</small></div></div><div class="foot"><span id="advstatus">compare candidate plans</span><span>PG 19 beta</span></div></div>
css
*{box-sizing:border-box}.demo{width:min(96vw,820px);height:min(94vh,350px);padding:clamp(8px,2vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);display:flex;flex-direction:column;gap:clamp(5px,1.5vmin,12px);font:600 clamp(12px,3.5vmin,15px)/1.25 var(--font-sans),sans-serif;overflow:hidden}.head,.foot,.row{display:flex;justify-content:space-between;align-items:center;gap:8px}.head b{color:var(--accent)}.head span,.foot,.muted{color:var(--muted)}.stage{flex:1;min-height:0;display:flex;align-items:center;justify-content:center;gap:8px}.cell,.pill{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(4px,1.2vmin,9px);text-align:center}.pill{border-radius:999px}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 17%,var(--surface))!important;color:var(--fg)!important}.bad{border-color:#e16a5d!important;background:color-mix(in srgb,#e16a5d 18%,var(--surface))!important}.foot{font-size:clamp(12px,3vmin,14px)}.advice{justify-content:space-around}.plan{min-width:37%;display:grid;gap:4px;text-align:center}.plan strong{color:var(--muted)}.plan small{font:600 clamp(11px,2.8vmin,13px) ui-monospace,monospace;color:var(--muted)}.switch{font-size:clamp(19px,5vmin,28px);color:var(--accent)}.plan .cell{transition:.3s}
js
let n=0;function tick(){document.getElementById('plain').classList.toggle('on',!n);document.getElementById('advised').classList.toggle('on',!!n);document.getElementById('advstatus').textContent=n?'advice selects Index Scan':'planner selects Seq Scan';n=1-n}tick();const t=setInterval(tick,1100);document.querySelector('.demo').onclick=()=>{clearInterval(t);tick()}

PostgreSQL 19 beta adds pg_plan_advice to influence planner decisions. A companion extension, pg_stash_advice, can apply advice by query identifier.

The demo compares a candidate plan with the plan chosen under advice. Advice can become stale when data distribution changes, so remeasure actual execution time and plans. Both extensions are beta features.

When to use

Evaluate it narrowly when measured plan changes cause a real bottleneck.

Open as page ↗