From 108aac393c7198156823211406ce0b0efe3431d2 Mon Sep 17 00:00:00 2001 From: Andreas Karlsson Date: Wed, 13 Aug 2025 10:00:03 +0200 Subject: [PATCH] Only initialize WAL shmem once in EXEC_BACKEND builds This only affects EXEC_BACKEND/Windows builds which we currently do not support, but we fix this anyway to make the code more consistent and easier to understand since we try to care about this in other places. In the future we may want to add CI and proper support for EXEC_BACKEND builds. The issue was originally found by Zsolt Parragi. --- contrib/pg_tde/src/access/pg_tde_xlog_smgr.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/contrib/pg_tde/src/access/pg_tde_xlog_smgr.c b/contrib/pg_tde/src/access/pg_tde_xlog_smgr.c index 2b25bcb71356c..ec85244479724 100644 --- a/contrib/pg_tde/src/access/pg_tde_xlog_smgr.c +++ b/contrib/pg_tde/src/access/pg_tde_xlog_smgr.c @@ -156,22 +156,25 @@ TDEXLogEncryptStateSize(void) void TDEXLogShmemInit(void) { - bool foundBuf; + bool found; EncryptionState = (EncryptionStateData *) ShmemInitStruct("TDE XLog Encryption State", TDEXLogEncryptStateSize(), - &foundBuf); + &found); - memset(EncryptionState, 0, sizeof(EncryptionStateData)); + if (!found) + { + memset(EncryptionState, 0, sizeof(EncryptionStateData)); - EncryptionBuf = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, ((char *) EncryptionState) + sizeof(EncryptionStateData)); + pg_atomic_init_u64(&EncryptionState->enc_key_lsn, 0); - Assert((char *) EncryptionState + TDEXLogEncryptStateSize() >= (char *) EncryptionBuf + TDEXLogEncryptBuffSize()); + elog(DEBUG1, "pg_tde: initialized encryption buffer %lu bytes", TDEXLogEncryptStateSize()); + } - pg_atomic_init_u64(&EncryptionState->enc_key_lsn, 0); + EncryptionBuf = (char *) TYPEALIGN(PG_IO_ALIGN_SIZE, ((char *) EncryptionState) + sizeof(EncryptionStateData)); - elog(DEBUG1, "pg_tde: initialized encryption buffer %lu bytes", TDEXLogEncryptStateSize()); + Assert((char *) EncryptionState + TDEXLogEncryptStateSize() >= (char *) EncryptionBuf + TDEXLogEncryptBuffSize()); } #else /* !FRONTEND */