pgsql: Fix crash with wal_debug in EXEC_BACKEND child processes

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix crash with wal_debug in EXEC_BACKEND child processes
Date: 2026-10-09 22:21:04
Message-ID: E1xFIxc-000000010DS-3zgc@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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
XLOGShmemInit() callback, which now only runs in the postmaster or in
a standalone backend. Previously, XLOGShmemInit() ran in every child.
As a result, walDebugCtx was left uninitialized in child processes in
EXEC_BACKEND mode, and with wal_debug turned on, the backend crashed
on first WAL insertion.

Fix by moving the walDebugCtx initialization to a separate function
that is called in each backend that wishes to create WAL records. (It
cannot be created lazily on first WAL insertion, because it's done in
a critical section, and you cannot create a new memory context in a
critical section.)

Oversight in 9b5acad3f40f.

Co-authored-by:: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Reviewed-by: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Discussion: https://www.postgresql.org/message-id/CALj2ACUNL4Xn3aBzvm4DTpdr_L0-AfL2agsghMRRy_ZTiKhxSA@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/270caee04f5632ab006ec8b3d160dabac91cdf31

Modified Files
--------------
src/backend/access/transam/xlog.c | 40 ++++++++++++++++++++-------------
src/backend/access/transam/xloginsert.c | 5 +++++
src/include/access/xlog.h | 3 +++
3 files changed, 32 insertions(+), 16 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Richard Guo 2026-10-10 00:23:29 pgsql: Don't trust NOT NULL on virtual generated columns of partitioned
Previous Message Heikki Linnakangas 2026-10-09 21:29:13 pgsql: Fix check on test function's arguments