← Browse the extensions catalog

pg-hint-plan

Source README ↗

pg-hint-plan

pg_hint_plan adds optimizer hints to PostgreSQL. Hints are written in SQL comments and can choose scan methods, join methods, and other planner behavior for individual queries.

Follow the quick start to set up extension-update email alerts first, then use the CronJob to install and refresh the catalog. These examples inherit image references and runtime settings from the catalog. The Cluster YAML is an excerpt: replace imageCatalogRef: ... with your catalog reference and keep your existing instance and storage settings.

Usage

1. Add the pg-hint-plan extension image to your Cluster

Add the image to a Cluster and preload pg_hint_plan:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-pg-hint-plan
spec:
  imageCatalogRef: ...
  postgresql:
    shared_preload_libraries:
    - pg_hint_plan
    extensions:
    - name: pg-hint-plan

2. Enable the extension in a database

Once the extension's files are available in the cluster, you can install it in a database in either of two ways:

Platform teams may make extension containers available across their clusters without installing every extension in every database. Install only the extensions a database uses; letting users enable them through SQL alongside the rest of their DDL schema management code can be a convenient approach.

For extensions that normally require superuser privileges, platform teams can use pgextwlist to allow non-superusers to install an administrator-approved selection of extensions.

3. Verify installation

Connect to the database with psql and run \dx to check the installed extensions.

The extension creates its objects in the hint_plan schema. For example:

CREATE TABLE hint_example (id integer PRIMARY KEY);
INSERT INTO hint_example SELECT generate_series(1, 1000);
ANALYZE hint_example;
/*+ SeqScan(t) */ EXPLAIN SELECT * FROM hint_example AS t WHERE id = 1;

The package copyright and license notice are included in the image under /licenses/postgresql-18-pg-hint-plan/.