# The kernel patches pg_tde needs and their upstream prospects

> A breakdown of the 650-line Percona kernel patch set behind pg_tde, its upstream Commitfest and mailing-list history, and what that means for Mimus across PostgreSQL 18, 19 and 20.

---

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

---

Percona's `pg_tde` extension implements transparent data encryption (TDE) for PostgreSQL heap tables, indexes and WAL. An early community mode (`tde_heap_basic`, which left indexes in cleartext) was deprecated in March 2025 and removed from `pg_tde` 2.2.x. Running `pg_tde` on PostgreSQL 18 therefore requires the kernel patch set in Percona Server for PostgreSQL (`PSP_REL_18_STABLE`).

On 2026-11-07, we audited that patch set against stock PG 18.4, PG `19rc1` and PG 20 `master`, and traced every related thread on `pgsql-hackers` and the Commitfest. This post records our findings and conclusions for Mimus ([Storage patches for pg_tde](/docs/kernel/storage-patches/)).

> [!NOTE] Fact vs inference convention
> Statements below are sourced facts (with commit hashes or links) unless labeled **Inference**. Items searched for in archives and Commitfests without finding a primary source are labeled **Not found**.

## The 650-line patch set in four parts {#four-parts}

Comparing Percona Server for PostgreSQL `release-18.4.2` (commit `be009d6`) against stock PG 18.4—and cross-checking the 20 Percona commits on [`PSP_REL_18_STABLE`](https://github.com/percona/postgres/commits/PSP_REL_18_STABLE) (`release-18.6.1`, commit `19c3033d`) and [`PSP_REL_19_STABLE`](https://github.com/percona/postgres/commits/PSP_REL_19_STABLE) (rebased onto `19rc1` on 2026-10-14)—shows that the kernel changes under `src/` touch 35 files (`+650/−252` lines), plus build files, 6 `contrib` modules and test outputs. (`src/include/libpq/libpq-be.h` is not touched by Percona; that 1-line change belongs to the Mimus [protocol hook](/docs/kernel/protocol-hook/).)

| Part | Kernel changes in `src/` | How `pg_tde` 2.2.2 uses it | Stock ABI effect (`abidiff`) | Percona commits (`PSP_REL_18_STABLE`) |
| --- | --- | --- | --- | --- |
| **1. Extensible `smgr` registry** | Moves `f_smgr` to `storage/smgr.h` with `name`; replaces static `smgrsw[]` with `smgr_register(const f_smgr *, Size)`; adds `SMgrId` (`uint8`) and `storage_manager_id`; moves `md_num_open_segs` and `md_seg_fds` from `SMgrRelationData` into `MdSMgrRelationData`; calls `register_builtin_dynamic_managers()` | Registers `tde` (`RegisterStorageMgr`) and overrides `storage_manager_id` globally, wrapping `md` in `extend`, `writev`, `readv`, `startreadv`, `create` and `unlink`. Singleton only (`FATAL` if another custom `smgr` exists) | **1 struct layout change**: `SMgrRelationData` drops trailing `md` fields and narrows `smgr_which` to `uint8` (`pincount` and `node` shift; earlier fields keep offsets) | `6469142723`, `c8317c82a1`, `937fca1f3c`, `b476c8b8af` |
| **2. Encryption context on create** | Adds `old_rlocator` to `mdcreate()`, `f_smgr.smgr_create` and `heap_create()`; adds `smgrcreate_percona()`, `RelationCreateStoragePercona()` and `index_create_percona()`; updates ~20 callers; guards `RelationCreateStorage()`, `smgrcreate()` and `index_create()` with `percona_allow_upstream_smgr_api` | `tde_mdcreate()` sets `ENCRYPT` or `PLAIN` inside DDL captured by `pg_tde`'s `ProcessUtility_hook` and `ddl_command_start` event trigger, or `RETAIN` (inheriting from `old_rlocator`) during `VACUUM FULL`, `CLUSTER`, `TRUNCATE`, `SET TABLESPACE` and `REINDEX CONCURRENTLY`. Sets `percona_allow_upstream_smgr_api = false` | **2 signature changes**: `heap_create()` and `mdcreate()`. **Runtime behavior**: when `pg_tde` is loaded, legacy wrapper callers fail with `ERROR` (TimescaleDB, Citus columnar, unpatched OrioleDB) | `c204e46359`, `9bd71a588a`, `9c0ac6d6cf` (`PERCONA_API_VERSION = 3`) |
| **3. Extensible AIO callbacks** | Makes `aio_handle_cbs[]` writable with `PGAIO_HCB_MAX = 15` (4 built-in, 11 extension); adds `pgaio_io_register_callback_entry()`; drops `const` from `aio_md_readv_cb`; exports `md_readv_complete()` | PG 18 routes most reads through AIO (`smgr_startreadv`). `tde_mdstartreadv()` stores the key by I/O handle and registers `PGAIO_HCB_TDE_READV`; `tde_readv_complete()` decrypts pages between `md` and bufmgr callbacks | Zero struct or signature changes (`aio_md_readv_cb` drops `const`) | `2324a66872`, `2a839c1a45` |
| **4. WAL segment I/O (`XLogSmgr`)** | Adds `access/xlog_smgr.h` (`XLogSmgr { seg_read, seg_write }`, `xlog_smgr`, `SetXLogSmgr()`); routes `XLogWrite`, `XLogFileCopy`, `WALRead`, `XLogPageRead` and `XLogWalRcvWrite` through `xlog_smgr` | `pg_tde_xlog_smgr.c` calls `SetXLogSmgr()` to encrypt/decrypt WAL segments page by page (plus archive/restore helpers). Key-event WAL records use PG 15's standard `RegisterCustomRmgr()` (`5c279a6d35`), needing no patch | Pure addition | `9f59910142` |
| **5. Version guard and `contrib`** | Adds `PERCONA_API_VERSION` and `check_percona_api_version()`; updates 6 `contrib` modules (`amcheck`, `pageinspect`, `pg_surgery`, `pgrowlocks`, `pgstattuple`) to check `rd_tableam == GetHeapamTableAmRoutine()` | Refuses mismatched kernels and lets diagnostic tools inspect `tde_heap` tables | Pure addition | `6a7608d7ca`, `e10d4168c6`, `85dbb5d11d`, `03d9d932f7`, `1d44de57fe`, `19c3033dc4` |
{.wide}

### How Percona's branch relates to Commitfest #5616 {#cf5616-relation}

Upstream [Commitfest #5616: Extensible storage manager API](https://commitfest.postgresql.org/patch/5616) (v6 posted on [2026-02-04](https://www.postgresql.org/message-id/CAN4CZFMRgQAy+6sDfgx0oFc+JEzL2TqCiM0Ns-Z0zmrbBwss=w@mail.gmail.com) by Percona's Zsolt Parragi) contains 6 patches: `0001` (`f_smgr` exposure and global override), `0002` (`checkpoint_create_hook`), `0003` (`fsync_checker` test module), `0004` (`mdcreate` old `RelFileLocator`), `0005` (`smgr_chain` GUC) and `0006` (extensible AIO callbacks).

**Inference** (from matching patch filenames and commit subjects, without a line-by-line diff of v6): parts 1, 3 and the `mdcreate` portion of part 2 share the same origin as CF #5616, whereas the ~20-caller `heap_create` / `index_create` plumbing, `PERCONA_API_VERSION = 3` wrappers and `XLogSmgr` exist only in Percona's repository and have never been submitted upstream. Conversely, v6's `smgr_chain` GUC and `checkpoint_create_hook` are not in Percona's branch.

## Ten years of upstream TDE and extensible smgr discussions {#timeline}

Upstream PostgreSQL has debated two approaches to encryption: building TDE into core, or opening storage hooks for extensions.

### In-core TDE attempts (2016–2025) {#core-tde-history}

- **2016–2019**: Ants Aasma (Cybertec) posted the first cluster-level AES-XTS patch in 2016 ([thread](https://www.postgresql.org/message-id/flat/CA%2BCSw_tb3bk5i7if6inZFc3yyf%2B9HEVNTy51QFBoeUk7UE_V%3Dw%40mail.gmail.com)). Moon Insung (NTT) and Masahiko Sawada proposed table-level TDE and KMS in May 2018 ([thread](https://www.postgresql.org/message-id/031401d3f41d%245c70ed90%241552c8b0%24%40lab.ntt.co.jp)), followed in 2019 by buffer-encryption prototypes from Sawada and Antonin Houska ([patch](https://www.postgresql.org/message-id/CAD21AoBjrbxvaMpTApX1cEsO%3D8N%3Dnc2xVZPB0d9e-VjJ%3DYaRnw%40mail.gmail.com), [wiki](https://wiki.postgresql.org/wiki/Transparent_Data_Encryption)).
- **December 2020 KMS commit and revert**: Bruce Momjian committed internal KMS on 2020-12-25 ([`978f869b99`](https://github.com/postgres/postgres/commit/978f869b992f9fca343e99d6fdb71073c76e869a)) and reverted it two days later ([`3187ef7c46`](https://github.com/postgres/postgres/commit/3187ef7c46c5b884267a88f2d6119c9a05f1bbba)) after Tom Lane and Michael Paquier reported issues and missing tests ([thread](https://www.postgresql.org/message-id/flat/CA+fd4k7q5o6Nc_AaX6BcYM9yqTbC6_pnH-6nSD=54Zp6NBQTCQ@mail.gmail.com)). In January 2021, Momjian noted the lack of consensus and stopped work ([thread](https://www.postgresql.org/message-id/flat/2545980.1611847051%40sss.pgh.pa.us)); only `RelationIsPermanent()` landed in PG 14 ([`95d77149c5`](https://github.com/postgres/postgres/commit/95d77149c53545a74e0c84717cf8f925b8f6d632)).
- **2021–2025**: Robert Haas proposed storing a page nonce in May 2021 ([thread](https://www.postgresql.org/message-id/CA+TgmoaD8wMN6i1mmuo+4ZNeGE3Hd57ys8uV8UZm7cneqy3W2g@mail.gmail.com)). David Christensen (Crunchy Data) and Stephen Frost revived the KMS/TDE series in October 2022 ([thread](https://www.postgresql.org/message-id/CAOxo6XJh95xPOpvTxuP_kiGRs8eHcaNrmy3kkzWrzWxvyVkKkQ%40mail.gmail.com)): [CF #3985](https://commitfest.postgresql.org/patch/3985/) was returned with feedback in February 2024 after Andres Freund asked to split the heap-encryption patch, and post-special page storage ([CF #3986](https://commitfest.postgresql.org/patch/3986/)) stalled in `Waiting on Author` in January 2025.

### Extensible smgr proposals (2021–2026) {#smgr-history}

- **2021–2024**: Anastasia Lubennikova proposed `smgr` hooks in June 2021 ([CF #3216](https://commitfest.postgresql.org/patch/3216), [thread](https://www.postgresql.org/message-id/flat/CAP4vRV6JKXyFfEOf=n+v5RGsZywAQ3CTM8ESWvgq+S87Tmgx_g@mail.gmail.com)), closed in March 2022 after 6 months of inactivity. In June 2023, Matthias van de Meent (Neon) posted "SMGR hook Redux" ([CF #4428](https://commitfest.postgresql.org/patch/4428), [thread](https://www.postgresql.org/message-id/flat/CAEze2WgMySu2suO_TLvFyGY3URa4mAx22WeoEicnK%3DPCNWEMrA%40mail.gmail.com)), which closed in October 2024 after six Commitfests.
- **2025–2026 ([CF #5616](https://commitfest.postgresql.org/patch/5616))**: Andreas Karlsson (Percona) posted v3 and v4 in February–March 2025, and Zsolt Parragi posted v5 and v6 in January–February 2026 ([v6 email](https://www.postgresql.org/message-id/CAN4CZFMRgQAy+6sDfgx0oFc+JEzL2TqCiM0Ns-Z0zmrbBwss=w@mail.gmail.com)), adding extensible AIO callbacks and [`pg_smgrstat`](https://github.com/dutow/pg_smgrstat/). As of 2026-11-07, [#5616](https://commitfest.postgresql.org/patch/5616) remains in the closed `PG19-Final` Commitfest in `Needs review`, with no committer, CFBot red since 2026-03-09, and not moved into any PG 20 Commitfest.

### The late-2025 and 2026 shift toward unified in-core TDE {#shift-2026}

- **December 2025 I/O hooks RFC**: When Henson Choi proposed five I/O hooks and 5 reserved `pd_flags` bits ([thread](https://www.postgresql.org/message-id/flat/CAAAe_zCHNVKxETAWBZg3YWPdmXsf-G2OcQtQOYQn4AeZaES4tQ%40mail.gmail.com)), [Zsolt Parragi replied on 2025-12-30](https://www.postgresql.org/message-id/CAN4CZFOeN-2nWNoz5zezDU_ko4d7i8g13Ypaqp=iNurmSNcZVA@mail.gmail.com) that Neon, Nile and Percona had run the `smgr` patch in production since 2023, while Percona had held back its WAL hook because it was unsure the design belonged in core.
- **May 2026 PGConf.dev**: Percona, EDB and Cybertec held a joint session ("Stop Debating, Start Implementing: Unifying TDE Efforts for Postgres"; [Highgo recap](https://www.highgo.ca/2026/05/26/pgconf-dev-2026-why-it-remains-my-favorite-postgresql-conference/), [IvorySQL recap](https://ivorysql.org/news/pgconf-dev-2026-recap)) on authenticated encryption, WAL design, key management and LSN-as-IV concerns.
- **July 2026 WAL encryption benchmarks**: On [2026-07-16](https://www.postgresql.org/message-id/CAN4CZFN7bm+D1kDEYs=-WDNX=yatTNP=JDyPGfjWAKgeMT-TXQ@mail.gmail.com) ([follow-up 2026-07-20](https://www.postgresql.org/message-id/CAN4CZFM8tN17W+RsdVZp3opCdVXMA0oSrqZvK=Qq28xTJ7rgOQ@mail.gmail.com)), Zsolt Parragi showed that AES-CTR-256 page-level WAL encryption inside the WAL write lock critical section was up to ~20% slower on write-heavy workloads (plus ~20% higher recovery CPU), whereas record-level encryption matched `master`. He announced plans to submit an in-core record-level TDE proposal within weeks. **Not found**: as of 2026-11-07, no such proposal appeared on `pgsql-hackers` or in `PG20-3` / `PG20-4`.

**Inference**: Percona's upstream strategy shifted in mid-2026 from purely seeking extension hooks to co-designing in-core TDE (at least for WAL). If in-core WAL encryption succeeds, `pg_tde`'s `XLogSmgr` hook will be superseded by a core feature rather than merged as an extension API.

## Committer feedback and upstream preconditions {#committers}

Across all threads examined on 2026-11-07, direct committer feedback on extensible storage and TDE includes:

- **Andres Freund**: Gave the only direct committer review on the `smgr` registration thread on [2023-07-01](https://www.postgresql.org/message-id/flat/CAEze2WgMySu2suO_TLvFyGY3URa4mAx22WeoEicnK%3DPCNWEMrA%40mail.gmail.com): register in `BaseInit()` rather than `PostmasterMain()`; avoid extra indirection on `smgrsw[]` by using a fixed-limit static table; question `pg_compiler_barrier()`; and explain why `smgrrelation_size` was stored per entry. In the PG 18 AIO commits ([`da7226993f`](https://github.com/postgres/postgres/commit/da7226993fd4b73d8b40abb7167d124eada97f2e), [`50cb7505b3`](https://github.com/postgres/postgres/commit/50cb7505b3010736b9a7922e903931534785f3aa)), he noted in `aio.h` that extensible callback IDs work if every process re-registers callbacks in the same order under `EXEC_BACKEND`, and that completion callbacks must not allocate memory or start new I/O.
- **Tomas Vondra**: On [2025-12-28 and 12-30](https://www.postgresql.org/message-id/flat/CAAAe_zCHNVKxETAWBZg3YWPdmXsf-G2OcQtQOYQn4AeZaES4tQ%40mail.gmail.com), opposed reserving `pd_flags` bits for extensions, questioned ad-hoc I/O hooks that must be maintained forever, and argued that `smgr` itself should be improved if needed.
- **Bruce Momjian, Tom Lane and Robert Haas**: Momjian noted in [April 2026](https://www.postgresql.org/message-id/flat/ad9UXNBE0uMQmmpd@pureos) that `pg_tde` requires a patched fork. **Not found**: any direct messages from Heikki Linnakangas, Robert Haas or Tom Lane on the two extensible `smgr` threads, or primary verification of a 2020 export-control remark attributed to Tom Lane in [pgEdge's May 2026 article](https://www.pgedge.com/blog/why-postgres-lacks-transparent-data-encryption).

**Inference**: For extensible `smgr` ([#5616](https://commitfest.postgresql.org/patch/5616)) to land upstream, six preconditions must align: (1) a storage/AIO committer claiming the patch; (2) addressing Freund's fixed-size table and `BaseInit()` points; (3) a clean redo story (v6 sidesteps per-relation lookup during recovery via global override / `smgr_chain`); (4) multiple consumers beyond TDE (Neon, Nile, Percona, `pg_smgrstat`); (5) strict compliance with the AIO + `EXEC_BACKEND` contract; and (6) an active rebase with green CI.

## Outlook for PostgreSQL 19, 20 and 21+, and what Mimus will do {#outlook}

### Upstream outlook by release {#release-outlook}

- **PostgreSQL 19 (fact: absent)**: `19rc1` shipped on 2026-10-15 and `PG19-Final` closed in April 2026. In `19rc1`, `smgr.h`, `md.h`, `catalog/storage.h`, `catalog/heap.h` and `storage/aio.h` differ from 18.4 only in copyright years, `smgrsw[]` is still `static const`, `xlog.c` still calls `pg_pwrite()` directly, and `release-19.sgml` contains only two AIO tuning commits ([`a9ee668817`](https://github.com/postgres/postgres/commit/a9ee66881744d67193b56964b8398e5f8313e85), [`d1c01b79d4`](https://github.com/postgres/postgres/commit/d1c01b79d4ae90e52bf9db9c05c9de17b7313e85)). See [PostgreSQL 19](/docs/kernel/pg19/).
- **PostgreSQL 20 (inference: low overall likelihood before the April 2027 freeze)**: As of 2026-11-04, `master` has no extensible `smgr` or AIO callback commits, and neither `PG20-3` nor `PG20-4` lists an `smgr` or TDE entry (only the adjacent [CF #6689: Extensible sync handler registration](https://commitfest.postgresql.org/patch/6689/) in `sync.c`).

| Component | PG 20 likelihood (**Inference**) | Basis |
| --- | --- | --- |
| 1. `smgr` registration ([#5616](https://commitfest.postgresql.org/patch/5616) `0001`) | **Low** | Unmerged after 5 years and 3 CF entries; no committer; CFBot red for 7+ months; not in PG 20 CF |
| 3. AIO callback registration (`v6-0006`) | **Low to medium** | Small (~20 lines) and anticipated in `aio.h`, but tied to part 1 |
| 2. Old `RelFileLocator` on create (`v6-0004` + `#156`) | **Low** | TDE-specific rewrite context; touches `heap_create` / `index_create` |
| 4. `XLogSmgr` WAL segment hook | **Very low** | Never submitted; Percona's July 2026 benchmark favors in-core record-level WAL encryption |
| In-core TDE | **Very low (for PG 20)** | No patch posted as of 2026-11-07; multi-vendor consensus takes multiple cycles |
{.wide}

- **PostgreSQL 21+ (inference)**: Either the community pursues **in-core TDE** (replacing `XLogSmgr` with core record-level WAL encryption and requiring data migration from `pg_tde`) or it merges **extensible storage points** ([#5616](https://commitfest.postgresql.org/patch/5616), shrinking Mimus's patch set). Neither path will settle before 2027.

### How Mimus carries the patches {#mimus-plan}

Carrying Percona's ~650-line patch set costs a rough estimate of 1–2 person-days per minor release (rough estimate, not a commitment) and merges with the Mimus protocol hook with **0 conflicts**. Mimus 1 therefore includes the storage patches in PostgreSQL 18 and 19, split into four patch files (`smgr-registry`, `smgr-create-context`, `aio-callback-registry`, `wal-io-hook`) so each piece can be retired independently.

Based on source analysis on 2026-11-07 (**Inference / design judgment, not yet prototyped**), Mimus 1 can also rewrite Percona's 3 `abidiff` changes into **zero ABI changes** so precompiled PGDG packages stay 100% binary-compatible ([Storage patches for pg_tde](/docs/kernel/storage-patches/#add-only), [ABI compatibility](/docs/kernel/abi/)):

1. **`SMgrRelationData`**: keep the `md` fields and `int smgr_which` in place and append custom `smgr` private fields at the end.
2. **`mdcreate()` and `heap_create()`**: restore stock `mdcreate()` and `heap_create()` signatures as wrappers and add `mdcreate_ext()` and `heap_create_ext()` with `old_rlocator` (matching `index_create_percona()`).
3. **`*_percona` symbols and version guard**: keep `RelationCreateStoragePercona`, `smgrcreate_percona`, `index_create_percona` and `percona_api_version` exported for `pg_tde`, and document the runtime guard (`percona_allow_upstream_smgr_api`) when `pg_tde` is loaded.
