Skip to content

Conversation

@dwillitzer
Copy link

Summary

  • Upgrade pgrx from 0.12 to 0.16 for pg17/pg18 support
  • Convert 43 extern "C" to extern "C-unwind" for pg_guard functions
  • Add pg18 feature flag with proper IndexAmRoutine fields and cfg guards

Problem

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:

  1. ABI changes: All #[pg_guard] functions must use extern "C-unwind" instead of extern "C"
  2. GUC registration: String literals changed to C string literals (c"...")
  3. SPI API: select() params changed from None to &[]
  4. IndexAmRoutine: pg17/pg18 add new fields that need proper cfg guards:
    • pg17: amcanbuildparallel, aminsertcleanup
    • pg18: amcanhash, amconsistentequality, amconsistentordering, amgettreeheight, amtranslatestrategy, amtranslatecmptype
  5. amestimateparallelscan: Function signature varies by PG version:
    • pg14-16: no params
    • pg17: 2 params (nkeys, norderbys)
    • pg18: 3 params (Relation, nkeys, norderbys)

Files Changed

File Changes
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

Test Plan

  • cargo check --features pg17 passes
  • cargo build --lib --features pg17 --release produces libruvector_postgres.dylib (3.3MB)
  • Integration test with actual PostgreSQL 17 (recommended for reviewer)

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

dwillitzer and others added 5 commits January 14, 2026 10:48
## 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant