# Merging four PostgreSQL forks into one kernel

> Why merging Percona pg_tde, OrioleDB, Babelfish and OpenHalo onto PostgreSQL 18.6 was easy to run, what broke at runtime, and why ABI compatibility forced a two-tier roadmap.

---

LLMS index: [llms.txt](/llms.txt)

---

Several PostgreSQL forks add major server capabilities: Percona Server for PostgreSQL adds storage hooks for `pg_tde` encryption, OrioleDB adds an index-organized storage engine with undo MVCC, Babelfish adds SQL Server wire and T-SQL support, OpenHalo 18 adds MySQL compatibility, and IvorySQL adds Oracle compatibility. Maintaining a separate kernel binary and extension matrix for each fork multiplies packaging and operational work.

On 2026-11-07, we tested a direct question on PostgreSQL 18.6 (`REL_18_6`, commit `724edf9b`, EL9 aarch64, `--enable-debug --enable-cassert`): can one PG 18.6 kernel carry all of these patches at once, behave like stock PostgreSQL when nothing is preloaded, and load any combination of extensions on demand?

The experiment gave a sharp answer: **getting four of the five forks to compile and run together in one instance was straightforward; keeping binary compatibility (ABI) with the PostgreSQL extension ecosystem was not.** That distinction between "it runs" and "it preserves the ABI" is why Mimus ships in two tiers ([Unified base research](/docs/kernel/unified-base/), [ABI compatibility](/docs/kernel/abi/)).

## Which forks fit into a shared kernel, and why IvorySQL does not {#five-forks}

We first profiled each fork's non-test `src/` diff against PG 18.6 (`REL_18_6`, 2026-08-11):

| Fork / patch set | Revision on PG 18.6 | Non-test `src/` diff | New hooks | Structs | Signatures¹ | Catalog / format | Gated² |
| --- | --- | --- | --- | --- | --- | --- | --- |
| Protocol hook | `c4b3cbe` | 12 files, `+357/−18` | 0 (registry) | 1 (`ClientSocket`) | 0 | None | 88% |
| Percona (`pg_tde` 2.2.1) | `release-18.6.1` (`19c3033d`) | 41 files, `+689/−268` | 0 (registries) | 1 (`SMgrRelationData`) | 2 (`mdcreate`, `heap_create`) | None (WAL encrypted when on) | 76% |
| OrioleDB (`1.10.2` / `b4f9683`) | `patches18` (`cc8c1483`) | 212 files, `+5,901/−1,504` | 31 | 23 | 25 | 24-byte `xl_running_xacts` tail; new TOAST `vartag` | 60% |
| Babelfish 6.2 | `BABEL_6_2_STABLE__PG_18_6` (`6ba0d062`) | 268 files, `+14,000/−721` | 143 | 31 | 10 | None (2 kernel GUCs) | 78% |
| IvorySQL 5.6 | `IvorySQL_5.6` (`74c405c9`) | 672 files, `+122,216/−3,438` | 11 | 49 + catalogs | 1+ | Alters `pg_attribute`, `pg_class`, `pg_proc`, `pg_control`; 3 tables; 22 GUCs | 38% |
{.wide}

¹ Parameter-count changes across headers and `.c` definitions. ² Upper-bound share of added hunks guarded by a hook pointer or dialect switch.

The first four forks keep their bulk in loadable extensions (`orioledb` ~139k lines, `babelfish_extensions` ~218k lines, `pg_tde` ~12k lines, `aux_mysql` ~83k lines of C/SQL) and do not change `catversion` or system catalog layouts.

IvorySQL 5.6 is a true kernel fork: it adds columns to `pg_attribute` (`attisinvisible`), `pg_class` (`relhasrowid`) and `pg_proc` (3 columns), adds three system tables (`pg_package`, `pg_package_body`, `pg_force_view`), alters `pg_control` (`dbmode`, `casemode`), compiles PL/iSQL (`47,750` lines) into the core tree, and scatters 314 `compatible_mode` / `DB_ORACLE` branches across 67 kernel files (428 existing files modified). Merging IvorySQL onto the unified tree produced 71 text conflicts across 45 files and would force every cluster into IvorySQL's catalog format. Mimus keeps IvorySQL as a separate flavor (our 12-file protocol hook applies with 2 context conflicts) and uses `orafce` for Oracle functions.

## Merging the code: 23 text conflicts vs 11 hidden runtime conflicts {#merging}

### Three-way text merge {#text-merge}

Merging Percona `release-18.6.1`, OrioleDB `patches18` and Babelfish 6.2 onto PG 18.6 (`git merge-tree --merge-base=REL_18_6`) produced **23 conflict blocks across 22 files**:

- **10 adjacent additions**: independent hooks, declarations or struct fields at the same line (`heapam_visibility.c`, `xact.c`, `elog.c`, `transam.h`).
- **7 expression merges**: e.g., OrioleDB passing `buffer` by value in `heapam.c` while Babelfish added `relation` to `HeapTupleSatisfiesUpdate()`; Percona calling `RelationCreateStoragePercona()` while Babelfish passed `!IsTsqlTableVariable(rel)`.
- **2 constant collisions**: OrioleDB's `PERFORM_DELETION_OF_RELATION` and Babelfish's `PERFORM_DELETION_SKIP_ENR` both used `0x0040` in `dependency.h` (Babelfish moved to `0x0080`).
- **2 AIO registration blocks (`aio.h`, `aio_callback.c`)**: Percona's dynamic callback allocator starts at OrioleDB's first reserved slot.

For MySQL, `aux_mysql` compiled against Babelfish's `ProtocolExtensionConfig` plus a 2-file (`+36/−5`) delta adding `fn_parse_query` and `PROTOCOL_EXTENSION_FALLTHROUGH`, avoiding the 6-file overlap with our 12-file hook.

### The 11 compile-time and runtime conflicts git did not see {#hidden-conflicts}

Running one mode per instance does not avoid cross-fork bugs: all kernel patches stay active in `postgres`. Static analysis, compilation (`--enable-debug --enable-cassert`) and runtime tests found **11 hidden conflicts** (`+30/−10` lines in the kernel, `+22/−11` in OrioleDB, `+17/−10` in Babelfish's extensions):

| ID | Stage | Symptom | Root cause and fix |
| --- | --- | --- | --- |
| `H1` | Static scan | `trigger.c:6836` compile error | OrioleDB changed `afterTriggerAddEvent()` from 3 to 5 args; Babelfish passed 3 (`NULL, NULL` added) |
| `C1` | Kernel build | 4 `-Wint-conversion` in `trigger.c` (GCC ≥ 14 error) | OrioleDB changed trigger `tupleid` to `Datum`; Babelfish's `ExecIR*TriggersTSQL` passed `ItemPointer` (updated to `Datum`) |
| `C2` | Extension build | Babelfish `forjson.c` fails (`-Werror`) | OrioleDB defined `TABLE_SIZE` in `tableam.h`, colliding with `forjson.c` (renamed in Babelfish) |
| `R1` | Runtime (`pg_tde` + OrioleDB) | OrioleDB `CREATE TABLE` fails with `pg_tde` | `pg_tde` disables `RelationCreateStorage()`; updated 3 OrioleDB calls to `RelationCreateStoragePercona()` |
| `R2` | Runtime (OrioleDB + Babelfish) | T-SQL `CREATE TABLE` on `orioledb` fails (`SI ID: -7`) | Babelfish's `SIMessageIsForTempTable()` errored on OrioleDB (`-7`) and PG 18 (`-6`) invalidation IDs (return `false`) |
| `R3` | Runtime (**OrioleDB alone**) | **Every OrioleDB `DROP TABLE` fails (`missing entries in o_indices`), even without Babelfish** | Babelfish's `RemoveRelations()` called `InvokeObjectDropHook` early whenever `object_access_hook` was set, making OrioleDB delete index entries twice. Added `pre_drop_relation_hook` |
| `R4` | Runtime (OrioleDB + Babelfish) | T-SQL error cleanup hits `Assert("DoLocalLockExist(&locktag)")` | Babelfish skips locks on `ENR` tables; OrioleDB's drop hook asserted a lock on every relation (scoped to OrioleDB tables) |
| `R5` | Runtime (Babelfish + non-heap) | T-SQL `@table` and `#temp` fail (`OID 2601 in ENR`) on `tde_heap` or `orioledb` | Babelfish's `ENR` catalog requires `heap` (**unfixed**; keep `default_table_access_method = heap` in Babelfish DBs) |
| `R6` | Configuration | `CREATE EXTENSION pg_tde` in Babelfish DB uses `information_schema_tsql` | First schema on Babelfish's `search_path` (specify `SCHEMA public`) |
| `R7` | Runtime (`aux_mysql` + `pg_tde`) | MySQL `ALTER TABLE … ENCRYPTION='Y'` wrote plaintext `tde_heap` | `aux_mysql` used `PROCESS_UTILITY_SUBCOMMAND`, skipping `pg_tde`'s `ddl_command_start` trigger (switched to `PROCESS_UTILITY_QUERY`) |
| `R8` | Configuration (TDS + MySQL) | TDS login fails on `scram-sha-256` HBA rules | Babelfish TDS requires `md5` or `password` HBA rules |
{.wide}

`R3` shows why static hook-chaining checks are not enough: all four extensions chained `ProcessUtility_hook`, `shmem_request_hook`, `shmem_startup_hook` and `object_access_hook` properly, yet Babelfish changed *when* `object_access_hook` fired inside `RemoveRelations()`, breaking OrioleDB even without Babelfish loaded.

### All four capabilities running in one instance {#four-coload}

With those fixes applied on 2026-11-07 (EL9 aarch64, `--enable-debug --enable-cassert`), one instance preloading `orioledb, pg_tde, babelfishpg_tds, aux_mysql` listened on ports 5432, 1433 and 3306 simultaneously:

- **Regression suites**: core PG passed **233/233** and isolation **123/123**; `pg_tde` passed **14/14**; OrioleDB passed **42/52** (matching the unpatched OrioleDB baseline); T-SQL `AFTER` and `INSTEAD OF` triggers passed on `heap`, `tde_heap` and `orioledb`; and `aux_mysql` passed in full.
- **Cross-feature DDL and queries**: from MySQL on port 3306, `CREATE TABLE ... ENGINE=OrioleDB` created an OrioleDB table, and `CREATE TABLE ... ENCRYPTION='Y'` created an encrypted `tde_heap` table verified free of plaintext on disk. One SQL query joined `orioledb`, `tde_heap` and `heap` tables.
- **Encryption boundary (`pg_tde` × OrioleDB)**: `pg_tde.wal_encrypt = on` encrypted WAL records for both `tde_heap` and `orioledb` tables in `pg_wal/` and recovered 6,000 rows per table after an immediate stop. Because OrioleDB bypasses `smgr` (`o_buffers` / `FileWrite`), **files under `orioledb_data/` remained in cleartext**.

## Why "it runs" is not enough: ABI and extension packages {#abi}

Building the server and four extensions from source proves source coexistence, not binary compatibility with existing packages.

On 2026-11-07, we ran libabigail's `abidiff` against stock PG 18.6 / 18.4 builds with identical `configure` flags, and tested precompiled PGDG and Pigsty PG 18 packages in each variant ([ABI compatibility](/docs/kernel/abi/), [Extension matrix](/docs/kernel/extensions/)):

| Kernel variant | `abidiff` structs | `abidiff` signatures | `NodeTag` | Stock PGDG / Pigsty PG 18 packages | Source rebuild against headers |
| --- | --- | --- | --- | --- | --- |
| Protocol hook | 1 (`ClientSocket`) | 0 | `479` | All 11 C/Rust packages pass ✅ | Not needed |
| Percona 18.4.2 | 1 (`SMgrRelationData`) | 2 (`heap_create`, `mdcreate`) | `479` | All pass ✅ (TimescaleDB 18.4/18.6 diff) | Rebuilds cleanly ✅ |
| OrioleDB (`patches18`) | 23 | 11 changed, 1 removed | `479` | `pgvector`, VectorChord, `vchord_bm25`, `pg_search`, Citus, TimescaleDB **crash** 💥 | `pgvector` passes ✅; **Citus 14.3, TimescaleDB 2.31, VectorChord fail** ❌ |
| Babelfish 6.2 | 31 (`FuncExpr`, `SelectStmt`, `Port`) | 5 | **`479` → `480`** | Citus **crashes** 💥; `pg_search` **fails** ❌ | Citus, VectorChord (pgrx `0.19.3`) rebuild and pass ✅ |
| Merged base | 55 | 31 changed, 1 removed | **`479` → `480`** | Inherits all crashes and errors 💥 | Fails to compile Citus, TimescaleDB, VectorChord ❌ |
{.wide}

Two mechanisms explain the failures:

1. **Babelfish shifts parse-node numbers and `Port` offsets**: PostgreSQL pins `$last_nodetag_no = 479` in `gen_node_support.pl` to preserve the stable-branch ABI. Babelfish bumps it to `480`, shifting `T_OidList` from `472` to `473`. Precompiled C and Rust extensions that check node tags fail at runtime: Citus crashes on `list->type == T_List`, and `pg_search` fails with `PgList does not contain oids`. Babelfish also inserts `protocol_config` into `Port` (shifting 30 fields) and enlarges `FuncExpr` (`+3` fields) and `SelectStmt` (`+8` fields). Preloading `babelfishpg_tds` also alters 2 upstream role regression tests (9 when initialized).
2. **OrioleDB alters access-method structs and signatures**: OrioleDB keeps `$last_nodetag_no = 479`, but inserts 5 callbacks into `IndexAmRoutine`, 6 into `TableAmRoutine`, and `lastCommittedCSN` into `PGPROC`. Stock index extensions allocate a smaller `IndexAmRoutine` and crash on `amoptions != NULL`. Worse, OrioleDB removes `tuple_insert_speculative`, alters `table_tuple_delete` and changes `index_fetch_tuple` from `ItemPointer` to `Datum tupleid` plus `is_rowid`—breaking compilation for Citus columnar, TimescaleDB compression and VectorChord.

## Compatibility levels A and B, and the Mimus roadmap {#roadmap}

Our ABI study defined two coexistence targets:

- **Level B (source compatible)**: extensions compile without source edits (existing functions and callbacks keep signatures; new features use `*_ext` functions and sidecar tables).
- **Level A (binary compatible)**: precompiled PGDG and Pigsty packages load unchanged (all of Level B, plus zero layout changes to public structs: append fields only to kernel-private structs, move new `PGPROC` / `ReplicationSlot` fields into sidecar shared-memory arrays, and keep `$last_nodetag_no = 479`).

Rewriting OrioleDB's 23 struct and 11 signature changes to follow the add-only rule was roughly estimated at **2–4 person-weeks for Level B** and **2–3 person-months for Level A** (rough estimates for an engineer familiar with OrioleDB internals, not commitments, and not yet prototyped; see [OrioleDB](/docs/kernel/orioledb/)). Carrying that rewrite would create a permanent fork unless upstream OrioleDB merged it.

Release cadence reinforces the split. After PG 18.6 shipped on 2026-08-11, Percona rebased in **+1 day** (`2026-08-12`), OrioleDB and IvorySQL in **+22 days** (`2026-09-02`), and Babelfish in **+48 days** (`2026-09-28`). On PG `19rc1`, the protocol hook and Percona patches are already rebased, while Babelfish, OrioleDB and IvorySQL have no PG 19 branch yet ([PostgreSQL 19](/docs/kernel/pg19/)).

Mimus therefore splits its kernel [roadmap](/docs/intro/roadmap/) along the ABI boundary:

- **Mimus 1 (Level A, binary compatible)**: PG 18.x + the 12-file protocol hook + Percona storage patches (with add-only wrappers). It runs MySQL (`aux_mysql`), `pg_tde`, and the Redis, etcd and S3 gateways, loads stock PGDG / Pigsty packages unchanged, and ships with upstream PostgreSQL (~1–2 person-days per minor release).
- **Mimus 2 (adds SQL Server, independent ABI)**: adds Babelfish (using Babelfish's protocol API + the 2-file MySQL delta) and rebuilds its extension matrix against Mimus 2 headers (~3–5 person-days per minor release after Babelfish rebases).
- **OrioleDB and IvorySQL**: remain separate flavors until upstream PostgreSQL adopts the storage and catalog interfaces they require.
