mirror of
https://github.com/postgres/postgres.git
synced 2026-04-15 22:10:45 -04:00
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
This commit is contained in:
parent
1f6f200cab
commit
2407c8db15
1 changed files with 9 additions and 1 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
Loading…
Reference in a new issue