Planet PostgreSQL·· 10d agoFeatured
PostgreSQL 19 Plan Advice Tools for Transactional Outbox Workloads
Mayur B.: PostgreSQL 19: When the Planner Needs Adult Supervision
Brief · Based on the source excerpt
A lab using the transactional outbox pattern shows how changed data and stale statistics can lead PostgreSQL to choose an execution plan based on outdated information. It introduces PostgreSQL 19’s pg_plan_advice and pg_stash_advice, including generated advice for reproducing an index scan plan.
Why It Matters
The lab shows how stale statistics can mislead PostgreSQL’s planner on transactional outbox workloads and introduces PostgreSQL 19 tools for reproducing and stashing plan advice.
Technical Breakdown · Distilled from the original source
Outbox writes and polling
- The lab commits an order and its corresponding
OrderPlacedevent in the same transaction. The event is inserted intodemo_outboxwith statusREADY, so recording it for delivery does not depend on a separate publish succeeding after the order commits. - The author generates representative data and inspects the polling query plan while statistics are accurate, establishing a baseline. The production scenario motivating the experiment is a database with several outbox tables and a limited number of autovacuum workers.
Plan advice and the statistics test
- The lab preloads
pg_plan_adviceandpg_stash_adviceviashared_preload_libraries, setscompute_query_id = on, and restarts PostgreSQL after applying the settings. Parallel query is disabled to make the plans easier to read; the article notes that JIT is off by default in PostgreSQL 19. - The baseline run emits
INDEX_SCAN(e public.demo_outbox_poll_idx)as generated plan advice. That string can be copied into a stash to reproduce the index scan plan. - Autovacuum is disabled only for the lab so statistics do not refresh between steps. The author performs retention cleanup, runs
ANALYZE, then simulates a traffic burst without analyzing again. The planner is left with statistics from before the burst.
Source: Planet PostgreSQL· postgr.es
PG Radar summarizes verified changes and impact. Read the original post for full technical details and code samples.