From: Heikki Linnakangas Date: Fri, 27 Mar 2026 23:02:11 +0000 (+0200) Subject: Fix RequestNamedLWLockTranche in single-user mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2407c8db159dbae5afd23080a92122e1acb2f5c1;p=thirdparty%2Fpostgresql.git Fix RequestNamedLWLockTranche in single-user mode PostmasterContext is not available in single-user mode, use TopMemoryContext instead. Also make sure that we use the correct memory context in the lappend(). Author: Nathan Bossart Discussion: https://www.postgresql.org/message-id/acb_Eo1XtmCO_9z7@nathan --- diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 7a68071302a..f5b2a6d479d 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -630,6 +630,7 @@ void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks) { NamedLWLockTrancheRequest *request; + MemoryContext oldcontext; if (!process_shmem_requests_in_progress) elog(FATAL, "cannot request additional LWLocks outside shmem_request_hook"); @@ -652,10 +653,17 @@ RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks) errdetail("No more than %d tranches may be registered.", MAX_USER_DEFINED_TRANCHES))); - request = MemoryContextAllocZero(PostmasterContext, sizeof(NamedLWLockTrancheRequest)); + if (IsPostmasterEnvironment) + oldcontext = MemoryContextSwitchTo(PostmasterContext); + else + oldcontext = MemoryContextSwitchTo(TopMemoryContext); + + request = palloc0(sizeof(NamedLWLockTrancheRequest)); strlcpy(request->tranche_name, tranche_name, NAMEDATALEN); request->num_lwlocks = num_lwlocks; NamedLWLockTrancheRequests = lappend(NamedLWLockTrancheRequests, request); + + MemoryContextSwitchTo(oldcontext); } /*