PostgreSQL 19 introduces the pg_plan_advice contrib module, which allows users to stabilize or override query planner decisions. By analyzing a finished query plan, it generates textual 'plan advice' (e.g., JOIN_ORDER, MERGE_JOIN, SEQ_SCAN directives) that can be fed back to force the planner to reproduce or alter those decisions in future executions. The post walks through loading the extension, generating advice from EXPLAIN output, and progressively overriding join order, join type, and scan method. While powerful for cases where statistics mislead the planner, the author warns it's a 'foot-gun' — advice set once tends to be forgotten, and bad advice in production can cause serious performance regressions.
Sort: