PostgreSQL 19: pg_plan_advice and pg_stash_advice
In my previous article, PostgreSQL vs Oracle: When Higher Cost Means Better Performance , I showed that a plan with a higher estimated cost can run almost twice as fast as the plan the optimizer prefers. To demonstrate this, we had to use SET enable_seqscan = off , which disables sequential scans for all tables in the session. PostgreSQL 19 adds two contrib modules that remove that limitation: pg_plan_advice allows us to guide PostgreSQL toward a particular execution plan without changing the original SQL statement. For example, we can ask the planner to use an index scan instead of a sequential scan. pg_stash_advice takes this a step further by allowing us to save plan advice for a specific query. PostgreSQL can then automatically apply that advice whenever the query is executed. In simple terms, pg_plan_advice guides PostgreSQL toward a specific execution plan, while pg_stash_advice allows you to save and automatically reuse that advice. In this article, we will demonstrate both m...