Skip to content

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.

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 ).

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

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 (release-18.6.1, commit 19c3033d) and 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 .)

PartKernel changes in src/How pg_tde 2.2.2 uses itStock ABI effect (abidiff)Percona commits (PSP_REL_18_STABLE)
1. Extensible smgr registryMoves 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 createAdds 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_apitde_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 = false2 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 callbacksMakes 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 callbacksZero 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_smgrpg_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 patchPure addition9f59910142
5. Version guard and contribAdds 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 tablesPure addition6a7608d7ca, e10d4168c6, 85dbb5d11d, 03d9d932f7, 1d44de57fe, 19c3033dc4

How Percona’s branch relates to Commitfest #5616

Upstream Commitfest #5616: Extensible storage manager API (v6 posted on 2026-02-04 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

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

In-core TDE attempts (2016–2025)

  • 2016–2019: Ants Aasma (Cybertec) posted the first cluster-level AES-XTS patch in 2016 (thread ). Moon Insung (NTT) and Masahiko Sawada proposed table-level TDE and KMS in May 2018 (thread ), followed in 2019 by buffer-encryption prototypes from Sawada and Antonin Houska (patch , wiki ).
  • December 2020 KMS commit and revert: Bruce Momjian committed internal KMS on 2020-12-25 (978f869b99 ) and reverted it two days later (3187ef7c46 ) after Tom Lane and Michael Paquier reported issues and missing tests (thread ). In January 2021, Momjian noted the lack of consensus and stopped work (thread ); only RelationIsPermanent() landed in PG 14 (95d77149c5 ).
  • 2021–2025: Robert Haas proposed storing a page nonce in May 2021 (thread ). David Christensen (Crunchy Data) and Stephen Frost revived the KMS/TDE series in October 2022 (thread ): CF #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 ) stalled in Waiting on Author in January 2025.

Extensible smgr proposals (2021–2026)

  • 2021–2024: Anastasia Lubennikova proposed smgr hooks in June 2021 (CF #3216 , thread ), closed in March 2022 after 6 months of inactivity. In June 2023, Matthias van de Meent (Neon) posted “SMGR hook Redux” (CF #4428 , thread ), which closed in October 2024 after six Commitfests.
  • 2025–2026 (CF #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 ), adding extensible AIO callbacks and pg_smgrstat . As of 2026-11-07, #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

  • December 2025 I/O hooks RFC: When Henson Choi proposed five I/O hooks and 5 reserved pd_flags bits (thread ), Zsolt Parragi replied on 2025-12-30 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 , IvorySQL recap ) on authenticated encryption, WAL design, key management and LSN-as-IV concerns.
  • July 2026 WAL encryption benchmarks: On 2026-07-16 (follow-up 2026-07-20 ), 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

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 : 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 , 50cb7505b3 ), 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 , 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 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 .

Inference: For extensible smgr (#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

Upstream outlook by release

  • 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 , d1c01b79d4 ). See PostgreSQL 19 .
  • 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 in sync.c).
ComponentPG 20 likelihood (Inference)Basis
1. smgr registration (#5616 0001)LowUnmerged 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 mediumSmall (~20 lines) and anticipated in aio.h, but tied to part 1
2. Old RelFileLocator on create (v6-0004 + #156)LowTDE-specific rewrite context; touches heap_create / index_create
4. XLogSmgr WAL segment hookVery lowNever submitted; Percona’s July 2026 benchmark favors in-core record-level WAL encryption
In-core TDEVery low (for PG 20)No patch posted as of 2026-11-07; multi-vendor consensus takes multiple cycles
  • 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 , shrinking Mimus’s patch set). Neither path will settle before 2027.

How Mimus carries the patches

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 , ABI compatibility ):

  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.