Use MyBackendType in more places to check what process this is

Remove IsBackgroundWorker, IsAutoVacuumLauncherProcess(),
IsAutoVacuumWorkerProcess(), and IsLogicalSlotSyncWorker() in favor of
new Am*Process() macros that use MyBackendType. For consistency with
the existing Am*Process() macros.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/f3ecd4cb-85ee-4e54-8278-5fabfb3a4ed0@iki.fi
This commit is contained in:
Heikki Linnakangas 2024-03-04 10:25:12 +02:00
parent 067701f577
commit 393b5599e5
20 changed files with 42 additions and 91 deletions

View File

@ -812,7 +812,7 @@ ginInsertCleanup(GinState *ginstate, bool full_clean,
*/ */
LockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock); LockPage(index, GIN_METAPAGE_BLKNO, ExclusiveLock);
workMemory = workMemory =
(IsAutoVacuumWorkerProcess() && autovacuum_work_mem != -1) ? (AmAutoVacuumWorkerProcess() && autovacuum_work_mem != -1) ?
autovacuum_work_mem : maintenance_work_mem; autovacuum_work_mem : maintenance_work_mem;
} }
else else

View File

@ -590,7 +590,7 @@ ginbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
/* /*
* and cleanup any pending inserts * and cleanup any pending inserts
*/ */
ginInsertCleanup(&gvs.ginstate, !IsAutoVacuumWorkerProcess(), ginInsertCleanup(&gvs.ginstate, !AmAutoVacuumWorkerProcess(),
false, true, stats); false, true, stats);
} }
@ -701,7 +701,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
*/ */
if (info->analyze_only) if (info->analyze_only)
{ {
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
{ {
initGinState(&ginstate, index); initGinState(&ginstate, index);
ginInsertCleanup(&ginstate, false, true, true, stats); ginInsertCleanup(&ginstate, false, true, true, stats);
@ -717,7 +717,7 @@ ginvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
{ {
stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult)); stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
initGinState(&ginstate, index); initGinState(&ginstate, index);
ginInsertCleanup(&ginstate, !IsAutoVacuumWorkerProcess(), ginInsertCleanup(&ginstate, !AmAutoVacuumWorkerProcess(),
false, true, stats); false, true, stats);
} }

View File

@ -307,7 +307,7 @@ heap_vacuum_rel(Relation rel, VacuumParams *params,
char **indnames = NULL; char **indnames = NULL;
verbose = (params->options & VACOPT_VERBOSE) != 0; verbose = (params->options & VACOPT_VERBOSE) != 0;
instrument = (verbose || (IsAutoVacuumWorkerProcess() && instrument = (verbose || (AmAutoVacuumWorkerProcess() &&
params->log_min_duration >= 0)); params->log_min_duration >= 0));
if (instrument) if (instrument)
{ {
@ -3087,7 +3087,7 @@ static int
dead_items_max_items(LVRelState *vacrel) dead_items_max_items(LVRelState *vacrel)
{ {
int64 max_items; int64 max_items;
int vac_work_mem = IsAutoVacuumWorkerProcess() && int vac_work_mem = AmAutoVacuumWorkerProcess() &&
autovacuum_work_mem != -1 ? autovacuum_work_mem != -1 ?
autovacuum_work_mem : maintenance_work_mem; autovacuum_work_mem : maintenance_work_mem;

View File

@ -351,7 +351,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
save_nestlevel = NewGUCNestLevel(); save_nestlevel = NewGUCNestLevel();
/* measure elapsed time iff autovacuum logging requires it */ /* 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) if (track_io_timing)
{ {
@ -729,7 +729,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
vac_close_indexes(nindexes, Irel, NoLock); vac_close_indexes(nindexes, Irel, NoLock);
/* Log the action if appropriate */ /* Log the action if appropriate */
if (IsAutoVacuumWorkerProcess() && params->log_min_duration >= 0) if (AmAutoVacuumWorkerProcess() && params->log_min_duration >= 0)
{ {
TimestampTz endtime = GetCurrentTimestamp(); TimestampTz endtime = GetCurrentTimestamp();

View File

@ -564,7 +564,7 @@ vacuum(List *relations, VacuumParams *params, BufferAccessStrategy bstrategy,
else else
{ {
Assert(params->options & VACOPT_ANALYZE); Assert(params->options & VACOPT_ANALYZE);
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
use_own_xacts = true; use_own_xacts = true;
else if (in_outer_xact) else if (in_outer_xact)
use_own_xacts = false; 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 * statements in the permission checks; otherwise, only log if the caller
* so requested. * so requested.
*/ */
if (!IsAutoVacuumWorkerProcess()) if (!AmAutoVacuumWorkerProcess())
elevel = WARNING; elevel = WARNING;
else if (verbose) else if (verbose)
elevel = LOG; elevel = LOG;
@ -896,7 +896,7 @@ expand_vacuum_rel(VacuumRelation *vrel, MemoryContext vac_context,
* Since autovacuum workers supply OIDs when calling vacuum(), no * Since autovacuum workers supply OIDs when calling vacuum(), no
* autovacuum worker should reach this code. * autovacuum worker should reach this code.
*/ */
Assert(!IsAutoVacuumWorkerProcess()); Assert(!AmAutoVacuumWorkerProcess());
/* /*
* We transiently take AccessShareLock to protect the syscache lookup * 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 * [autovacuum_]vacuum_cost_delay to take effect while a table is being
* vacuumed or analyzed. * vacuumed or analyzed.
*/ */
if (ConfigReloadPending && IsAutoVacuumWorkerProcess()) if (ConfigReloadPending && AmAutoVacuumWorkerProcess())
{ {
ConfigReloadPending = false; ConfigReloadPending = false;
ProcessConfigFile(PGC_SIGHUP); ProcessConfigFile(PGC_SIGHUP);

View File

@ -136,10 +136,6 @@ int Log_autovacuum_min_duration = 600000;
#define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */ #define MIN_AUTOVAC_SLEEPTIME 100.0 /* milliseconds */
#define MAX_AUTOVAC_SLEEPTIME 300 /* seconds */ #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 * Variables to save the cost-related storage parameters for the current
* relation being vacuumed by this autovacuum worker. Using these, we can * relation being vacuumed by this autovacuum worker. Using these, we can
@ -436,8 +432,6 @@ AutoVacLauncherMain(int argc, char *argv[])
{ {
sigjmp_buf local_sigjmp_buf; sigjmp_buf local_sigjmp_buf;
am_autovacuum_launcher = true;
MyBackendType = B_AUTOVAC_LAUNCHER; MyBackendType = B_AUTOVAC_LAUNCHER;
init_ps_display(NULL); init_ps_display(NULL);
@ -1491,8 +1485,6 @@ AutoVacWorkerMain(int argc, char *argv[])
sigjmp_buf local_sigjmp_buf; sigjmp_buf local_sigjmp_buf;
Oid dbid; Oid dbid;
am_autovacuum_worker = true;
MyBackendType = B_AUTOVAC_WORKER; MyBackendType = B_AUTOVAC_WORKER;
init_ps_display(NULL); init_ps_display(NULL);
@ -3352,24 +3344,6 @@ autovac_init(void)
errhint("Enable the \"track_counts\" option."))); 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 * AutoVacuumShmemSize
* Compute space needed for autovacuum-related shared memory * Compute space needed for autovacuum-related shared memory

View File

@ -731,8 +731,6 @@ BackgroundWorkerMain(void)
if (worker == NULL) if (worker == NULL)
elog(FATAL, "unable to find bgworker entry"); elog(FATAL, "unable to find bgworker entry");
IsBackgroundWorker = true;
MyBackendType = B_BG_WORKER; MyBackendType = B_BG_WORKER;
init_ps_display(worker->bgw_name); init_ps_display(worker->bgw_name);

View File

@ -5000,9 +5000,6 @@ SubPostmasterMain(int argc, char *argv[])
} }
if (strcmp(argv[1], "--forkbgworker") == 0) if (strcmp(argv[1], "--forkbgworker") == 0)
{ {
/* do this as early as possible; in particular, before InitProcess() */
IsBackgroundWorker = true;
/* Restore basic shared memory pointers */ /* Restore basic shared memory pointers */
InitShmemAccess(UsedShmemSegAddr); InitShmemAccess(UsedShmemSegAddr);

View File

@ -113,9 +113,6 @@ static long sleep_ms = MIN_SLOTSYNC_WORKER_NAPTIME_MS;
/* The restart interval for slot sync work used by postmaster */ /* The restart interval for slot sync work used by postmaster */
#define SLOTSYNC_RESTART_INTERVAL_SEC 10 #define SLOTSYNC_RESTART_INTERVAL_SEC 10
/* Flag to tell if we are in a slot sync worker process */
static bool am_slotsync_worker = false;
/* /*
* Flag to tell if we are syncing replication slots. Unlike the 'syncing' flag * Flag to tell if we are syncing replication slots. Unlike the 'syncing' flag
* in SlotSyncCtxStruct, this flag is true only if the current process is * in SlotSyncCtxStruct, this flag is true only if the current process is
@ -491,7 +488,7 @@ synchronize_one_slot(RemoteSlot *remote_slot, Oid remote_dbid)
latestFlushPtr = GetStandbyFlushRecPtr(NULL); latestFlushPtr = GetStandbyFlushRecPtr(NULL);
if (remote_slot->confirmed_lsn > latestFlushPtr) if (remote_slot->confirmed_lsn > latestFlushPtr)
{ {
ereport(am_slotsync_worker ? LOG : ERROR, ereport(AmLogicalSlotSyncWorkerProcess() ? LOG : ERROR,
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("skipping slot synchronization as the received slot sync" errmsg("skipping slot synchronization as the received slot sync"
" LSN %X/%X for slot \"%s\" is ahead of the standby position %X/%X", " LSN %X/%X for slot \"%s\" is ahead of the standby position %X/%X",
@ -1114,8 +1111,6 @@ ReplSlotSyncWorkerMain(int argc, char *argv[])
sigjmp_buf local_sigjmp_buf; sigjmp_buf local_sigjmp_buf;
StringInfoData app_name; StringInfoData app_name;
am_slotsync_worker = true;
MyBackendType = B_SLOTSYNC_WORKER; MyBackendType = B_SLOTSYNC_WORKER;
init_ps_display(NULL); init_ps_display(NULL);
@ -1438,15 +1433,6 @@ IsSyncingReplicationSlots(void)
return syncing_slots; return syncing_slots;
} }
/*
* Is current process a slot sync worker?
*/
bool
IsLogicalSlotSyncWorker(void)
{
return am_slotsync_worker;
}
/* /*
* Amount of shared memory required for slot synchronization. * Amount of shared memory required for slot synchronization.
*/ */

View File

@ -173,7 +173,7 @@ BuildRelationExtStatistics(Relation onerel, bool inh, double totalrows,
natts, vacattrstats); natts, vacattrstats);
if (!stats) if (!stats)
{ {
if (!IsAutoVacuumWorkerProcess()) if (!AmAutoVacuumWorkerProcess())
ereport(WARNING, ereport(WARNING,
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION), (errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
errmsg("statistics object \"%s.%s\" could not be computed for relation \"%s.%s\"", errmsg("statistics object \"%s.%s\" could not be computed for relation \"%s.%s\"",

View File

@ -136,7 +136,7 @@ proc_exit(int code)
*/ */
char gprofDirName[32]; char gprofDirName[32];
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
snprintf(gprofDirName, 32, "gprof/avworker"); snprintf(gprofDirName, 32, "gprof/avworker");
else else
snprintf(gprofDirName, 32, "gprof/%d", (int) getpid()); snprintf(gprofDirName, 32, "gprof/%d", (int) getpid());

View File

@ -42,7 +42,6 @@
#include "replication/slot.h" #include "replication/slot.h"
#include "replication/slotsync.h" #include "replication/slotsync.h"
#include "replication/syncrep.h" #include "replication/syncrep.h"
#include "replication/walsender.h"
#include "storage/condition_variable.h" #include "storage/condition_variable.h"
#include "storage/ipc.h" #include "storage/ipc.h"
#include "storage/lmgr.h" #include "storage/lmgr.h"
@ -310,11 +309,11 @@ InitProcess(void)
elog(ERROR, "you already exist"); elog(ERROR, "you already exist");
/* Decide which list should supply our PGPROC. */ /* Decide which list should supply our PGPROC. */
if (IsAnyAutoVacuumProcess()) if (AmAutoVacuumLauncherProcess() || AmAutoVacuumWorkerProcess())
procgloballist = &ProcGlobal->autovacFreeProcs; procgloballist = &ProcGlobal->autovacFreeProcs;
else if (IsBackgroundWorker) else if (AmBackgroundWorkerProcess())
procgloballist = &ProcGlobal->bgworkerFreeProcs; procgloballist = &ProcGlobal->bgworkerFreeProcs;
else if (am_walsender) else if (AmWalSenderProcess())
procgloballist = &ProcGlobal->walsenderFreeProcs; procgloballist = &ProcGlobal->walsenderFreeProcs;
else else
procgloballist = &ProcGlobal->freeProcs; procgloballist = &ProcGlobal->freeProcs;
@ -344,7 +343,7 @@ InitProcess(void)
* in the autovacuum case? * in the autovacuum case?
*/ */
SpinLockRelease(ProcStructLock); SpinLockRelease(ProcStructLock);
if (am_walsender) if (AmWalSenderProcess())
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_TOO_MANY_CONNECTIONS), (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
errmsg("number of requested standby connections exceeds max_wal_senders (currently %d)", errmsg("number of requested standby connections exceeds max_wal_senders (currently %d)",
@ -370,8 +369,8 @@ InitProcess(void)
* Slot sync worker also does not participate in it, see comments atop * Slot sync worker also does not participate in it, see comments atop
* 'struct bkend' in postmaster.c. * 'struct bkend' in postmaster.c.
*/ */
if (IsUnderPostmaster && !IsAutoVacuumLauncherProcess() && if (IsUnderPostmaster && !AmAutoVacuumLauncherProcess() &&
!IsLogicalSlotSyncWorker()) !AmLogicalSlotSyncWorkerProcess())
MarkPostmasterChildActive(); MarkPostmasterChildActive();
/* /*
@ -391,11 +390,11 @@ InitProcess(void)
MyProc->databaseId = InvalidOid; MyProc->databaseId = InvalidOid;
MyProc->roleId = InvalidOid; MyProc->roleId = InvalidOid;
MyProc->tempNamespaceId = InvalidOid; MyProc->tempNamespaceId = InvalidOid;
MyProc->isBackgroundWorker = IsBackgroundWorker; MyProc->isBackgroundWorker = AmBackgroundWorkerProcess();
MyProc->delayChkptFlags = 0; MyProc->delayChkptFlags = 0;
MyProc->statusFlags = 0; MyProc->statusFlags = 0;
/* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */ /* NB -- autovac launcher intentionally does not set IS_AUTOVACUUM */
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
MyProc->statusFlags |= PROC_IS_AUTOVACUUM; MyProc->statusFlags |= PROC_IS_AUTOVACUUM;
MyProc->lwWaiting = LW_WS_NOT_WAITING; MyProc->lwWaiting = LW_WS_NOT_WAITING;
MyProc->lwWaitMode = 0; MyProc->lwWaitMode = 0;
@ -587,7 +586,7 @@ InitAuxiliaryProcess(void)
MyProc->databaseId = InvalidOid; MyProc->databaseId = InvalidOid;
MyProc->roleId = InvalidOid; MyProc->roleId = InvalidOid;
MyProc->tempNamespaceId = InvalidOid; MyProc->tempNamespaceId = InvalidOid;
MyProc->isBackgroundWorker = IsBackgroundWorker; MyProc->isBackgroundWorker = AmBackgroundWorkerProcess();
MyProc->delayChkptFlags = 0; MyProc->delayChkptFlags = 0;
MyProc->statusFlags = 0; MyProc->statusFlags = 0;
MyProc->lwWaiting = LW_WS_NOT_WAITING; MyProc->lwWaiting = LW_WS_NOT_WAITING;
@ -951,8 +950,8 @@ ProcKill(int code, Datum arg)
* Slot sync worker is also not a postmaster child, so skip this shared * Slot sync worker is also not a postmaster child, so skip this shared
* memory related processing here. * memory related processing here.
*/ */
if (IsUnderPostmaster && !IsAutoVacuumLauncherProcess() && if (IsUnderPostmaster && !AmAutoVacuumLauncherProcess() &&
!IsLogicalSlotSyncWorker()) !AmLogicalSlotSyncWorkerProcess())
MarkPostmasterChildInactive(); MarkPostmasterChildInactive();
/* wake autovac launcher if needed -- see comments in FreeWorkerInfo */ /* wake autovac launcher if needed -- see comments in FreeWorkerInfo */

View File

@ -3259,7 +3259,7 @@ ProcessInterrupts(void)
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_QUERY_CANCELED), (errcode(ERRCODE_QUERY_CANCELED),
errmsg("canceling authentication due to timeout"))); errmsg("canceling authentication due to timeout")));
else if (IsAutoVacuumWorkerProcess()) else if (AmAutoVacuumWorkerProcess())
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_ADMIN_SHUTDOWN), (errcode(ERRCODE_ADMIN_SHUTDOWN),
errmsg("terminating autovacuum process due to administrator command"))); errmsg("terminating autovacuum process due to administrator command")));
@ -3278,7 +3278,7 @@ ProcessInterrupts(void)
*/ */
proc_exit(1); proc_exit(1);
} }
else if (IsBackgroundWorker) else if (AmBackgroundWorkerProcess())
ereport(FATAL, ereport(FATAL,
(errcode(ERRCODE_ADMIN_SHUTDOWN), (errcode(ERRCODE_ADMIN_SHUTDOWN),
errmsg("terminating background worker \"%s\" due to administrator command", errmsg("terminating background worker \"%s\" due to administrator command",
@ -3378,7 +3378,7 @@ ProcessInterrupts(void)
(errcode(ERRCODE_QUERY_CANCELED), (errcode(ERRCODE_QUERY_CANCELED),
errmsg("canceling statement due to statement timeout"))); errmsg("canceling statement due to statement timeout")));
} }
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
{ {
LockErrorCleanup(); LockErrorCleanup();
ereport(ERROR, ereport(ERROR,

View File

@ -246,7 +246,7 @@ pgstat_report_vacuum(Oid tableoid, bool shared,
*/ */
tabentry->ins_since_vacuum = 0; tabentry->ins_since_vacuum = 0;
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
{ {
tabentry->last_autovacuum_time = ts; tabentry->last_autovacuum_time = ts;
tabentry->autovacuum_count++; tabentry->autovacuum_count++;
@ -337,7 +337,7 @@ pgstat_report_analyze(Relation rel,
if (resetcounter) if (resetcounter)
tabentry->mod_since_analyze = 0; tabentry->mod_since_analyze = 0;
if (IsAutoVacuumWorkerProcess()) if (AmAutoVacuumWorkerProcess())
{ {
tabentry->last_autoanalyze_time = GetCurrentTimestamp(); tabentry->last_autoanalyze_time = GetCurrentTimestamp();
tabentry->autoanalyze_count++; tabentry->autoanalyze_count++;

View File

@ -115,7 +115,6 @@ pid_t PostmasterPid = 0;
bool IsPostmasterEnvironment = false; bool IsPostmasterEnvironment = false;
bool IsUnderPostmaster = false; bool IsUnderPostmaster = false;
bool IsBinaryUpgrade = false; bool IsBinaryUpgrade = false;
bool IsBackgroundWorker = false;
bool ExitOnAnyError = false; bool ExitOnAnyError = false;

View File

@ -841,8 +841,8 @@ InitializeSessionUserIdStandalone(void)
* This function should only be called in single-user mode, in autovacuum * This function should only be called in single-user mode, in autovacuum
* workers, in slot sync worker and in background workers. * workers, in slot sync worker and in background workers.
*/ */
Assert(!IsUnderPostmaster || IsAutoVacuumWorkerProcess() || Assert(!IsUnderPostmaster || AmAutoVacuumWorkerProcess() ||
IsLogicalSlotSyncWorker() || IsBackgroundWorker); AmLogicalSlotSyncWorkerProcess() || AmBackgroundWorkerProcess());
/* call only once */ /* call only once */
Assert(!OidIsValid(AuthenticatedUserId)); Assert(!OidIsValid(AuthenticatedUserId));

View File

@ -346,7 +346,7 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
* *
* We do not enforce them for autovacuum worker processes either. * We do not enforce them for autovacuum worker processes either.
*/ */
if (IsUnderPostmaster && !IsAutoVacuumWorkerProcess()) if (IsUnderPostmaster && !AmAutoVacuumWorkerProcess())
{ {
/* /*
* Check that the database is currently allowing connections. * Check that the database is currently allowing connections.
@ -828,7 +828,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
before_shmem_exit(ShutdownPostgres, 0); before_shmem_exit(ShutdownPostgres, 0);
/* The autovacuum launcher is done here */ /* The autovacuum launcher is done here */
if (IsAutoVacuumLauncherProcess()) if (AmAutoVacuumLauncherProcess())
{ {
/* report this backend in the PgBackendStatus array */ /* report this backend in the PgBackendStatus array */
pgstat_bestart(); pgstat_bestart();
@ -873,7 +873,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
* process, we use a fixed ID, otherwise we figure it out from the * process, we use a fixed ID, otherwise we figure it out from the
* authenticated user name. * authenticated user name.
*/ */
if (bootstrap || IsAutoVacuumWorkerProcess() || IsLogicalSlotSyncWorker()) if (bootstrap || AmAutoVacuumWorkerProcess() || AmLogicalSlotSyncWorkerProcess())
{ {
InitializeSessionUserIdStandalone(); InitializeSessionUserIdStandalone();
am_superuser = true; am_superuser = true;
@ -889,7 +889,7 @@ InitPostgres(const char *in_dbname, Oid dboid,
errhint("You should immediately run CREATE USER \"%s\" SUPERUSER;.", errhint("You should immediately run CREATE USER \"%s\" SUPERUSER;.",
username != NULL ? username : "postgres"))); username != NULL ? username : "postgres")));
} }
else if (IsBackgroundWorker) else if (AmBackgroundWorkerProcess())
{ {
if (username == NULL && !OidIsValid(useroid)) if (username == NULL && !OidIsValid(useroid))
{ {

View File

@ -165,7 +165,6 @@ do { \
extern PGDLLIMPORT pid_t PostmasterPid; extern PGDLLIMPORT pid_t PostmasterPid;
extern PGDLLIMPORT bool IsPostmasterEnvironment; extern PGDLLIMPORT bool IsPostmasterEnvironment;
extern PGDLLIMPORT bool IsUnderPostmaster; extern PGDLLIMPORT bool IsUnderPostmaster;
extern PGDLLIMPORT bool IsBackgroundWorker;
extern PGDLLIMPORT bool IsBinaryUpgrade; extern PGDLLIMPORT bool IsBinaryUpgrade;
extern PGDLLIMPORT bool ExitOnAnyError; extern PGDLLIMPORT bool ExitOnAnyError;
@ -369,6 +368,11 @@ typedef enum BackendType
extern PGDLLIMPORT BackendType MyBackendType; extern PGDLLIMPORT BackendType MyBackendType;
#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 AmLogicalSlotSyncWorkerProcess() (MyBackendType == B_SLOTSYNC_WORKER)
#define AmArchiverProcess() (MyBackendType == B_ARCHIVER) #define AmArchiverProcess() (MyBackendType == B_ARCHIVER)
#define AmBackgroundWriterProcess() (MyBackendType == B_BG_WRITER) #define AmBackgroundWriterProcess() (MyBackendType == B_BG_WRITER)
#define AmCheckpointerProcess() (MyBackendType == B_CHECKPOINTER) #define AmCheckpointerProcess() (MyBackendType == B_CHECKPOINTER)

View File

@ -49,11 +49,6 @@ extern PGDLLIMPORT int Log_autovacuum_min_duration;
/* Status inquiry functions */ /* Status inquiry functions */
extern bool AutoVacuumingActive(void); extern bool AutoVacuumingActive(void);
extern bool IsAutoVacuumLauncherProcess(void);
extern bool IsAutoVacuumWorkerProcess(void);
#define IsAnyAutoVacuumProcess() \
(IsAutoVacuumLauncherProcess() || IsAutoVacuumWorkerProcess())
/* Functions to start autovacuum process, called from postmaster */ /* Functions to start autovacuum process, called from postmaster */
extern void autovac_init(void); extern void autovac_init(void);

View File

@ -34,7 +34,6 @@ extern int StartSlotSyncWorker(void);
extern void ShutDownSlotSync(void); extern void ShutDownSlotSync(void);
extern bool SlotSyncWorkerCanRestart(void); extern bool SlotSyncWorkerCanRestart(void);
extern bool IsSyncingReplicationSlots(void); extern bool IsSyncingReplicationSlots(void);
extern bool IsLogicalSlotSyncWorker(void);
extern Size SlotSyncShmemSize(void); extern Size SlotSyncShmemSize(void);
extern void SlotSyncShmemInit(void); extern void SlotSyncShmemInit(void);
extern void SyncReplicationSlots(WalReceiverConn *wrconn); extern void SyncReplicationSlots(WalReceiverConn *wrconn);