postgres.git / summary / log / commit / refs

commit    2407c8db159dbae5afd23080a92122e1acb2f5c1
Author:   Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:     Fri Mar 27 23:02:11 2026 +0000

    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 <nathandbossart@gmail.com>
    Discussion: https://www.postgresql.org/message-id/acb_Eo1XtmCO_9z7@nathan


src/backend/storage/lmgr/lwlock.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); } /* [parent: 1f6f200cab67]