---
title: "Hints and hazards: pg_plan_advice in PG19"
description: "Postgres 19 adds two contrib modules for query hints: pg_plan_advice, which applies advice per session via SET, and pg_stash_advice, which attaches advice to specific query identifiers."
url: "https://swe.quest/articles/hints-and-hazards-pg-plan-advice-in-pg19-94b7939260d49157"
canonical: "https://clickhouse.com/blog/pg-plan-advice-postgresql-19"
source: "ClickHouse"
published: "2026-11-25"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 13
tags: ["postgres","query-engines","performance","sql"]
---

# Hints and hazards: pg\_plan\_advice in PG19

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-11-25, 13 min read, Deep dive. Original: [https://clickhouse.com/blog/pg-plan-advice-postgresql-19](https://clickhouse.com/blog/pg-plan-advice-postgresql-19)

## Summary

Postgres 19 adds two contrib modules for query hints: pg\_plan\_advice, which applies advice per session via SET, and pg\_stash\_advice, which attaches advice to specific query identifiers. Advice works by excluding plan options rather than forcing them, so unusable hints are ignored and harmful ones are accepted without checks. Benchmarks on artificial workloads show the effect: a BITMAP\_HEAP\_SCAN hint cut a clustered ORDER BY ... LIMIT query from 1.46s to under 10ms, and a JOIN\_ORDER hint fixed a correlated-filter misestimate for a roughly 200x speedup. In production, use SET LOCAL inside a transaction, and check the new EXPLAIN PLAN\_ADVICE output to confirm advice was matched.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Query engines](https://swe.quest/tags/query-engines.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [SQL](https://swe.quest/tags/sql.md) (Languages)

## Prerequisites

- Postgres EXPLAIN plans ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- query planner statistics ([easy posts on Query engines](https://swe.quest/tags/query-engines.md?difficulty=easy))
- index scan types
- join methods

## Keywords

PostgreSQL 19, pg\_plan\_advice, pg\_stash\_advice, pg\_hint\_plan, EXPLAIN PLAN\_ADVICE, ClickHouse Managed Postgres

## Related posts

- [Postgres week in the Netherlands: PGDay Lowlands & Percona Live 2026](https://swe.quest/articles/postgres-week-in-the-netherlands-pgday-lowlands-percona-live-2026-0eb593178690a919.md): ClickHouse · 2026-09-18 · Easy · 7 min read · PostgreSQL, Observability, Analytics & OLAP, Query engines
  Notes from PGDay Lowlands in Utrecht and Percona Live in Amsterdam, covering two ClickHouse-maintained Postgres extensions and several PostgreSQL 19 features. pg\_clickhouse is a foreign data wrapper that lets unmodified Postgres queries and ORMs run against ClickHouse via pushdown, with 15 of 22 TPC-H queries fully pushed down. pg\_stat\_ch streams per-query execution events through a shared-memory ring buffer to ClickHouse without back-pressure.
- [Easier Postgres fine-tuning with online\_advisor](https://swe.quest/articles/easier-postgres-fine-tuning-with-online-advisor-fe9a8f6b2841792d.md): Neon · 2025-09-16 · Medium · 4 min read · PostgreSQL, Performance engineering, Query engines
  online\_advisor is a Postgres extension that hooks into the executor (like auto\_explain) to watch the live workload and recommend indexes, extended statistics, or prepared statements without applying anything automatically.
- [PostgreSQL Stories: From slow query to fast—via stats](https://swe.quest/articles/postgresql-stories-from-slow-query-to-fast-via-stats-ac7001ab0fde8224.md): Render · 2024-05-14 · Medium · 13 min read · PostgreSQL, Query engines, Performance engineering, Debugging
  A simple LIMIT 1 join between a ~100k-row postgres\_dbs table and a ~90M-row events table ran for hours.
- [Postgres 19 is out: try it on Neon](https://swe.quest/articles/postgres-19-is-out-try-it-on-neon-e6c41c3a4f2e92c9.md): Neon · 2026-11-19 · Medium · 12 min read · PostgreSQL, Replication, Query engines, Databases
  Postgres 19 is an operations-focused release that adds REPACK (CONCURRENTLY) for online table rebuilding and clustering via logical decoding, pg\_plan\_advice/pg\_stash\_advice for stabilizing bad plans by query ID, parallel autovacuum with priority scoring, WAIT FOR LSN for read-your-writes on replicas, and logical replication sequence sync.
- [Introducing Postgres Query Insights in ClickHouse Cloud](https://swe.quest/articles/introducing-postgres-query-insights-in-clickhouse-cloud-a9697a827409b984.md): ClickHouse · 2026-05-07 · Medium · 7 min read · PostgreSQL, Observability, Performance engineering, Analytics & OLAP
  Postgres Query Insights, now in preview for ClickHouse Cloud Managed Postgres, ranks every normalized query pattern by impact and aggregates per-execution counters (CPU, cache vs disk reads, temp spills, unlaunched parallel workers, WAL) to explain why a pattern is slow.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
