The kernel patches pg_tde needs and their upstream prospects
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
).
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
.)
| 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 |
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 ); onlyRelationIsPermanent()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 Authorin January 2025.
Extensible smgr proposals (2021–2026)
- 2021–2024: Anastasia Lubennikova proposed
smgrhooks 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 closedPG19-FinalCommitfest inNeeds 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_flagsbits (thread ), Zsolt Parragi replied on 2025-12-30 that Neon, Nile and Percona had run thesmgrpatch 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 onpgsql-hackersor inPG20-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
smgrregistration thread on 2023-07-01 : register inBaseInit()rather thanPostmasterMain(); avoid extra indirection onsmgrsw[]by using a fixed-limit static table; questionpg_compiler_barrier(); and explain whysmgrrelation_sizewas stored per entry. In the PG 18 AIO commits (da7226993f,50cb7505b3), he noted inaio.hthat extensible callback IDs work if every process re-registers callbacks in the same order underEXEC_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_flagsbits for extensions, questioned ad-hoc I/O hooks that must be maintained forever, and argued thatsmgritself should be improved if needed. - Bruce Momjian, Tom Lane and Robert Haas: Momjian noted in April 2026
that
pg_tderequires a patched fork. Not found: any direct messages from Heikki Linnakangas, Robert Haas or Tom Lane on the two extensiblesmgrthreads, 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):
19rc1shipped on 2026-10-15 andPG19-Finalclosed in April 2026. In19rc1,smgr.h,md.h,catalog/storage.h,catalog/heap.handstorage/aio.hdiffer from 18.4 only in copyright years,smgrsw[]is stillstatic const,xlog.cstill callspg_pwrite()directly, andrelease-19.sgmlcontains 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,
masterhas no extensiblesmgror AIO callback commits, and neitherPG20-3norPG20-4lists ansmgror TDE entry (only the adjacent CF #6689: Extensible sync handler registration insync.c).
| Component | PG 20 likelihood (Inference) | Basis |
|---|---|---|
1. smgr registration (#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 |
- PostgreSQL 21+ (inference): Either the community pursues in-core TDE (replacing
XLogSmgrwith core record-level WAL encryption and requiring data migration frompg_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
):
SMgrRelationData: keep themdfields andint smgr_whichin place and append customsmgrprivate fields at the end.mdcreate()andheap_create(): restore stockmdcreate()andheap_create()signatures as wrappers and addmdcreate_ext()andheap_create_ext()withold_rlocator(matchingindex_create_percona()).*_perconasymbols and version guard: keepRelationCreateStoragePercona,smgrcreate_percona,index_create_perconaandpercona_api_versionexported forpg_tde, and document the runtime guard (percona_allow_upstream_smgr_api) whenpg_tdeis loaded.