summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane2024-12-28 17:30:42 +0000
committerTom Lane2024-12-28 17:30:42 +0000
commit14141bbbc103bf5db41c8f9a8206dfc9ca626e9f (patch)
tree1f9dd728e9dab97bae8620824d63b4014fa3404a /src/include
parenta46311ed7214741ad0d38893da4285b2c2b468ad (diff)
Reserve a PGPROC slot and semaphore for the slotsync worker process.
The need for this was missed in commit 93db6cbda, with the result being that if we launch a slotsync worker it would consume one of the PGPROCs in the max_connections pool. That could lead to inability to launch the worker, or to subsequent failures of connection requests that 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 launcher in a new category of "special worker" processes. These are kind of like auxiliary processes, but they cannot use that infrastructure because they need to be able to run transactions. For the moment, make these processes share the PGPROC freelist used for autovac workers (which previously supplied the autovac launcher too). This is partly to avoid an ABI change in v17, and partly because it seems silly to have a freelist with at most two members. This might be worth revisiting if we grow enough workers in this category. Tom Lane and Hou Zhijie. Back-patch to v17. Discussion: https://postgr.es/m/1808397.1735156190@sss.pgh.pa.us
Diffstat (limited to 'src/include')
-rw-r--r--src/include/miscadmin.h9
-rw-r--r--src/include/storage/proc.h14
2 files changed, 19 insertions, 4 deletions
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index d3ff1d22795..ea7efefaf08 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -346,8 +346,9 @@ typedef enum BackendType
/*
* Auxiliary processes. These have PGPROC entries, but they are not
- * attached to any particular database. There can be only one of each of
- * these running at a time.
+ * attached to any particular database, and cannot run transactions or
+ * even take heavyweight locks. There can be only one of each of these
+ * running at a time.
*
* If you modify these, make sure to update NUM_AUXILIARY_PROCS and the
* glossary in the docs.
@@ -384,6 +385,10 @@ extern PGDLLIMPORT BackendType MyBackendType;
#define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
#define AmWalWriterProcess() (MyBackendType == B_WAL_WRITER)
+#define AmSpecialWorkerProcess() \
+ (AmAutoVacuumLauncherProcess() || \
+ AmLogicalSlotSyncWorkerProcess())
+
extern const char *GetBackendTypeDesc(BackendType backendType);
extern void SetDatabasePath(const char *path);
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index 9488bf1857c..e1281b44730 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -404,7 +404,7 @@ typedef struct PROC_HDR
uint32 allProcCount;
/* Head of list of free PGPROC structures */
dlist_head freeProcs;
- /* Head of list of autovacuum's free PGPROC structures */
+ /* Head of list of autovacuum & special worker free PGPROC structures */
dlist_head autovacFreeProcs;
/* Head of list of bgworker free PGPROC structures */
dlist_head bgworkerFreeProcs;
@@ -435,8 +435,18 @@ extern PGDLLIMPORT PGPROC *PreparedXactProcs;
#define GetNumberFromPGProc(proc) ((proc) - &ProcGlobal->allProcs[0])
/*
+ * We set aside some extra PGPROC structures for "special worker" processes,
+ * which are full-fledged backends (they can run transactions)
+ * but are unique animals that there's never more than one of.
+ * Currently there are two such processes: the autovacuum launcher
+ * and the slotsync worker.
+ */
+#define NUM_SPECIAL_WORKER_PROCS 2
+
+/*
* We set aside some extra PGPROC structures for auxiliary processes,
- * ie things that aren't full-fledged backends but need shmem access.
+ * ie things that aren't full-fledged backends (they cannot run transactions
+ * or take heavyweight locks) but need shmem access.
*
* Background writer, checkpointer, WAL writer, WAL summarizer, and archiver
* run during normal operation. Startup process and WAL receiver also consume