From bbffe289d381985d794b309d0561746fe6c90cb8 Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Mon, 21 Sep 2026 17:18:34 +0000 Subject: [PATCH v1] Fix crash with wal_debug in EXEC_BACKEND child processes. Converting xlog.c to the new shared memory allocation API left the creation of the memory context used by wal_debug in the initialization callback, which runs only in the postmaster or in a standalone backend. In EXEC_BACKEND builds, child processes run the attach callback instead, and that one was not taught to create the context. Previously, XLOGShmemInit() itself ran in every child and created the context before returning early. As a result, with WAL_DEBUG compiled in and wal_debug turned on, a child process has nowhere to allocate the description of the record it is about to insert, and crashes on the first WAL insertion. Fix this by creating the context from both callbacks, so that every process ends up with one as it did before. Creating it lazily on first use would be tidier, but WAL insertion happens in a critical section, where a new memory context cannot be created. Oversight in 9b5acad3f40f. Author: Bharath Rupireddy Discussion: https://postgr.es/m/ Backpatch-through: 19 --- src/backend/access/transam/xlog.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 9ec0be77ca0..73c7821f6d2 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -5562,14 +5562,11 @@ XLOGShmemRequest(void *arg) } /* - * XLOGShmemInit - initialize the XLogCtl shared memory area. + * Initialize process-local state needed by wal_debug. */ static void -XLOGShmemInit(void *arg) +InitWalDebug(void) { - char *allocptr; - int i; - #ifdef WAL_DEBUG /* @@ -5585,6 +5582,18 @@ XLOGShmemInit(void *arg) MemoryContextAllowInCriticalSection(walDebugCxt, true); } #endif +} + +/* + * XLOGShmemInit - initialize the XLogCtl shared memory area. + */ +static void +XLOGShmemInit(void *arg) +{ + char *allocptr; + int i; + + InitWalDebug(); memset(XLogCtl, 0, sizeof(XLogCtlData)); @@ -5667,6 +5676,8 @@ static void XLOGShmemAttach(void *arg) { WALInsertLocks = XLogCtl->Insert.WALInsertLocks; + + InitWalDebug(); } /* -- 2.47.3