Skip to content

pg_orca

ORCA query optimizer as a PostgreSQL extension

pg_orca · ORCA query optimizer as a PostgreSQL extension

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
2540pg_orcapg_orca1.1.0OLAPApache-2.0C++
AttributeHas BinaryHas LibraryNeed LoadHas DDLRelocatableTrusted
--sLd--NoYesYesYesnono
Set session_preload_libraries=pg_orca for automatic planner hooks.

Packages

TypeRepoVersionPG Major CompatibilityPackage PatternDependencies
EXTPIGSTY1.1.019 18 17 16 15pg_orca-
RPMPIGSTY1.1.019 18 17 16 15pg_orca_$v-
DEBPIGSTY1.1.019 18 17 16 15postgresql-$v-pg-orca-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.1.0N/AN/AN/A
el8.aarch64N/APIGSTY 1.1.0N/AN/AN/A
el9.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
el9.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
el10.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
el10.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
d12.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
d12.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
d13.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
d13.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
u22.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
u22.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
u24.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
u24.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
u26.x86_64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
u26.aarch64PIGSTY 1.1.0PIGSTY 1.1.0N/AN/AN/A
PackageVersionOSORGSIZEFile URL
pg_orca_181.1.0el8.x86_64pigsty1.9 MiBpg_orca_18-1.1.0-1PGSTY.el8.x86_64.rpm
pg_orca_181.1.0el8.aarch64pigsty1.7 MiBpg_orca_18-1.1.0-1PGSTY.el8.aarch64.rpm
pg_orca_181.1.0el9.x86_64pigsty1.9 MiBpg_orca_18-1.1.0-1PGSTY.el9.x86_64.rpm
pg_orca_181.1.0el9.aarch64pigsty1.7 MiBpg_orca_18-1.1.0-1PGSTY.el9.aarch64.rpm
pg_orca_181.1.0el10.x86_64pigsty1.8 MiBpg_orca_18-1.1.0-1PGSTY.el10.x86_64.rpm
pg_orca_181.1.0el10.aarch64pigsty1.6 MiBpg_orca_18-1.1.0-1PGSTY.el10.aarch64.rpm
postgresql-18-pg-orca1.1.0d12.x86_64pigsty1.7 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~bookworm_amd64.deb
postgresql-18-pg-orca1.1.0d12.aarch64pigsty1.5 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~bookworm_arm64.deb
postgresql-18-pg-orca1.1.0d13.x86_64pigsty1.7 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~trixie_amd64.deb
postgresql-18-pg-orca1.1.0d13.aarch64pigsty1.5 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~trixie_arm64.deb
postgresql-18-pg-orca1.1.0u22.x86_64pigsty1.7 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~jammy_amd64.deb
postgresql-18-pg-orca1.1.0u22.aarch64pigsty1.6 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~jammy_arm64.deb
postgresql-18-pg-orca1.1.0u24.x86_64pigsty1.7 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~noble_amd64.deb
postgresql-18-pg-orca1.1.0u24.aarch64pigsty1.6 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~noble_arm64.deb
postgresql-18-pg-orca1.1.0u26.x86_64pigsty1.7 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~resolute_amd64.deb
postgresql-18-pg-orca1.1.0u26.aarch64pigsty1.6 MiBpostgresql-18-pg-orca_1.1.0-1PGSTY~resolute_arm64.deb

Source

pig build pkg pg_orca;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

pig repo add pgsql -u   # add both repo and update cache

Install this extension with pig:

pig install pg_orca;		# install by package name

pig install pg_orca -v 19;   # install for PG 19
pig install pg_orca -v 18;   # install for PG 18

Config this extension to shared_preload_libraries:

shared_preload_libraries = 'pg_orca';

Create this extension with:

CREATE EXTENSION pg_orca;

Usage

Sources:

pg_orca plugs the ORCA cost-based optimizer from the Greenplum/Apache Cloudberry lineage into a standard PostgreSQL 18/19 server. The upstream README describes this project as PostgreSQL 18 primary target with PostgreSQL 19 preview support.

Enable ORCA For A Session

CREATE EXTENSION loads the library in the current session, so the pg_orca.* GUCs and planner hook are available immediately:

CREATE EXTENSION pg_orca;

SET pg_orca.enable_orca = on;

EXPLAIN
SELECT *
FROM orders
WHERE customer_id = 42
  AND created_at >= now() - interval '30 days';

If ORCA cannot handle a query, the README says it falls back to the standard PostgreSQL planner automatically. Turn on fallback logging while validating a workload:

SET pg_orca.trace_fallback = on;

Preload For New Connections

For automatic planner-hook loading in later sessions, upstream recommends session_preload_libraries, not shared_preload_libraries:

ALTER DATABASE mydb SET session_preload_libraries = 'pg_orca';
ALTER DATABASE mydb SET pg_orca.enable_orca = on;

Existing sessions are unaffected until they reconnect. If another session preload library is already configured, include both values explicitly:

ALTER DATABASE mydb
SET session_preload_libraries = 'pg_orca,pg_stat_statements';

Role-local and cluster-wide scopes are also valid:

ALTER ROLE bench SET session_preload_libraries = 'pg_orca';

ALTER SYSTEM SET session_preload_libraries = 'pg_orca';
SELECT pg_reload_conf();

Tuning And Diagnostics

The README documents these main GUCs:

  • pg_orca.enable_orca: enable ORCA; default off.
  • pg_orca.trace_fallback: log fallback to the standard planner; default off.
  • optimizer_segments: segment count for costing; default 1.
  • optimizer_sort_factor: sort cost scaling; default 1.0.
  • optimizer_metadata_caching: cache relation metadata; default on.
  • optimizer_mdcache_size: metadata cache size in KB; default 16384.
  • optimizer_search_strategy_path: optional custom search strategy XML path.

The entrypoint source also defines additional ORCA tuning and debug GUCs such as optimizer_join_order, pg_orca.join_order_dynamic_threshold, pg_orca.cost_model, and optimizer_print_*. Treat those as workload/debug knobs and validate plans before keeping them in a persistent database setting.

Caveats

  • PostgreSQL 18 is the primary target; PostgreSQL 19 is preview support.
  • Use session_preload_libraries = 'pg_orca' for automatic loading in new sessions.
  • ORCA is disabled by default after loading; set pg_orca.enable_orca = on.
  • Fallback to the PostgreSQL planner is expected for unsupported queries; enable pg_orca.trace_fallback when checking coverage.

PostgreSQL 19 Preview

Release 1.1.0 builds against PostgreSQL 19 beta/RC with version guards and adds coverage for the new window-function syntax. Treat PostgreSQL 19 as preview until the server release is final, and validate plan changes before enabling ORCA broadly.

Table reader