PG-2278 Re-use cipher contexts for SMGR encryption#554
Open
jeltz wants to merge 1 commit intopercona:mainfrom
Open
PG-2278 Re-use cipher contexts for SMGR encryption#554jeltz wants to merge 1 commit intopercona:mainfrom
jeltz wants to merge 1 commit intopercona:mainfrom
Conversation
Codecov Report❌ Patch coverage is ❌ Your project status has failed because the head coverage (75.83%) is below the target coverage (90.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #554 +/- ##
==========================================
- Coverage 57.47% 57.44% -0.03%
==========================================
Files 68 68
Lines 10709 10711 +2
Branches 2640 2642 +2
==========================================
- Hits 6155 6153 -2
- Misses 3292 3295 +3
- Partials 1262 1263 +1
🚀 New features to boost your workflow:
|
40ec44e to
3b567f5
Compare
dutow
reviewed
Mar 30, 2026
e2093dc to
d25fbe4
Compare
f62f4cb to
c9c4232
Compare
dutow
reviewed
Apr 2, 2026
5855d48 to
489ae42
Compare
Profiling with perf revealed that EVP_CipherInit_ex() showed up quite a lot when encrypting and decrypting tables, so to decrease how much it shows up we make sure to only allocate and initialize contexts for SMGR encryption once on loading pg_tde and then re-use those contexts but re-initializing them with different keys and IVs on use, which is a lot cheaper than doing a full initialization. This way of calling EVP_CipherInit_ex() is poorly documented in OpenSSL. WAL encryption already has logic for reusing contexts so this optimization is not as relevant there. Also removes an no longer true comment related to the WAL encryption.
489ae42 to
b854657
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Profiling with
perfrevealed thatEVP_CipherInit_ex()showed up quite a lot when encrypting and decrypting tables, so to decrease how much it shows up we make sure to only allocate and initialize contexts for SMGR encryption once on loadingpg_tdeand then re-use those contexts but re-initializing them with different keys and IVs on use, which is a lot cheaper than doing a full initialization. This way of callingEVP_CipherInit_ex()is poorly documented in OpenSSL.WAL encryption already has logic for reusing contexts so this optimization is not as relevant there.