PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/parallel.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
#include "postmaster/bgworker_internals.h"
#include "postmaster/postmaster.h"
#include "replication/logicallauncher.h"
#include "replication/logicalworker.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/lwlock.h"
#include "storage/pmsignal.h"
#include "storage/proc.h"
#include "storage/procsignal.h"
#include "storage/shmem.h"
#include "tcop/tcopprot.h"
#include "utils/ascii.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/timeout.h"
Go to the source code of this file.
Data Structures | |
struct | BackgroundWorkerSlot |
struct | BackgroundWorkerArray |
struct | BackgroundWorkerHandle |
Typedefs | |
typedef struct BackgroundWorkerSlot | BackgroundWorkerSlot |
typedef struct BackgroundWorkerArray | BackgroundWorkerArray |
Variables | |
dlist_head | BackgroundWorkerList = DLIST_STATIC_INIT(BackgroundWorkerList) |
static BackgroundWorkerArray * | BackgroundWorkerData |
struct { | |
const char * fn_name | |
bgworker_main_type fn_addr | |
} | InternalBGWorkers [] |
typedef struct BackgroundWorkerArray BackgroundWorkerArray |
typedef struct BackgroundWorkerSlot BackgroundWorkerSlot |
void BackgroundWorkerBlockSignals | ( | void | ) |
void BackgroundWorkerInitializeConnection | ( | const char * | dbname, |
const char * | username, | ||
uint32 | flags | ||
) |
Definition at line 852 of file bgworker.c.
References BackgroundWorker::bgw_flags, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_BYPASS_ALLOWCONN, BGWORKER_BYPASS_ROLELOGINCHECK, dbname, ereport, errcode(), errmsg(), ERROR, FATAL, INIT_PG_OVERRIDE_ALLOW_CONNS, INIT_PG_OVERRIDE_ROLE_LOGIN, InitPostgres(), InvalidOid, IsInitProcessingMode, MyBgworkerEntry, NormalProcessing, SetProcessingMode, and username.
Referenced by ApplyLauncherMain(), and worker_spi_main().
Definition at line 886 of file bgworker.c.
References BackgroundWorker::bgw_flags, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_BYPASS_ALLOWCONN, BGWORKER_BYPASS_ROLELOGINCHECK, ereport, errcode(), errmsg(), ERROR, FATAL, INIT_PG_OVERRIDE_ALLOW_CONNS, INIT_PG_OVERRIDE_ROLE_LOGIN, InitPostgres(), IsInitProcessingMode, MyBgworkerEntry, NormalProcessing, and SetProcessingMode.
Referenced by autoprewarm_database_main(), InitializeLogRepWorker(), ParallelWorkerMain(), and worker_spi_main().
void BackgroundWorkerMain | ( | char * | startup_data, |
size_t | startup_data_len | ||
) |
Definition at line 717 of file bgworker.c.
References Assert, B_BG_WORKER, BackgroundWorkerUnblockSignals(), BaseInit(), BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BackgroundWorker::bgw_name, BGWORKER_BACKEND_DATABASE_CONNECTION, bgworker_die(), elog, EmitErrorReport(), error_context_stack, FATAL, FloatExceptionHandler(), GetProcessingMode, HOLD_INTERRUPTS, init_ps_display(), InitializeTimeouts(), InitProcess(), InitProcessing, LookupBackgroundWorkerFunction(), MemoryContextAlloc(), MemoryContextDelete(), MyBackendType, MyBgworkerEntry, PG_exception_stack, pg_usleep(), PostAuthDelay, PostmasterContext, pqsignal(), proc_exit(), procsignal_sigusr1_handler(), SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SIGPIPE, SIGUSR1, SIGUSR2, StatementCancelHandler(), and TopMemoryContext.
void BackgroundWorkerShmemInit | ( | void | ) |
Definition at line 162 of file bgworker.c.
References Assert, BackgroundWorkerData, BackgroundWorkerList, BackgroundWorkerShmemSize(), BackgroundWorker::bgw_notify_pid, dlist_iter::cur, dlist_container, dlist_foreach, BackgroundWorkerSlot::generation, BackgroundWorkerSlot::in_use, InvalidPid, IsUnderPostmaster, max_worker_processes, BackgroundWorkerArray::parallel_register_count, BackgroundWorkerArray::parallel_terminate_count, BackgroundWorkerSlot::pid, RegisteredBgWorker::rw_shmem_slot, RegisteredBgWorker::rw_worker, ShmemInitStruct(), BackgroundWorkerArray::slot, BackgroundWorkerSlot::terminate, BackgroundWorkerArray::total_slots, and BackgroundWorkerSlot::worker.
Referenced by CreateOrAttachShmemStructs().
Size BackgroundWorkerShmemSize | ( | void | ) |
Definition at line 146 of file bgworker.c.
References add_size(), max_worker_processes, mul_size(), and size.
Referenced by BackgroundWorkerShmemInit(), and CalculateShmemSize().
void BackgroundWorkerStateChange | ( | bool | allow_new_workers | ) |
Definition at line 246 of file bgworker.c.
References ascii_safe_strlcpy(), BackgroundWorkerData, BackgroundWorkerList, BackgroundWorker::bgw_extra, BGW_EXTRALEN, BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_main_arg, BGW_MAXLEN, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWORKER_CLASS_PARALLEL, DEBUG1, dlist_push_head(), elog, ereport, errcode(), errmsg(), errmsg_internal(), FindRegisteredWorkerBySlotNumber(), BackgroundWorkerSlot::in_use, kill, LOG, max_worker_processes, MAXPGPATH, MCXT_ALLOC_NO_OOM, MCXT_ALLOC_ZERO, MemoryContextAllocExtended(), BackgroundWorkerArray::parallel_terminate_count, pg_memory_barrier, pg_read_barrier, BackgroundWorkerSlot::pid, PostmasterContext, PostmasterMarkPIDForWorkerNotify(), ReportBackgroundWorkerPID(), RegisteredBgWorker::rw_crashed_at, RegisteredBgWorker::rw_lnode, RegisteredBgWorker::rw_pid, RegisteredBgWorker::rw_shmem_slot, RegisteredBgWorker::rw_terminate, RegisteredBgWorker::rw_worker, SIGUSR1, BackgroundWorkerArray::slot, BackgroundWorkerSlot::terminate, BackgroundWorkerArray::total_slots, and BackgroundWorkerSlot::worker.
Referenced by process_pm_pmsignal().
void BackgroundWorkerStopNotifications | ( | pid_t | pid | ) |
Definition at line 514 of file bgworker.c.
References BackgroundWorkerList, BackgroundWorker::bgw_notify_pid, dlist_iter::cur, dlist_container, dlist_foreach, and RegisteredBgWorker::rw_worker.
Referenced by CleanupBackend().
void BackgroundWorkerUnblockSignals | ( | void | ) |
Definition at line 926 of file bgworker.c.
References UnBlockSig.
Referenced by ApplyLauncherMain(), autoprewarm_database_main(), autoprewarm_main(), BackgroundWorkerMain(), ParallelApplyWorkerMain(), ParallelWorkerMain(), SetupApplyOrSyncWorker(), test_shm_mq_main(), and worker_spi_main().
|
static |
Definition at line 703 of file bgworker.c.
References BackgroundWorker::bgw_type, BlockSig, ereport, errcode(), errmsg(), FATAL, and MyBgworkerEntry.
Referenced by BackgroundWorkerMain().
|
static |
Definition at line 221 of file bgworker.c.
References BackgroundWorkerList, dlist_iter::cur, dlist_container, dlist_foreach, and RegisteredBgWorker::rw_shmem_slot.
Referenced by BackgroundWorkerStateChange().
void ForgetBackgroundWorker | ( | RegisteredBgWorker * | rw | ) |
Definition at line 429 of file bgworker.c.
References Assert, BackgroundWorkerData, BackgroundWorker::bgw_flags, BackgroundWorker::bgw_name, BGWORKER_CLASS_PARALLEL, DEBUG1, dlist_delete(), ereport, errmsg_internal(), BackgroundWorkerSlot::in_use, max_worker_processes, BackgroundWorkerArray::parallel_terminate_count, pfree(), pg_memory_barrier, RegisteredBgWorker::rw_lnode, RegisteredBgWorker::rw_shmem_slot, RegisteredBgWorker::rw_worker, and BackgroundWorkerArray::slot.
Referenced by DetermineSleepTime(), ForgetUnstartedBackgroundWorkers(), maybe_start_bgworkers(), ReportBackgroundWorkerExit(), and ResetBackgroundWorkerCrashTimes().
void ForgetUnstartedBackgroundWorkers | ( | void | ) |
Definition at line 541 of file bgworker.c.
References Assert, BackgroundWorkerData, BackgroundWorkerList, BackgroundWorker::bgw_notify_pid, dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, ForgetBackgroundWorker(), InvalidPid, kill, max_worker_processes, BackgroundWorkerSlot::pid, RegisteredBgWorker::rw_shmem_slot, RegisteredBgWorker::rw_worker, SIGUSR1, and BackgroundWorkerArray::slot.
Referenced by PostmasterStateMachine().
BgwHandleStatus GetBackgroundWorkerPid | ( | BackgroundWorkerHandle * | handle, |
pid_t * | pidp | ||
) |
Definition at line 1157 of file bgworker.c.
References Assert, BackgroundWorkerData, BGWH_NOT_YET_STARTED, BGWH_STARTED, BGWH_STOPPED, BackgroundWorkerSlot::generation, BackgroundWorkerHandle::generation, BackgroundWorkerSlot::in_use, InvalidPid, LW_SHARED, LWLockAcquire(), LWLockRelease(), max_worker_processes, BackgroundWorkerSlot::pid, BackgroundWorkerArray::slot, and BackgroundWorkerHandle::slot.
Referenced by check_worker_status(), shm_mq_counterparty_gone(), shm_mq_wait_internal(), WaitForBackgroundWorkerShutdown(), WaitForBackgroundWorkerStartup(), WaitForParallelWorkersToAttach(), WaitForParallelWorkersToFinish(), and WaitForReplicationWorkerAttach().
const char* GetBackgroundWorkerTypeByPid | ( | pid_t | pid | ) |
Definition at line 1371 of file bgworker.c.
References BackgroundWorkerData, BGW_MAXLEN, BackgroundWorker::bgw_type, LW_SHARED, LWLockAcquire(), LWLockRelease(), BackgroundWorkerSlot::pid, BackgroundWorkerArray::slot, BackgroundWorkerArray::total_slots, and BackgroundWorkerSlot::worker.
Referenced by pg_stat_get_activity().
|
static |
Definition at line 1337 of file bgworker.c.
References elog, ERROR, fn_addr, fn_name, funcname, i, InternalBGWorkers, lengthof, and load_external_function().
Referenced by BackgroundWorkerMain().
void RegisterBackgroundWorker | ( | BackgroundWorker * | worker | ) |
Definition at line 939 of file bgworker.c.
References BackgroundWorkerData, BackgroundWorkerList, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, DEBUG1, dlist_push_head(), elog, ereport, errcode(), errdetail_plural(), errhint(), errmsg(), errmsg_internal(), ERROR, IsPostmasterEnvironment, IsUnderPostmaster, LOG, max_worker_processes, MCXT_ALLOC_NO_OOM, MemoryContextAllocExtended(), PostmasterContext, process_shared_preload_libraries_in_progress, RegisteredBgWorker::rw_crashed_at, RegisteredBgWorker::rw_lnode, RegisteredBgWorker::rw_pid, RegisteredBgWorker::rw_terminate, RegisteredBgWorker::rw_worker, and SanityCheckBackgroundWorker().
Referenced by _PG_init(), ApplyLauncherRegister(), and apw_start_leader_worker().
bool RegisterDynamicBackgroundWorker | ( | BackgroundWorker * | worker, |
BackgroundWorkerHandle ** | handle | ||
) |
Definition at line 1045 of file bgworker.c.
References Assert, BackgroundWorkerData, BackgroundWorker::bgw_flags, BGWORKER_CLASS_PARALLEL, ERROR, BackgroundWorkerSlot::generation, BackgroundWorkerSlot::in_use, InvalidPid, IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAX_PARALLEL_WORKER_LIMIT, max_parallel_workers, palloc(), BackgroundWorkerArray::parallel_register_count, BackgroundWorkerArray::parallel_terminate_count, pg_write_barrier, BackgroundWorkerSlot::pid, PMSIGNAL_BACKGROUND_WORKER_CHANGE, SanityCheckBackgroundWorker(), SendPostmasterSignal(), BackgroundWorkerArray::slot, success, BackgroundWorkerSlot::terminate, BackgroundWorkerArray::total_slots, and BackgroundWorkerSlot::worker.
Referenced by apw_start_database_worker(), apw_start_leader_worker(), LaunchParallelWorkers(), logicalrep_worker_launch(), setup_background_workers(), and worker_spi_launch().
void ReportBackgroundWorkerExit | ( | RegisteredBgWorker * | rw | ) |
Definition at line 483 of file bgworker.c.
References Assert, BackgroundWorkerData, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, ForgetBackgroundWorker(), kill, max_worker_processes, BackgroundWorkerSlot::pid, RegisteredBgWorker::rw_pid, RegisteredBgWorker::rw_shmem_slot, RegisteredBgWorker::rw_terminate, RegisteredBgWorker::rw_worker, SIGUSR1, and BackgroundWorkerArray::slot.
Referenced by CleanupBackend().
void ReportBackgroundWorkerPID | ( | RegisteredBgWorker * | rw | ) |
Definition at line 461 of file bgworker.c.
References Assert, BackgroundWorkerData, BackgroundWorker::bgw_notify_pid, kill, max_worker_processes, BackgroundWorkerSlot::pid, RegisteredBgWorker::rw_pid, RegisteredBgWorker::rw_shmem_slot, RegisteredBgWorker::rw_worker, SIGUSR1, and BackgroundWorkerArray::slot.
Referenced by BackgroundWorkerStateChange(), and StartBackgroundWorker().
void ResetBackgroundWorkerCrashTimes | ( | void | ) |
Definition at line 579 of file bgworker.c.
References Assert, BackgroundWorkerList, BackgroundWorker::bgw_flags, BGW_NEVER_RESTART, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BGWORKER_CLASS_PARALLEL, dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, ForgetBackgroundWorker(), RegisteredBgWorker::rw_crashed_at, and RegisteredBgWorker::rw_worker.
Referenced by PostmasterStateMachine().
|
static |
Definition at line 631 of file bgworker.c.
References BackgroundWorker::bgw_flags, BackgroundWorker::bgw_name, BGW_NEVER_RESTART, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWORKER_BACKEND_DATABASE_CONNECTION, BGWORKER_CLASS_PARALLEL, BGWORKER_SHMEM_ACCESS, BgWorkerStart_PostmasterStart, ereport, errcode(), errmsg(), and USECS_PER_DAY.
Referenced by RegisterBackgroundWorker(), and RegisterDynamicBackgroundWorker().
void TerminateBackgroundWorker | ( | BackgroundWorkerHandle * | handle | ) |
Definition at line 1296 of file bgworker.c.
References Assert, BackgroundWorkerData, BackgroundWorkerSlot::generation, BackgroundWorkerHandle::generation, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), max_worker_processes, PMSIGNAL_BACKGROUND_WORKER_CHANGE, SendPostmasterSignal(), BackgroundWorkerArray::slot, BackgroundWorkerHandle::slot, and BackgroundWorkerSlot::terminate.
Referenced by cleanup_background_workers(), and DestroyParallelContext().
BgwHandleStatus WaitForBackgroundWorkerShutdown | ( | BackgroundWorkerHandle * | handle | ) |
Definition at line 1257 of file bgworker.c.
References BGWH_POSTMASTER_DIED, BGWH_STOPPED, CHECK_FOR_INTERRUPTS, GetBackgroundWorkerPid(), MyLatch, ResetLatch(), WaitLatch(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.
Referenced by apw_start_database_worker(), and WaitForParallelWorkersToExit().
BgwHandleStatus WaitForBackgroundWorkerStartup | ( | BackgroundWorkerHandle * | handle, |
pid_t * | pidp | ||
) |
Definition at line 1212 of file bgworker.c.
References BGWH_NOT_YET_STARTED, BGWH_POSTMASTER_DIED, BGWH_STARTED, CHECK_FOR_INTERRUPTS, GetBackgroundWorkerPid(), MyLatch, ResetLatch(), WaitLatch(), WL_LATCH_SET, and WL_POSTMASTER_DEATH.
Referenced by apw_start_leader_worker(), and worker_spi_launch().
|
static |
Definition at line 108 of file bgworker.c.
Referenced by BackgroundWorkerShmemInit(), BackgroundWorkerStateChange(), ForgetBackgroundWorker(), ForgetUnstartedBackgroundWorkers(), GetBackgroundWorkerPid(), GetBackgroundWorkerTypeByPid(), RegisterBackgroundWorker(), RegisterDynamicBackgroundWorker(), ReportBackgroundWorkerExit(), ReportBackgroundWorkerPID(), and TerminateBackgroundWorker().
dlist_head BackgroundWorkerList = DLIST_STATIC_INIT(BackgroundWorkerList) |
Definition at line 40 of file bgworker.c.
Referenced by BackgroundWorkerShmemInit(), BackgroundWorkerStateChange(), BackgroundWorkerStopNotifications(), DetermineSleepTime(), FindRegisteredWorkerBySlotNumber(), ForgetUnstartedBackgroundWorkers(), maybe_start_bgworkers(), RegisterBackgroundWorker(), and ResetBackgroundWorkerCrashTimes().
bgworker_main_type fn_addr |
Definition at line 117 of file bgworker.c.
Referenced by LookupBackgroundWorkerFunction().
const char* fn_name |
Definition at line 116 of file bgworker.c.
Referenced by LookupBackgroundWorkerFunction().
const { ... } InternalBGWorkers[] |
Referenced by LookupBackgroundWorkerFunction().