Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e1a5ed9

Browse files
committed
allocate apply bgworker handles in TopMemoryContext
1 parent dd9f6dc commit e1a5ed9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/bgwpool.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "tcop/tcopprot.h"
1616
#include "utils/syscache.h"
1717
#include "utils/inval.h"
18+
#include "utils/memutils.h"
1819

1920
#include "bgwpool.h"
2021
#include "multimaster.h"
@@ -239,6 +240,7 @@ static void BgwStartExtraWorker(BgwPool* pool)
239240
{
240241
BackgroundWorker worker;
241242
BackgroundWorkerHandle* handle;
243+
MemoryContext oldcontext;
242244

243245
if (pool->nWorkers >= MtmMaxWorkers)
244246
return;
@@ -253,6 +255,9 @@ static void BgwStartExtraWorker(BgwPool* pool)
253255
snprintf(worker.bgw_name, BGW_MAXLEN, "%s-dynworker-%d", pool->poolName, (int) pool->nWorkers + 1);
254256

255257
pool->lastDynamicWorkerStartTime = MtmGetSystemTime();
258+
259+
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
260+
256261
if (RegisterDynamicBackgroundWorker(&worker, &handle))
257262
{
258263
pool->bgwhandles[pool->nWorkers++] = handle;
@@ -261,6 +266,8 @@ static void BgwStartExtraWorker(BgwPool* pool)
261266
{
262267
elog(WARNING, "Failed to start dynamic background worker");
263268
}
269+
270+
MemoryContextSwitchTo(oldcontext);
264271
}
265272

266273
void

0 commit comments

Comments
 (0)