feat(postgres): Upgrade pgrx to 0.16 with pg17/pg18 support#112
Open
dwillitzer wants to merge 5 commits intoruvnet:mainfrom
Open
feat(postgres): Upgrade pgrx to 0.16 with pg17/pg18 support#112dwillitzer wants to merge 5 commits intoruvnet:mainfrom
dwillitzer wants to merge 5 commits intoruvnet:mainfrom
Conversation
## Changes ### pgrx 0.16 Migration - Upgrade pgrx from 0.12 to 0.16 for pg17/pg18 support - Convert all `extern "C"` to `extern "C-unwind"` for pg_guard functions (43 functions across 9 files) - Update GUC registration to use C string literals (`c"..."`) - Update SPI select params from `None` to `&[]` ### pg18 Support - Add pg18 feature flag to Cargo.toml - Add pg18 IndexAmRoutine fields with cfg guards: - amcanhash, amconsistentequality, amconsistentordering - amgettreeheight, amtranslatestrategy, amtranslatecmptype - Add pg18 amestimateparallelscan variant (3 params: Relation, nkeys, norderbys) ### Files Modified - Cargo.toml: pgrx 0.12 → 0.16, add pg18 feature - src/lib.rs: extern C-unwind, GUC c"..." strings - src/index/hnsw_am.rs: extern C-unwind, pg18 IndexAmRoutine fields - src/index/ivfflat_am.rs: extern C-unwind, pg18 fields, amestimateparallelscan cfg guards - src/dag/functions/analysis.rs: SPI params - src/healing/worker.rs: extern C-unwind - src/index/bgworker.rs: extern C-unwind - src/types/vector.rs: extern C-unwind - src/workers/engine.rs: extern C-unwind - src/workers/maintenance.rs: extern C-unwind ### Build Tested - `cargo check --features pg17` passes - `cargo build --lib --features pg17 --release` produces libruvector_postgres.dylib Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
CRITICAL FIX: PostgreSQL 18 added amgettreeheight callback BETWEEN amcostestimate and amoptions, not at the end. This caused all subsequent callbacks to be misaligned by one slot, resulting in segfaults during ORDER BY index scans. Changes: - Move amgettreeheight from end of struct to correct position - Add PG18-specific ORDER BY extraction from scan->orderByData - Clarify comments about PG18 boolean flags vs callbacks Fixes #TBD - HNSW index scan crash on PostgreSQL 18 Tested: ORDER BY embedding <-> '...'::ruvector now works correctly Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- HNSW_PG18_CRASH_RCA.md: Full root cause analysis, resolution, validation - hnsw-debug-task.json: Original task definition for audit trail Resolves issue where ORDER BY embedding <-> '...' crashed on pg18 Root cause: amgettreeheight callback position misalignment in IndexAmRoutine
- Integration with existing Tailscale ACL tags - Defense in depth security model - PgBouncer configuration for connection pooling - WAL archiving for PITR backup - Health checks and monitoring setup - 90-minute rollout checklist Coordination hub role: metadata, queue state, agent coordination (not primary data store - heavy processing on gmktec-k9)
New files: - crates/ruvector-postgres/tests/pg18_routing_integration.sql - crates/ruvector-postgres/src/routing/tests.rs - crates/ruvector-postgres/src/routing/test_utils.rs - crates/ruvector-postgres/RUST_TEST_SUMMARY.md Modified: - crates/ruvector-postgres/sql/ruvector--2.0.0.sql - crates/ruvector-postgres/src/index/hnsw_am.rs - crates/ruvector-postgres/src/routing/operators.rs - crates/ruvector-postgres/tests/README.md Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extern "C"toextern "C-unwind"for pg_guard functionsProblem
The previous pgrx 0.12 configuration declared pg17 support, but pgrx 0.12 only supports pg14-16. This caused build failures when attempting to build with pg17.
Solution
Upgraded to pgrx 0.16 which properly supports pg17 and pg18. This required:
#[pg_guard]functions must useextern "C-unwind"instead ofextern "C"c"...")select()params changed fromNoneto&[]amcanbuildparallel,aminsertcleanupamcanhash,amconsistentequality,amconsistentordering,amgettreeheight,amtranslatestrategy,amtranslatecmptypeFiles Changed
Test Plan
cargo check --features pg17passescargo build --lib --features pg17 --releaseproduces libruvector_postgres.dylib (3.3MB)macOS Build Note
On macOS, building requires linker flags for PostgreSQL symbol resolution:
RUSTFLAGS="-C link-arg=-undefined -C link-arg=dynamic_lookup" \ cargo build --lib --no-default-features --features pg17 --release🤖 Generated with Claude Code