On 08/12/2023 14:33, Heikki Linnakangas wrote:
+ [PMC_AV_LAUNCHER] = {"autovacuum launcher", AutoVacLauncherMain, true},
+ [PMC_AV_WORKER] = {"autovacuum worker", AutoVacWorkerMain, true},
+ [PMC_BGWORKER] = {"bgworker", BackgroundWorkerMain, true},
+ [PMC_SYSLOGGER] = {"syslogger", SysLoggerMain, false},
+
+ [PMC_STARTUP] = {"startup", StartupProcessMain, true},
+ [PMC_BGWRITER] = {"bgwriter", BackgroundWriterMain, true},
+ [PMC_ARCHIVER] = {"archiver", PgArchiverMain, true},
+ [PMC_CHECKPOINTER] = {"checkpointer", CheckpointerMain, true},
+ [PMC_WAL_WRITER] = {"wal_writer", WalWriterMain, true},
+ [PMC_WAL_RECEIVER] = {"wal_receiver", WalReceiverMain, true},
+};
It feels like we have too many different ways of documenting the type of a
process. This new PMC_ stuff, enum AuxProcType, enum BackendType.
Agreed. And "am_walsender" and such variables.
Here's a patch that gets rid of AuxProcType. It's independent of the
other patches in this thread; if this is committed, I'll rebase the rest
of the patches over this and get rid of the new PMC_* enum.
Three patches, actually. The first one fixes an existing comment that I
noticed to be incorrect while working on this. I'll push that soon,
barring objections. The second one gets rid of AuxProcType, and the
third one replaces IsBackgroundWorker, IsAutoVacuumLauncherProcess() and
IsAutoVacuumWorkerProcess() with checks on MyBackendType. So
MyBackendType is now the primary way to check what kind of a process the
current process is.
'am_walsender' would also be fairly straightforward to remove and
replace with AmWalSenderProcess(). I didn't do that because we also have
am_db_walsender and am_cascading_walsender which cannot be directly
replaced with MyBackendType. Given that, it might be best to keep
am_walsender for symmetry.
--
Heikki Linnakangas
Neon (https://neon.tech)
From a0ecc54763252de74907fd0e4aed30fdb753ff86 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakan...@iki.fi>
Date: Wed, 10 Jan 2024 13:46:23 +0200
Subject: [PATCH v6 1/3] Fix incorrect comment on how BackendStatusArray is
indexed
The comment was copy-pasted from the call to ProcSignalInit() in
AuxiliaryProcessMain(), which uses a similar scheme of having reserved
slots for aux processes after MaxBackends slots for backends. However,
ProcSignalInit() indexing starts from 1, whereas BackendStatusArray
starts from 0. The code is correct, but the comment was wrong.
Reviewed-by: XXX
Discussion: XXX
---
src/backend/utils/activity/backend_status.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index 3dac79c30eb..1a1050c8da1 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -263,9 +263,9 @@ pgstat_beinit(void)
* Assign the MyBEEntry for an auxiliary process. Since it doesn't
* have a BackendId, the slot is statically allocated based on the
* auxiliary process type (MyAuxProcType). Backends use slots indexed
- * in the range from 1 to MaxBackends (inclusive), so we use
- * MaxBackends + AuxBackendType + 1 as the index of the slot for an
- * auxiliary process.
+ * in the range from 0 to MaxBackends (exclusive), so we use
+ * MaxBackends + AuxProcType as the index of the slot for an auxiliary
+ * process.
*/
MyBEEntry = &BackendStatusArray[MaxBackends + MyAuxProcType];
}
--
2.39.2
From 68b8c662af229f93244b45282f3112d9a5d809b9 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakan...@iki.fi>
Date: Wed, 10 Jan 2024 14:00:09 +0200
Subject: [PATCH v6 2/3] Remove MyAuxProcType, use MyBackendType instead
MyAuxProcType was redundant with MyBackendType.
Reviewed-by: XXX
Discussion: XXX
---
src/backend/postmaster/auxprocess.c | 68 +++++---------------
src/backend/postmaster/postmaster.c | 36 +++++------
src/backend/utils/activity/backend_status.c | 11 ++--
src/include/miscadmin.h | 71 ++++++++++-----------
src/include/postmaster/auxprocess.h | 2 +-
src/tools/pgindent/typedefs.list | 1 -
6 files changed, 74 insertions(+), 115 deletions(-)
diff --git a/src/backend/postmaster/auxprocess.c b/src/backend/postmaster/auxprocess.c
index ab86e802f21..bd3815b63d0 100644
--- a/src/backend/postmaster/auxprocess.c
+++ b/src/backend/postmaster/auxprocess.c
@@ -38,14 +38,6 @@
static void ShutdownAuxiliaryProcess(int code, Datum arg);
-/* ----------------
- * global variables
- * ----------------
- */
-
-AuxProcType MyAuxProcType = NotAnAuxProcess; /* declared in miscadmin.h */
-
-
/*
* AuxiliaryProcessMain
*
@@ -55,39 +47,13 @@ AuxProcType MyAuxProcType = NotAnAuxProcess; /* declared in miscadmin.h */
* This code is here just because of historical reasons.
*/
void
-AuxiliaryProcessMain(AuxProcType auxtype)
+AuxiliaryProcessMain(BackendType auxtype)
{
Assert(IsUnderPostmaster);
- MyAuxProcType = auxtype;
-
- switch (MyAuxProcType)
- {
- case StartupProcess:
- MyBackendType = B_STARTUP;
- break;
- case ArchiverProcess:
- MyBackendType = B_ARCHIVER;
- break;
- case BgWriterProcess:
- MyBackendType = B_BG_WRITER;
- break;
- case CheckpointerProcess:
- MyBackendType = B_CHECKPOINTER;
- break;
- case WalWriterProcess:
- MyBackendType = B_WAL_WRITER;
- break;
- case WalReceiverProcess:
- MyBackendType = B_WAL_RECEIVER;
- break;
- case WalSummarizerProcess:
- MyBackendType = B_WAL_SUMMARIZER;
- break;
- default:
- elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
- MyBackendType = B_INVALID;
- }
+ MyBackendType = auxtype;
+ if (!IsAuxProcess(MyBackendType))
+ elog(PANIC, "unrecognized process type: %d", (int) MyBackendType);
init_ps_display(NULL);
@@ -110,14 +76,14 @@ AuxiliaryProcessMain(AuxProcType auxtype)
/*
* Assign the ProcSignalSlot for an auxiliary process. Since it doesn't
* have a BackendId, the slot is statically allocated based on the
- * auxiliary process type (MyAuxProcType). Backends use slots indexed in
- * the range from 1 to MaxBackends (inclusive), so we use MaxBackends +
- * AuxProcType + 1 as the index of the slot for an auxiliary process.
+ * auxiliary process type. Backends use slots indexed in the range from 1
+ * to MaxBackends (inclusive), and aux processes use the slots after that,
+ * one reserved slot for each different kind of aux process.
*
* This will need rethinking if we ever want more than one of a particular
* auxiliary process type.
*/
- ProcSignalInit(MaxBackends + MyAuxProcType + 1);
+ ProcSignalInit(MaxBackends + MyBackendType - FIRST_AUX_PROC + 1);
/*
* Auxiliary processes don't run transactions, but they may need a
@@ -136,38 +102,38 @@ AuxiliaryProcessMain(AuxProcType auxtype)
SetProcessingMode(NormalProcessing);
- switch (MyAuxProcType)
+ switch (MyBackendType)
{
- case StartupProcess:
+ case B_STARTUP:
StartupProcessMain();
proc_exit(1);
- case ArchiverProcess:
+ case B_ARCHIVER:
PgArchiverMain();
proc_exit(1);
- case BgWriterProcess:
+ case B_BG_WRITER:
BackgroundWriterMain();
proc_exit(1);
- case CheckpointerProcess:
+ case B_CHECKPOINTER:
CheckpointerMain();
proc_exit(1);
- case WalWriterProcess:
+ case B_WAL_WRITER:
WalWriterMain();
proc_exit(1);
- case WalReceiverProcess:
+ case B_WAL_RECEIVER:
WalReceiverMain();
proc_exit(1);
- case WalSummarizerProcess:
+ case B_WAL_SUMMARIZER:
WalSummarizerMain();
proc_exit(1);
default:
- elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
+ elog(PANIC, "unrecognized process type: %d", (int) MyBackendType);
proc_exit(1);
}
}
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index feb471dd1df..c51b6a1376a 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -440,7 +440,7 @@ static int CountChildren(int target);
static bool assign_backendlist_entry(RegisteredBgWorker *rw);
static void maybe_start_bgworkers(void);
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
-static pid_t StartChildProcess(AuxProcType type);
+static pid_t StartChildProcess(BackendType type);
static void StartAutovacuumWorker(void);
static void MaybeStartWalReceiver(void);
static void MaybeStartWalSummarizer(void);
@@ -561,13 +561,13 @@ static void ShmemBackendArrayAdd(Backend *bn);
static void ShmemBackendArrayRemove(Backend *bn);
#endif /* EXEC_BACKEND */
-#define StartupDataBase() StartChildProcess(StartupProcess)
-#define StartArchiver() StartChildProcess(ArchiverProcess)
-#define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
-#define StartCheckpointer() StartChildProcess(CheckpointerProcess)
-#define StartWalWriter() StartChildProcess(WalWriterProcess)
-#define StartWalReceiver() StartChildProcess(WalReceiverProcess)
-#define StartWalSummarizer() StartChildProcess(WalSummarizerProcess)
+#define StartupDataBase() StartChildProcess(B_STARTUP)
+#define StartArchiver() StartChildProcess(B_ARCHIVER)
+#define StartBackgroundWriter() StartChildProcess(B_BG_WRITER)
+#define StartCheckpointer() StartChildProcess(B_CHECKPOINTER)
+#define StartWalWriter() StartChildProcess(B_WAL_WRITER)
+#define StartWalReceiver() StartChildProcess(B_WAL_RECEIVER)
+#define StartWalSummarizer() StartChildProcess(B_WAL_SUMMARIZER)
/* Macros to check exit status of a child process */
#define EXIT_STATUS_0(st) ((st) == 0)
@@ -4953,7 +4953,7 @@ SubPostmasterMain(int argc, char *argv[])
}
if (strcmp(argv[1], "--forkaux") == 0)
{
- AuxProcType auxtype;
+ BackendType auxtype;
Assert(argc == 4);
@@ -5292,7 +5292,7 @@ CountChildren(int target)
* to start subprocess.
*/
static pid_t
-StartChildProcess(AuxProcType type)
+StartChildProcess(BackendType type)
{
pid_t pid;
@@ -5344,31 +5344,31 @@ StartChildProcess(AuxProcType type)
errno = save_errno;
switch (type)
{
- case StartupProcess:
+ case B_STARTUP:
ereport(LOG,
(errmsg("could not fork startup process: %m")));
break;
- case ArchiverProcess:
+ case B_ARCHIVER:
ereport(LOG,
(errmsg("could not fork archiver process: %m")));
break;
- case BgWriterProcess:
+ case B_BG_WRITER:
ereport(LOG,
(errmsg("could not fork background writer process: %m")));
break;
- case CheckpointerProcess:
+ case B_CHECKPOINTER:
ereport(LOG,
(errmsg("could not fork checkpointer process: %m")));
break;
- case WalWriterProcess:
+ case B_WAL_WRITER:
ereport(LOG,
(errmsg("could not fork WAL writer process: %m")));
break;
- case WalReceiverProcess:
+ case B_WAL_RECEIVER:
ereport(LOG,
(errmsg("could not fork WAL receiver process: %m")));
break;
- case WalSummarizerProcess:
+ case B_WAL_SUMMARIZER:
ereport(LOG,
(errmsg("could not fork WAL summarizer process: %m")));
break;
@@ -5382,7 +5382,7 @@ StartChildProcess(AuxProcType type)
* fork failure is fatal during startup, but there's no need to choke
* immediately if starting other child types fails.
*/
- if (type == StartupProcess)
+ if (type == B_STARTUP)
ExitPostmaster(1);
return 0;
}
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index 1a1050c8da1..92f24db4e18 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -257,17 +257,16 @@ pgstat_beinit(void)
else
{
/* Must be an auxiliary process */
- Assert(MyAuxProcType != NotAnAuxProcess);
+ Assert(IsAuxProcess(MyBackendType));
/*
* Assign the MyBEEntry for an auxiliary process. Since it doesn't
* have a BackendId, the slot is statically allocated based on the
- * auxiliary process type (MyAuxProcType). Backends use slots indexed
- * in the range from 0 to MaxBackends (exclusive), so we use
- * MaxBackends + AuxProcType as the index of the slot for an auxiliary
- * process.
+ * auxiliary process type. Backends use slots indexed in the range
+ * from 0 to MaxBackends (exclusive), and aux processes use the slots
+ * after that.
*/
- MyBEEntry = &BackendStatusArray[MaxBackends + MyAuxProcType];
+ MyBEEntry = &BackendStatusArray[MaxBackends + MyBackendType - FIRST_AUX_PROC];
}
/* Set up a process-exit hook to clean up */
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 0b01c1f0935..70da52a7876 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -321,21 +321,36 @@ extern void InitProcessLocalLatch(void);
extern void SwitchToSharedLatch(void);
extern void SwitchBackToLocalLatch(void);
+/*
+ * MyBackendType indicates what kind of a backend this is.
+ */
typedef enum BackendType
{
B_INVALID = 0,
- B_ARCHIVER,
+
+ /* Backends and other backend-like processes */
+ B_BACKEND,
B_AUTOVAC_LAUNCHER,
B_AUTOVAC_WORKER,
- B_BACKEND,
B_BG_WORKER,
+ B_WAL_SENDER,
+
+ B_STANDALONE_BACKEND,
+ B_LOGGER,
+
+ /*
+ * 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.
+ *
+ * If you modify these, make sure to update NUM_AUXILIARY_PROCS and the
+ * glossary in the docs.
+ */
+ B_ARCHIVER,
B_BG_WRITER,
B_CHECKPOINTER,
- B_LOGGER,
- B_STANDALONE_BACKEND,
B_STARTUP,
B_WAL_RECEIVER,
- B_WAL_SENDER,
B_WAL_SUMMARIZER,
B_WAL_WRITER,
} BackendType;
@@ -344,6 +359,19 @@ typedef enum BackendType
extern PGDLLIMPORT BackendType MyBackendType;
+#define FIRST_AUX_PROC B_ARCHIVER
+#define NUM_AUXPROCTYPES (BACKEND_NUM_TYPES - FIRST_AUX_PROC)
+
+#define AmStartupProcess() (MyBackendType == B_STARTUP)
+#define AmBackgroundWriterProcess() (MyBackendType == B_BG_WRITER)
+#define AmArchiverProcess() (MyBackendType == B_ARCHIVER)
+#define AmCheckpointerProcess() (MyBackendType == B_CHECKPOINTER)
+#define AmWalWriterProcess() (MyBackendType == B_WAL_WRITER)
+#define AmWalReceiverProcess() (MyBackendType == B_WAL_RECEIVER)
+#define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
+
+#define IsAuxProcess(type) (MyBackendType >= FIRST_AUX_PROC)
+
extern const char *GetBackendTypeDesc(BackendType backendType);
extern void SetDatabasePath(const char *path);
@@ -426,39 +454,6 @@ extern PGDLLIMPORT ProcessingMode Mode;
} while(0)
-/*
- * Auxiliary-process type identifiers. These used to be in bootstrap.h
- * but it seems saner to have them here, with the ProcessingMode stuff.
- * The MyAuxProcType global is defined and set in auxprocess.c.
- *
- * Make sure to list in the glossary any items you add here.
- */
-
-typedef enum
-{
- NotAnAuxProcess = -1,
- StartupProcess = 0,
- BgWriterProcess,
- ArchiverProcess,
- CheckpointerProcess,
- WalWriterProcess,
- WalReceiverProcess,
- WalSummarizerProcess,
-
- NUM_AUXPROCTYPES /* Must be last! */
-} AuxProcType;
-
-extern PGDLLIMPORT AuxProcType MyAuxProcType;
-
-#define AmStartupProcess() (MyAuxProcType == StartupProcess)
-#define AmBackgroundWriterProcess() (MyAuxProcType == BgWriterProcess)
-#define AmArchiverProcess() (MyAuxProcType == ArchiverProcess)
-#define AmCheckpointerProcess() (MyAuxProcType == CheckpointerProcess)
-#define AmWalWriterProcess() (MyAuxProcType == WalWriterProcess)
-#define AmWalReceiverProcess() (MyAuxProcType == WalReceiverProcess)
-#define AmWalSummarizerProcess() (MyAuxProcType == WalSummarizerProcess)
-
-
/*****************************************************************************
* pinit.h -- *
* POSTGRES initialization and cleanup definitions. *
diff --git a/src/include/postmaster/auxprocess.h b/src/include/postmaster/auxprocess.h
index 1fdde3bb77b..3e443edde70 100644
--- a/src/include/postmaster/auxprocess.h
+++ b/src/include/postmaster/auxprocess.h
@@ -15,6 +15,6 @@
#include "miscadmin.h"
-extern void AuxiliaryProcessMain(AuxProcType auxtype) pg_attribute_noreturn();
+extern void AuxiliaryProcessMain(BackendType auxtype) pg_attribute_noreturn();
#endif /* AUXPROCESS_H */
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 5fd46b7bd1f..2abe43c57f6 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -172,7 +172,6 @@ AutoVacOpts
AutoVacuumShmemStruct
AutoVacuumWorkItem
AutoVacuumWorkItemType
-AuxProcType
BF_ctx
BF_key
BF_word
--
2.39.2
From 795929a5f5a5d6ea4fa8a46bb15c68d2ff46ad3d Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki.linnakan...@iki.fi>
Date: Wed, 10 Jan 2024 12:59:48 +0200
Subject: [PATCH v6 3/3] Use MyBackendType in more places to check what process
this is
Remove IsBackgroundWorker, IsAutoVacuumLauncherProcess() and
IsAutoVacuumWorkerProcess() in favor of new Am*Process() macros that
use MyBackendType. For consistency with the existing Am*Process()
macros.
Reviewed-by: XXX
Discussion: XXX
---
src/backend/access/gin/ginfast.c | 2 +-
src/backend/access/gin/ginvacuum.c | 6 ++---
src/backend/access/heap/vacuumlazy.c | 4 +--
src/backend/commands/analyze.c | 4 +--
src/backend/commands/vacuum.c | 8 +++---
src/backend/postmaster/autovacuum.c | 26 --------------------
src/backend/postmaster/bgworker.c | 2 --
src/backend/postmaster/postmaster.c | 3 ---
src/backend/statistics/extended_stats.c | 2 +-
src/backend/storage/ipc/ipc.c | 2 +-
src/backend/storage/lmgr/proc.c | 19 +++++++-------
src/backend/tcop/postgres.c | 6 ++---
src/backend/utils/activity/pgstat_relation.c | 4 +--
src/backend/utils/init/globals.c | 1 -
src/backend/utils/init/miscinit.c | 2 +-
src/backend/utils/init/postinit.c | 8 +++---
src/include/miscadmin.h | 8 +++---
src/include/postmaster/autovacuum.h | 5 ----
18 files changed, 38 insertions(+), 74 deletions(-)
diff --git a/src/backend/access/gin/ginfast.c b/src/backend/access/gin/ginfast.c
index cff6850ef86..e118cecb9a4 100644
--- a/src/backend/access/gin/ginfast.c
+++ b/src/backend/access/gin/ginfast.c
@@ -812,7 +812,7 @@ ginInsertCleanup(GinState *ginstate, bool full_clean,
*/
LockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock);
workMemory =
- (IsAutoVacuumWorkerProcess() && autovacuum_work_mem != -1) ?
+ (AmAutoVacuumWorkerProcess() && autovacuum_work_mem != -1) ?
autovacuum_work_mem : maintenance_work_mem;
}
else
diff --git a/src/backend/access/gin/ginvacuum.c b/src/backend/access/gin/ginvacuum.c
index aee6aab44ae..b3f415e2849 100644
--- a/src/backend/access/gin/ginvacuum.c
+++ b/src/backend/access/gin/ginvacuum.c
@@ -590,7 +590,7 @@ ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
/*
* and cleanup any pending inserts
*/
- ginInsertCleanup(&gvs.ginstate, !IsAutoVacuumWorkerProcess(),
+ ginInsertCleanup(&gvs.ginstate, !AmAutoVacuumWorkerProcess(),
false, true, stats);
}
@@ -701,7 +701,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
*/
if (info->analyze_only)
{
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
{
initGinState(&ginstate, index);
ginInsertCleanup(&ginstate, false, true, true, stats);
@@ -717,7 +717,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
{
stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
initGinState(&ginstate, index);
- ginInsertCleanup(&ginstate, !IsAutoVacuumWorkerProcess(),
+ ginInsertCleanup(&ginstate, !AmAutoVacuumWorkerProcess(),
false, true, stats);
}
diff --git a/src/backend/access/heap/vacuumlazy.c b/src/backend/access/heap/vacuumlazy.c
index abbba8947fa..2194d4fced3 100644
--- a/src/backend/access/heap/vacuumlazy.c
+++ b/src/backend/access/heap/vacuumlazy.c
@@ -324,7 +324,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
char **indnames = NULL;
verbose = (params->options & VACOPT_VERBOSE) != 0;
- instrument = (verbose || (IsAutoVacuumWorkerProcess() &&
+ instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
params->log_min_duration >= 0));
if (instrument)
{
@@ -3148,7 +3148,7 @@ static int
dead_items_max_items(LVRelState *vacrel)
{
int64 max_items;
- int vac_work_mem = IsAutoVacuumWorkerProcess() &&
+ int vac_work_mem = AmAutoVacuumWorkerProcess() &&
autovacuum_work_mem != -1 ?
autovacuum_work_mem : maintenance_work_mem;
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index deef865ce6d..655dc09444b 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -351,7 +351,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
save_nestlevel = NewGUCNestLevel();
/* measure elapsed time iff autovacuum logging requires it */
- if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
+ if (AmAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
{
if (track_io_timing)
{
@@ -729,7 +729,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
vac_close_indexes(nindexes, Irel, NoLock);
/* Log the action if appropriate */
- if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
+ if (AmAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
{
TimestampTz endtime = GetCurrentTimestamp();
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 64da8486276..e40cef6566e 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -564,7 +564,7 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
else
{
Assert(params->options & VACOPT_ANALYZE);
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
use_own_xacts = true;
else if (in_outer_xact)
use_own_xacts = false;
@@ -809,7 +809,7 @@ vacuum_open_relation(Oid relid, RangeVar *relation, bits32 options,
* statements in the permission checks; otherwise, only log if the caller
* so requested.
*/
- if (!IsAutoVacuumWorkerProcess())
+ if (!AmAutoVacuumWorkerProcess())
elevel = WARNING;
else if (verbose)
elevel = LOG;
@@ -896,7 +896,7 @@ expand_vacuum_rel(VacuumRelation *vrel, MemoryContext vac_context,
* Since autovacuum workers supply OIDs when calling vacuum(), no
* autovacuum worker should reach this code.
*/
- Assert(!IsAutoVacuumWorkerProcess());
+ Assert(!AmAutoVacuumWorkerProcess());
/*
* We transiently take AccessShareLock to protect the syscache lookup
@@ -2336,7 +2336,7 @@ vacuum_delay_point(void)
* [autovacuum_]vacuum_cost_delay to take effect while a table is being
* vacuumed or analyzed.
*/
- if (ConfigReloadPending && IsAutoVacuumWorkerProcess())
+ if (ConfigReloadPending && AmAutoVacuumWorkerProcess())
{
ConfigReloadPending = false;
ProcessConfigFile(PGC_SIGHUP);
diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c
index 2c3099f76f1..cecbaaa5b91 100644
--- a/src/backend/postmaster/autovacuum.c
+++ b/src/backend/postmaster/autovacuum.c
@@ -135,10 +135,6 @@ int Log_autovacuum_min_duration = 600000;
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
#define MAX_AUTOVAC_SLEEPTIME 300 /* seconds */
-/* Flags to tell if we are in an autovacuum process */
-static bool am_autovacuum_launcher = false;
-static bool am_autovacuum_worker = false;
-
/*
* Variables to save the cost-related storage parameters for the current
* relation being vacuumed by this autovacuum worker. Using these, we can
@@ -435,8 +431,6 @@ AutoVacLauncherMain(int argc, char *argv[])
{
sigjmp_buf local_sigjmp_buf;
- am_autovacuum_launcher = true;
-
MyBackendType = B_AUTOVAC_LAUNCHER;
init_ps_display(NULL);
@@ -1495,8 +1489,6 @@ AutoVacWorkerMain(int argc, char *argv[])
sigjmp_buf local_sigjmp_buf;
Oid dbid;
- am_autovacuum_worker = true;
-
MyBackendType = B_AUTOVAC_WORKER;
init_ps_display(NULL);
@@ -3355,24 +3347,6 @@ autovac_init(void)
errhint("Enable the \"track_counts\" option.")));
}
-/*
- * IsAutoVacuum functions
- * Return whether this is either a launcher autovacuum process or a worker
- * process.
- */
-bool
-IsAutoVacuumLauncherProcess(void)
-{
- return am_autovacuum_launcher;
-}
-
-bool
-IsAutoVacuumWorkerProcess(void)
-{
- return am_autovacuum_worker;
-}
-
-
/*
* AutoVacuumShmemSize
* Compute space needed for autovacuum-related shared memory
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 67f92c24db1..d8e89de7494 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -731,8 +731,6 @@ BackgroundWorkerMain(void)
if (worker == NULL)
elog(FATAL, "unable to find bgworker entry");
- IsBackgroundWorker = true;
-
MyBackendType = B_BG_WORKER;
init_ps_display(worker->bgw_name);
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index c51b6a1376a..8aa2ddf0c46 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -4979,9 +4979,6 @@ SubPostmasterMain(int argc, char *argv[])
}
if (strcmp(argv[1], "--forkbgworker") == 0)
{
- /* do this as early as possible; in particular, before InitProcess() */
- IsBackgroundWorker = true;
-
/* Restore basic shared memory pointers */
InitShmemAccess(UsedShmemSegAddr);
diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c
index c5461514d8f..135151a2723 100644
--- a/src/backend/statistics/extended_stats.c
+++ b/src/backend/statistics/extended_stats.c
@@ -173,7 +173,7 @@ BuildRelationExtStatistics(Relation onerel, bool inh, double totalrows,
natts, vacattrstats);
if (!stats)
{
- if (!IsAutoVacuumWorkerProcess())
+ if (!AmAutoVacuumWorkerProcess())
ereport(WARNING,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("statistics object \"%s.%s\" could not be computed for relation \"%s.%s\"",
diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c
index 2681e4cdff5..b06e4b84528 100644
--- a/src/backend/storage/ipc/ipc.c
+++ b/src/backend/storage/ipc/ipc.c
@@ -136,7 +136,7 @@ proc_exit(int code)
*/
char gprofDirName[32];
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
snprintf(gprofDirName, 32, "gprof/avworker");
else
snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index 4ad96beb87a..b904fab5de5 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -41,7 +41,6 @@
#include "postmaster/autovacuum.h"
#include "replication/slot.h"
#include "replication/syncrep.h"
-#include "replication/walsender.h"
#include "storage/condition_variable.h"
#include "storage/ipc.h"
#include "storage/lmgr.h"
@@ -309,11 +308,11 @@ InitProcess(void)
elog(ERROR, "you already exist");
/* Decide which list should supply our PGPROC. */
- if (IsAnyAutoVacuumProcess())
+ if (AmAutoVacuumLauncherProcess() || AmAutoVacuumWorkerProcess())
procgloballist = &ProcGlobal->autovacFreeProcs;
- else if (IsBackgroundWorker)
+ else if (AmBackgroundWorkerProcess())
procgloballist = &ProcGlobal->bgworkerFreeProcs;
- else if (am_walsender)
+ else if (AmWalSenderProcess())
procgloballist = &ProcGlobal->walsenderFreeProcs;
else
procgloballist = &ProcGlobal->freeProcs;
@@ -343,7 +342,7 @@ InitProcess(void)
* in the autovacuum case?
*/
SpinLockRelease(ProcStructLock);
- if (am_walsender)
+ if (AmWalSenderProcess())
ereport(FATAL,
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
errmsg("number of requested standby connections exceeds max_wal_senders (currently %d)",
@@ -365,7 +364,7 @@ InitProcess(void)
* cleaning up. (XXX autovac launcher currently doesn't participate in
* this; it probably should.)
*/
- if (IsUnderPostmaster && !IsAutoVacuumLauncherProcess())
+ if (IsUnderPostmaster && !AmAutoVacuumLauncherProcess())
MarkPostmasterChildActive();
/*
@@ -385,11 +384,11 @@ InitProcess(void)
MyProc->databaseId = InvalidOid;
MyProc->roleId = InvalidOid;
MyProc->tempNamespaceId = InvalidOid;
- MyProc->isBackgroundWorker = IsBackgroundWorker;
+ MyProc->isBackgroundWorker = AmBackgroundWorkerProcess();
MyProc->delayChkptFlags = 0;
MyProc->statusFlags = 0;
/* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
MyProc->statusFlags |= PROC_IS_AUTOVACUUM;
MyProc->lwWaiting = LW_WS_NOT_WAITING;
MyProc->lwWaitMode = 0;
@@ -580,7 +579,7 @@ InitAuxiliaryProcess(void)
MyProc->databaseId = InvalidOid;
MyProc->roleId = InvalidOid;
MyProc->tempNamespaceId = InvalidOid;
- MyProc->isBackgroundWorker = IsBackgroundWorker;
+ MyProc->isBackgroundWorker = AmBackgroundWorkerProcess();
MyProc->delayChkptFlags = 0;
MyProc->statusFlags = 0;
MyProc->lwWaiting = LW_WS_NOT_WAITING;
@@ -935,7 +934,7 @@ ProcKill(int code, Datum arg)
* way, so tell the postmaster we've cleaned up acceptably well. (XXX
* autovac launcher should be included here someday)
*/
- if (IsUnderPostmaster && !IsAutoVacuumLauncherProcess())
+ if (IsUnderPostmaster && !AmAutoVacuumLauncherProcess())
MarkPostmasterChildInactive();
/* wake autovac launcher if needed -- see comments in FreeWorkerInfo */
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 1eaaf3c6c58..1f74de17edf 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -3267,7 +3267,7 @@ ProcessInterrupts(void)
ereport(FATAL,
(errcode(ERRCODE_QUERY_CANCELED),
errmsg("canceling authentication due to timeout")));
- else if (IsAutoVacuumWorkerProcess())
+ else if (AmAutoVacuumWorkerProcess())
ereport(FATAL,
(errcode(ERRCODE_ADMIN_SHUTDOWN),
errmsg("terminating autovacuum process due to administrator command")));
@@ -3286,7 +3286,7 @@ ProcessInterrupts(void)
*/
proc_exit(1);
}
- else if (IsBackgroundWorker)
+ else if (AmBackgroundWorkerProcess())
ereport(FATAL,
(errcode(ERRCODE_ADMIN_SHUTDOWN),
errmsg("terminating background worker \"%s\" due to administrator command",
@@ -3386,7 +3386,7 @@ ProcessInterrupts(void)
(errcode(ERRCODE_QUERY_CANCELED),
errmsg("canceling statement due to statement timeout")));
}
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
{
LockErrorCleanup();
ereport(ERROR,
diff --git a/src/backend/utils/activity/pgstat_relation.c b/src/backend/utils/activity/pgstat_relation.c
index 111050725a6..b20a60b5a87 100644
--- a/src/backend/utils/activity/pgstat_relation.c
+++ b/src/backend/utils/activity/pgstat_relation.c
@@ -246,7 +246,7 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
*/
tabentry->ins_since_vacuum = 0;
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
{
tabentry->last_autovacuum_time = ts;
tabentry->autovacuum_count++;
@@ -337,7 +337,7 @@ pgstat_report_analyze(Relation rel,
if (resetcounter)
tabentry->mod_since_analyze = 0;
- if (IsAutoVacuumWorkerProcess())
+ if (AmAutoVacuumWorkerProcess())
{
tabentry->last_autoanalyze_time = GetCurrentTimestamp();
tabentry->autoanalyze_count++;
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index 88b03e8fa3c..ce1fa1092f2 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -114,7 +114,6 @@ pid_t PostmasterPid = 0;
bool IsPostmasterEnvironment = false;
bool IsUnderPostmaster = false;
bool IsBinaryUpgrade = false;
-bool IsBackgroundWorker = false;
bool ExitOnAnyError = false;
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 23f77a59e58..9c91e9a1324 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -837,7 +837,7 @@ InitializeSessionUserIdStandalone(void)
* This function should only be called in single-user mode, in autovacuum
* workers, and in background workers.
*/
- Assert(!IsUnderPostmaster || IsAutoVacuumWorkerProcess() || IsBackgroundWorker);
+ Assert(!IsUnderPostmaster || AmAutoVacuumWorkerProcess() || AmBackgroundWorkerProcess());
/* call only once */
Assert(!OidIsValid(AuthenticatedUserId));
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 1ad33671598..8323c02acf2 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -344,7 +344,7 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
*
* We do not enforce them for autovacuum worker processes either.
*/
- if (IsUnderPostmaster && !IsAutoVacuumWorkerProcess())
+ if (IsUnderPostmaster && !AmAutoVacuumWorkerProcess())
{
/*
* Check that the database is currently allowing connections.
@@ -833,7 +833,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
before_shmem_exit(ShutdownPostgres, 0);
/* The autovacuum launcher is done here */
- if (IsAutoVacuumLauncherProcess())
+ if (AmAutoVacuumLauncherProcess())
{
/* report this backend in the PgBackendStatus array */
pgstat_bestart();
@@ -877,7 +877,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
* In standalone mode and in autovacuum worker processes, we use a fixed
* ID, otherwise we figure it out from the authenticated user name.
*/
- if (bootstrap || IsAutoVacuumWorkerProcess())
+ if (bootstrap || AmAutoVacuumWorkerProcess())
{
InitializeSessionUserIdStandalone();
am_superuser = true;
@@ -893,7 +893,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
errhint("You should immediately run CREATE USER \"%s\" SUPERUSER;.",
username != NULL ? username : "postgres")));
}
- else if (IsBackgroundWorker)
+ else if (AmBackgroundWorkerProcess())
{
if (username == NULL && !OidIsValid(useroid))
{
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 70da52a7876..f7d08b1dafd 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -164,7 +164,6 @@ do { \
extern PGDLLIMPORT pid_t PostmasterPid;
extern PGDLLIMPORT bool IsPostmasterEnvironment;
extern PGDLLIMPORT bool IsUnderPostmaster;
-extern PGDLLIMPORT bool IsBackgroundWorker;
extern PGDLLIMPORT bool IsBinaryUpgrade;
extern PGDLLIMPORT bool ExitOnAnyError;
@@ -361,7 +360,12 @@ extern PGDLLIMPORT BackendType MyBackendType;
#define FIRST_AUX_PROC B_ARCHIVER
#define NUM_AUXPROCTYPES (BACKEND_NUM_TYPES - FIRST_AUX_PROC)
+#define IsAuxProcess(type) (MyBackendType >= FIRST_AUX_PROC)
+#define AmAutoVacuumLauncherProcess() (MyBackendType == B_AUTOVAC_LAUNCHER)
+#define AmAutoVacuumWorkerProcess() (MyBackendType == B_AUTOVAC_WORKER)
+#define AmBackgroundWorkerProcess() (MyBackendType == B_BG_WORKER)
+#define AmWalSenderProcess() (MyBackendType == B_WAL_SENDER)
#define AmStartupProcess() (MyBackendType == B_STARTUP)
#define AmBackgroundWriterProcess() (MyBackendType == B_BG_WRITER)
#define AmArchiverProcess() (MyBackendType == B_ARCHIVER)
@@ -370,8 +374,6 @@ extern PGDLLIMPORT BackendType MyBackendType;
#define AmWalReceiverProcess() (MyBackendType == B_WAL_RECEIVER)
#define AmWalSummarizerProcess() (MyBackendType == B_WAL_SUMMARIZER)
-#define IsAuxProcess(type) (MyBackendType >= FIRST_AUX_PROC)
-
extern const char *GetBackendTypeDesc(BackendType backendType);
extern void SetDatabasePath(const char *path);
diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h
index 1994aedef03..80cf4cdd969 100644
--- a/src/include/postmaster/autovacuum.h
+++ b/src/include/postmaster/autovacuum.h
@@ -49,11 +49,6 @@ extern PGDLLIMPORT int Log_autovacuum_min_duration;
/* Status inquiry functions */
extern bool AutoVacuumingActive(void);
-extern bool IsAutoVacuumLauncherProcess(void);
-extern bool IsAutoVacuumWorkerProcess(void);
-
-#define IsAnyAutoVacuumProcess() \
- (IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess())
/* Functions to start autovacuum process, called from postmaster */
extern void autovac_init(void);
--
2.39.2