Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2bdf1b2

Browse files
committed
Reserve a PGPROC slot and semaphore for the slotsync worker process.
The need for this was missed in commit93db6cb, with the resultbeing that if we launch a slotsync worker it would consume one ofthe PGPROCs in the max_connections pool. That could lead to inabilityto launch the worker, or to subsequent failures of connection requeststhat should have succeeded according to the configured settings.Rather than create some one-off infrastructure to support this,let's group the slotsync worker with the existing autovac launcherin a new category of "special worker" processes. These are kind oflike auxiliary processes, but they cannot use that infrastructurebecause they need to be able to run transactions.For the moment, make these processes share the PGPROC freelistused for autovac workers (which previously supplied the autovaclauncher too). This is partly to avoid an ABI change in v17,and partly because it seems silly to have a freelist withat most two members. This might be worth revisiting if we growenough workers in this category.Tom Lane and Hou Zhijie. Back-patch to v17.Discussion:https://postgr.es/m/1808397.1735156190@sss.pgh.pa.us
1 parentff90ee6 commit2bdf1b2

File tree

4 files changed

+44
-24
lines changed

4 files changed

+44
-24
lines changed

‎src/backend/storage/lmgr/proc.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@ InitProcGlobal(void)
197197

198198
/*
199199
* Create and initialize all the PGPROC structures we'll need. There are
200-
* five separate consumers: (1) normal backends, (2) autovacuum workers
201-
* and the autovacuum launcher, (3) background workers, (4) auxiliary
202-
* processes, and (5) prepared transactions. Each PGPROC structure is
203-
* dedicated to exactly one of these purposes, and they do not move
204-
* between groups.
200+
* six separate consumers: (1) normal backends, (2) autovacuum workers and
201+
* special workers, (3) background workers, (4) walsenders, (5) auxiliary
202+
* processes, and (6) prepared transactions. (For largely-historical
203+
* reasons, we combine autovacuum and special workers into one category
204+
* with a single freelist.) Each PGPROC structure is dedicated to exactly
205+
* one of these purposes, and they do not move between groups.
205206
*/
206207
procs= (PGPROC*)ShmemAlloc(TotalProcs*sizeof(PGPROC));
207208
MemSet(procs,0,TotalProcs*sizeof(PGPROC));
@@ -269,26 +270,27 @@ InitProcGlobal(void)
269270
}
270271

271272
/*
272-
* Newly created PGPROCs for normal backends, autovacuum and bgworkers
273-
* must be queued up on the appropriate free list. Because there can
274-
* only ever be a small, fixed number of auxiliary processes, no free
275-
* list is used in that case; InitAuxiliaryProcess() instead uses a
276-
* linear search. PGPROCs for prepared transactions are added to a
277-
* free list by TwoPhaseShmemInit().
273+
* Newly created PGPROCs for normal backends, autovacuum workers,
274+
* special workers, bgworkers, and walsenders must be queued up on the
275+
* appropriate free list. Because there can only ever be a small,
276+
* fixed number of auxiliary processes, no free list is used in that
277+
* case; InitAuxiliaryProcess() instead uses a linear search. PGPROCs
278+
* for prepared transactions are added to a free list by
279+
* TwoPhaseShmemInit().
278280
*/
279281
if (i<MaxConnections)
280282
{
281283
/* PGPROC for normal backend, add to freeProcs list */
282284
dlist_push_tail(&ProcGlobal->freeProcs,&proc->links);
283285
proc->procgloballist=&ProcGlobal->freeProcs;
284286
}
285-
elseif (i<MaxConnections+autovacuum_max_workers+1)
287+
elseif (i<MaxConnections+autovacuum_max_workers+NUM_SPECIAL_WORKER_PROCS)
286288
{
287-
/* PGPROC for AVlauncher/worker, add to autovacFreeProcs list */
289+
/* PGPROC for AVor specialworker, add to autovacFreeProcs list */
288290
dlist_push_tail(&ProcGlobal->autovacFreeProcs,&proc->links);
289291
proc->procgloballist=&ProcGlobal->autovacFreeProcs;
290292
}
291-
elseif (i<MaxConnections+autovacuum_max_workers+1+max_worker_processes)
293+
elseif (i<MaxConnections+autovacuum_max_workers+NUM_SPECIAL_WORKER_PROCS+max_worker_processes)
292294
{
293295
/* PGPROC for bgworker, add to bgworkerFreeProcs list */
294296
dlist_push_tail(&ProcGlobal->bgworkerFreeProcs,&proc->links);
@@ -358,8 +360,11 @@ InitProcess(void)
358360
if (IsUnderPostmaster)
359361
RegisterPostmasterChildActive();
360362

361-
/* Decide which list should supply our PGPROC. */
362-
if (AmAutoVacuumLauncherProcess()||AmAutoVacuumWorkerProcess())
363+
/*
364+
* Decide which list should supply our PGPROC. This logic must match the
365+
* way the freelists were constructed in InitProcGlobal().
366+
*/
367+
if (AmAutoVacuumWorkerProcess()||AmSpecialWorkerProcess())
363368
procgloballist=&ProcGlobal->autovacFreeProcs;
364369
elseif (AmBackgroundWorkerProcess())
365370
procgloballist=&ProcGlobal->bgworkerFreeProcs;

‎src/backend/utils/init/postinit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,9 +544,9 @@ InitializeMaxBackends(void)
544544
{
545545
Assert(MaxBackends==0);
546546

547-
/*the extra unit accounts for the autovacuum launcher */
548-
MaxBackends=MaxConnections+autovacuum_max_workers+1+
549-
max_worker_processes+max_wal_senders;
547+
/*Note that this does not include "auxiliary" processes */
548+
MaxBackends=MaxConnections+autovacuum_max_workers+
549+
max_worker_processes+max_wal_senders+NUM_SPECIAL_WORKER_PROCS;
550550

551551
if (MaxBackends>MAX_BACKENDS)
552552
ereport(ERROR,
@@ -555,7 +555,7 @@ InitializeMaxBackends(void)
555555
errdetail("\"max_connections\" (%d) plus \"autovacuum_max_workers\" (%d) plus \"max_worker_processes\" (%d) plus \"max_wal_senders\" (%d) must be less than %d.",
556556
MaxConnections,autovacuum_max_workers,
557557
max_worker_processes,max_wal_senders,
558-
MAX_BACKENDS)));
558+
MAX_BACKENDS- (NUM_SPECIAL_WORKER_PROCS-1))));
559559
}
560560

561561
/*

‎src/include/miscadmin.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,9 @@ typedef enum BackendType
350350

351351
/*
352352
* Auxiliary processes. These have PGPROC entries, but they are not
353-
* attached to any particular database. There can be only one of each of
354-
* these running at a time.
353+
* attached to any particular database, and cannot run transactions or
354+
* even take heavyweight locks. There can be only one of each of these
355+
* running at a time.
355356
*
356357
* If you modify these, make sure to update NUM_AUXILIARY_PROCS and the
357358
* glossary in the docs.
@@ -388,6 +389,10 @@ extern PGDLLIMPORT BackendType MyBackendType;
388389
#defineAmWalSummarizerProcess()(MyBackendType == B_WAL_SUMMARIZER)
389390
#defineAmWalWriterProcess()(MyBackendType == B_WAL_WRITER)
390391

392+
#defineAmSpecialWorkerProcess() \
393+
(AmAutoVacuumLauncherProcess() || \
394+
AmLogicalSlotSyncWorkerProcess())
395+
391396
externconstchar*GetBackendTypeDesc(BackendTypebackendType);
392397

393398
externvoidSetDatabasePath(constchar*path);

‎src/include/storage/proc.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ typedef struct PROC_HDR
408408
uint32allProcCount;
409409
/* Head of list of free PGPROC structures */
410410
dlist_headfreeProcs;
411-
/* Head of list of autovacuum's free PGPROC structures */
411+
/* Head of list of autovacuum & special worker free PGPROC structures */
412412
dlist_headautovacFreeProcs;
413413
/* Head of list of bgworker free PGPROC structures */
414414
dlist_headbgworkerFreeProcs;
@@ -442,9 +442,19 @@ extern PGDLLIMPORT PGPROC *PreparedXactProcs;
442442
#defineGetPGProcByNumber(n) (&ProcGlobal->allProcs[(n)])
443443
#defineGetNumberFromPGProc(proc) ((proc) - &ProcGlobal->allProcs[0])
444444

445+
/*
446+
* We set aside some extra PGPROC structures for "special worker" processes,
447+
* which are full-fledged backends (they can run transactions)
448+
* but are unique animals that there's never more than one of.
449+
* Currently there are two such processes: the autovacuum launcher
450+
* and the slotsync worker.
451+
*/
452+
#defineNUM_SPECIAL_WORKER_PROCS2
453+
445454
/*
446455
* We set aside some extra PGPROC structures for auxiliary processes,
447-
* ie things that aren't full-fledged backends but need shmem access.
456+
* ie things that aren't full-fledged backends (they cannot run transactions
457+
* or take heavyweight locks) but need shmem access.
448458
*
449459
* Background writer, checkpointer, WAL writer, WAL summarizer, and archiver
450460
* run during normal operation. Startup process and WAL receiver also consume

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp