vihash
pgvihash · version-independent hash functions
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100650 | vihash | pgvihash | 1 | FUNC | PostgreSQL | C |
Usage
Sources:
vihash provides one stable 32-bit text hash, vihashtext(text), copied from PostgreSQL 8.3’s hashtext implementation. Its purpose is preserving sharding/partition-routing decisions while different PostgreSQL major versions coexist during a migration.
Core Workflow
Install the extension on every participating database and verify identical results before changing routing code:
In PL/Proxy-era code, replace RUN ON hashtext(arg) with RUN ON vihashtext(arg) only as part of a planned redistribution/compatibility migration.
Compatibility Contract
vihashtext(text) RETURNS integer hashes the raw database-encoding bytes and is intended to remain version-independent. Its output matches built-in hashtext from PostgreSQL 8.0–8.3. It does not match the changed built-in implementation introduced in PostgreSQL 8.4.
Caveats
If data is already distributed with PostgreSQL 8.4-or-later hashtext, switching to vihashtext changes routes and requires redistribution. Test a fixed corpus on old and new nodes before cutover, keep database encoding identical, and handle the signed 32-bit result consistently when mapping it to shard numbers.
This is a migration aid, not a cryptographic or collision-resistant hash. Upstream recommends broader stable-hash libraries for new designs, and the repository is archived. Never use the result for authentication, integrity, uniqueness, or adversarial partition keys without collision handling.