pg_sorted_heap
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_sorted_heap | 0.14.0 | OLAP | PostgreSQL | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2550 | pg_sorted_heap | No | Yes | Yes | Yes | No | No | - |
sorted_hnsw.shared_cache requires shared_preload_libraries=pg_sorted_heap.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.14.0 | 1817161514 | pg_sorted_heap | - |
| RPM | PIGSTY | 0.14.0 | 1817161514 | pg_sorted_heap_$v | - |
| DEB | PIGSTY | 0.14.0 | 1817161514 | postgresql-$v-pg-sorted-heap | - |
Build
You can build the RPM / DEB packages for pg_sorted_heap using pig build:
Install
You can install pg_sorted_heap directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Preload:
Create Extension:
Usage
Sources: pg_sorted_heap README, stable API, SQL API, control file.
pg_sorted_heap adds the sorted_heap table access method, per-page zone-map pruning, maintenance helpers, built-in svec/hsvec vector types, a planner-integrated sorted_hnsw index AM, and stable GraphRAG wrappers. Upstream documents PostgreSQL 16, 17, and 18 support for the current release surface.
Sorted Heap Tables
Use USING sorted_heap on tables with a primary key. Bulk loads are sorted by primary key on the COPY path, and compaction globally sorts existing rows while rebuilding the zone map:
The README describes planner-injected SortedHeapScan paths for primary-key predicates and zone-map pruning at the heap-block level.
Maintenance And Observability
Stable maintenance functions include:
Partition helpers operate on concrete sorted-heap leaves under a parent:
Vector Search
The stable vector API includes svec(dim) for float32 vectors, hsvec(dim) for float16 vectors, and the sorted_hnsw index AM:
For compact base-table storage, use hsvec and the matching operator class:
The shared decoded graph cache is controlled by sorted_hnsw.shared_cache. Upstream examples note that using it requires preloading the extension:
GraphRAG
The stable fact-shaped GraphRAG entry point expects facts clustered by (entity_id, relation_id, target_id) or a registered alias mapping:
Register alternate fact column names once:
For routed or tenant-sharded fact tables, use sorted_heap_graph_route(...) and inspect routing with sorted_heap_graph_route_plan(...).
Stable GUCs
sorted_heap.enable_scan_pruning: enable sorted-heap custom scan pruning; defaulton.sorted_heap.vacuum_rebuild_zonemap: rebuild zone maps duringVACUUM; defaultoff.sorted_heap.lazy_update: defer eager zone-map update maintenance; defaultoff.sorted_hnsw.ef_search: runtime HNSW search breadth; default64.sorted_hnsw.shared_cache: shared decoded graph cache when preloaded; defaulton.sorted_hnsw.sq8: SQ8 decoded cache representation; defaulton.sorted_hnsw.build_sq8: low-memory index build mode; defaultoff.
Caveats
sorted_heap.lazy_update = ontrades scan pruning for faster update-heavy workloads until compaction or merge restores pruning.sorted_hnsw.shared_cacheshould be used withshared_preload_libraries = 'pg_sorted_heap'.- Planner-integrated
sorted_hnswordered scans requireLIMIT; the SQL API says they are not chosen when there is no limit or whenLIMIT > sorted_hnsw.ef_search. - The lower-level GraphRAG and legacy/manual ANN helpers remain documented, but the stable application-facing API is the compact surface in
docs/api-stable.md.
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)