1/*--------------------------------------------------------------------
3 * POSTGRES pluggable background workers implementation
5 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * src/backend/postmaster/bgworker.c
10 *-------------------------------------------------------------------------
38 * The postmaster's list of registered background workers, in private memory.
43 * BackgroundWorkerSlots exist in shared memory and can be accessed (via
44 * the BackgroundWorkerArray) by both the postmaster and by regular backends.
45 * However, the postmaster cannot take locks, even spinlocks, because this
46 * might allow it to crash or become wedged if shared memory gets corrupted.
47 * Such an outcome is intolerable. Therefore, we need a lockless protocol
48 * for coordinating access to this data.
50 * The 'in_use' flag is used to hand off responsibility for the slot between
51 * the postmaster and the rest of the system. When 'in_use' is false,
52 * the postmaster will ignore the slot entirely, except for the 'in_use' flag
53 * itself, which it may read. In this state, regular backends may modify the
54 * slot. Once a backend sets 'in_use' to true, the slot becomes the
55 * responsibility of the postmaster. Regular backends may no longer modify it,
56 * but the postmaster may examine it. Thus, a backend initializing a slot
57 * must fully initialize the slot - and insert a write memory barrier - before
58 * marking it as in use.
60 * As an exception, however, even when the slot is in use, regular backends
61 * may set the 'terminate' flag for a slot, telling the postmaster not
62 * to restart it. Once the background worker is no longer running, the slot
63 * will be released for reuse.
65 * In addition to coordinating with the postmaster, backends modifying this
66 * data structure must coordinate with each other. Since they can take locks,
67 * this is straightforward: any backend wishing to manipulate a slot must
68 * take BackgroundWorkerLock in exclusive mode. Backends wishing to read
69 * data that might get concurrently modified by other backends should take
70 * this lock in shared mode. No matter what, backends reading this data
71 * structure must be able to tolerate concurrent modifications by the
78 pid_t
pid;
/* InvalidPid = not started yet; 0 = dead */
84 * In order to limit the total number of parallel workers (according to
85 * max_parallel_workers GUC), we maintain the number of active parallel
86 * workers. Since the postmaster cannot take locks, two variables are used for
87 * this purpose: the number of registered parallel workers (modified by the
88 * backends, protected by BackgroundWorkerLock) and the number of terminated
89 * parallel workers (modified only by the postmaster, lockless). The active
90 * number of parallel workers is the number of registered workers minus the
91 * terminated ones. These counters can of course overflow, but it's not
92 * important here since the subtraction will still give the right number.
111 * List of internal background worker entry points. We need this for
112 * reasons explained in LookupBackgroundWorkerFunction(), below.
138/* Private functions. */
143 * Calculate shared memory needed.
150 /* Array of workers is variably sized. */
159 * Initialize shared memory.
179 * Copy contents of worker list into shared memory. Record the shared
180 * memory slot assigned to each worker. This ensures a 1-to-1
181 * correspondence between the postmaster's private list and the array
202 * Mark any remaining slots as not in use.
217 * Search the postmaster's backend-private list of RegisteredBgWorker objects
218 * for the one that maps to the given slot number.
238 * Notice changes to shared memory made by other backends.
239 * Accept new worker requests only if allow_new_workers is true.
241 * This code runs in the postmaster, so we must be very careful not to assume
242 * that shared memory contents are sane. Otherwise, a rogue backend could
243 * take out the postmaster.
251 * The total number of slots stored in shared memory should match our
252 * notion of max_worker_processes. If it does not, something is very
253 * wrong. Further down, we always refer to this value as
254 * max_worker_processes, in case shared memory gets corrupted while we're
260 (
errmsg(
"inconsistent background worker state (\"max_worker_processes\"=%d, total slots=%d)",
267 * Iterate through slots, looking for newly-registered workers or workers
279 * Make sure we don't see the in_use flag before the updated slot
284 /* See whether we already know about this worker. */
289 * In general, the worker data can't change after it's initially
290 * registered. However, someone can set the terminate flag.
299 /* Report never-started, now-terminated worker as dead. */
307 * If we aren't allowing new workers, then immediately mark it for
308 * termination; the next stanza will take care of cleaning it up.
309 * Doing this ensures that any process waiting for the worker will get
310 * awoken, even though the worker will never be allowed to run.
312 if (!allow_new_workers)
316 * If the worker is marked for termination, we don't need to add it to
317 * the registered workers list; we can just free the slot. However, if
318 * bgw_notify_pid is set, the process that registered the worker may
319 * need to know that we've processed the terminate request, so be sure
327 * We need a memory barrier here to make sure that the load of
328 * bgw_notify_pid and the update of parallel_terminate_count
329 * complete before the store to in_use.
346 * Copy the registration data into the registered workers list.
354 (
errcode(ERRCODE_OUT_OF_MEMORY),
355 errmsg(
"out of memory")));
360 * Copy strings in a paranoid way. If shared memory is corrupted, the
361 * source data might not even be NUL-terminated.
373 * Copy various fixed-size fields.
375 * flags, start_time, and restart_time are examined by the postmaster,
376 * but nothing too bad will happen if they are corrupted. The
377 * remaining fields will only be examined by the child process. It
378 * might crash, but we won't.
387 * Copy the PID to be notified about state changes, but only if the
388 * postmaster knows about a backend with that PID. It isn't an error
389 * if the postmaster doesn't know about the PID, because the backend
390 * that requested the worker could have died (or been killed) just
391 * after doing so. Nonetheless, at least until we get some experience
392 * with how this plays out in the wild, log a message at a relative
398 elog(
DEBUG1,
"worker notification PID %d is not valid",
403 /* Initialize postmaster bookkeeping. */
419 * Forget about a background worker that's no longer needed.
421 * NOTE: The entry is unlinked from BackgroundWorkerList. If the caller is
422 * iterating through it, better use a mutable iterator!
424 * Caller is responsible for notifying bgw_notify_pid, if appropriate.
426 * This function must be invoked only in the postmaster.
438 * We need a memory barrier here to make sure that the update of
439 * parallel_terminate_count completes before the store to in_use.
456 * Report the PID of a newly-launched background worker in shared memory.
458 * This function should only be called from the postmaster.
474 * Report that the PID of a background worker is now zero because a
475 * previously-running background worker has exited.
477 * NOTE: The entry may be unlinked from BackgroundWorkerList. If the caller
478 * is iterating through it, better use a mutable iterator!
480 * This function should only be called from the postmaster.
494 * If this worker is slated for deregistration, do that before notifying
495 * the process which started it. Otherwise, if that process tries to
496 * reuse the slot immediately, it might not be available yet. In theory
497 * that could happen anyway if the process checks slot->pid at just the
498 * wrong moment, but this makes the window narrower.
509 * Cancel SIGUSR1 notifications for a PID belonging to an exiting backend.
511 * This function should only be called from the postmaster.
529 * Cancel any not-yet-started worker requests that have waiting processes.
531 * This is called during a normal ("smart" or "fast") database shutdown.
532 * After this point, no new background workers will be started, so anything
533 * that might be waiting for them needs to be kicked off its wait. We do
534 * that by canceling the bgworker registration entirely, which is perhaps
535 * overkill, but since we're shutting down it does not matter whether the
536 * registration record sticks around.
538 * This function should only be called from the postmaster.
554 /* If it's not yet started, and there's someone waiting ... */
558 /* ... then zap it, and notify the waiter */
569 * Reset background worker crash state.
571 * We assume that, after a crash-and-restart cycle, background workers without
572 * the never-restart flag should be restarted immediately, instead of waiting
573 * for bgw_restart_time to elapse. On the other hand, workers with that flag
574 * should be forgotten immediately, since we won't ever restart them.
576 * This function should only be called from the postmaster.
592 * Workers marked BGW_NEVER_RESTART shouldn't get relaunched after
593 * the crash, so forget about them. (If we wait until after the
594 * crash to forget about them, and they are parallel workers,
595 * parallel_terminate_count will get incremented after we've
596 * already zeroed parallel_register_count, which would be bad.)
603 * The accounting which we do via parallel_register_count and
604 * parallel_terminate_count would get messed up if a worker marked
605 * parallel could survive a crash and restart cycle. All such
606 * workers should be marked BGW_NEVER_RESTART, and thus control
607 * should never reach this branch.
612 * Allow this worker to be restarted immediately after we finish
619 * If there was anyone waiting for it, they're history.
627 * Complain about the BackgroundWorker definition using error level elevel.
628 * Return true if it looks ok, false if not (unless elevel >= ERROR, in
629 * which case we won't return at all in the not-OK case).
634 /* sanity check for flags */
637 * We used to support workers not connected to shared memory, but don't
638 * anymore. Thus this is a required flag now. We're not removing the flag
639 * for compatibility reasons and because the flag still provides some
640 * signal when reading code.
645 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
646 errmsg(
"background worker \"%s\": background workers without shared memory access are not supported",
656 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
657 errmsg(
"background worker \"%s\": cannot request database access if starting at postmaster start",
662 /* XXX other checks? */
670 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
671 errmsg(
"background worker \"%s\": invalid restart interval",
677 * Parallel workers may not be configured for restart, because the
678 * parallel_register_count/parallel_terminate_count accounting can't
679 * handle parallel workers lasting through a crash-and-restart cycle.
685 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
686 errmsg(
"background worker \"%s\": parallel workers may not be configured for restart",
692 * If bgw_type is not filled in, use bgw_name.
694 if (strcmp(worker->
bgw_type,
"") == 0)
701 * Standard SIGTERM handler for background workers
706 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
709 (
errcode(ERRCODE_ADMIN_SHUTDOWN),
710 errmsg(
"terminating background worker \"%s\" due to administrator command",
715 * Main entry point for background worker processes.
720 sigjmp_buf local_sigjmp_buf;
724 if (startup_data == NULL)
725 elog(
FATAL,
"unable to find bgworker entry");
731 * Now that we're done reading the startup data, release postmaster's
732 * working memory context.
746 /* Apply PostAuthDelay */
751 * Set up signal handlers.
756 * SIGINT is used to signal canceling the current action
762 /* XXX Any other handlers needed here? */
771 /* SIGQUIT handler was already set up by InitPostmasterChild */
781 * If an exception is encountered, processing resumes here.
783 * We just need to clean up, report the error, and go away.
785 if (sigsetjmp(local_sigjmp_buf, 1) != 0)
787 /* Since not using PG_TRY, must reset error stack by hand */
790 /* Prevent interrupts while cleaning up */
794 * sigsetjmp will have blocked all signals, but we may need to accept
795 * signals while communicating with our parallel leader. Once we've
796 * done HOLD_INTERRUPTS() it should be safe to unblock signals.
800 /* Report the error to the parallel leader and the server log */
804 * Do we need more cleanup here? For shmem-connected bgworkers, we
805 * will call InitProcess below, which will install ProcKill as exit
806 * callback. That will take care of releasing locks, etc.
813 /* We can now handle ereport(ERROR) */
817 * Create a per-backend PGPROC struct in shared memory. We must do this
818 * before we can use LWLocks or access any shared memory.
823 * Early initialization.
828 * Look up the entry point function, loading its library if necessary.
834 * Note that in normal processes, we would call InitPostgres here. For a
835 * worker, however, we don't know what database to connect to, yet; so we
836 * need to wait until the user code does it via
837 * BackgroundWorkerInitializeConnection().
841 * Now invoke the user-defined worker code
845 /* ... and if it returns, we're done */
850 * Connect background worker to a database.
856 bits32 init_flags = 0;
/* never honor session_preload_libraries */
858 /* ignore datallowconn and ACL_CONNECT? */
861 /* ignore rolcanlogin? */
865 /* XXX is this the right errcode? */
868 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
869 errmsg(
"database connection requirement not indicated during registration")));
874 NULL);
/* no out_dbname */
876 /* it had better not gotten out of "init" mode yet */
879 (
errmsg(
"invalid processing mode in background worker")));
884 * Connect background worker to a database using OIDs.
890 bits32 init_flags = 0;
/* never honor session_preload_libraries */
892 /* ignore datallowconn and ACL_CONNECT? */
895 /* ignore rolcanlogin? */
899 /* XXX is this the right errcode? */
902 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
903 errmsg(
"database connection requirement not indicated during registration")));
906 NULL, useroid,
/* role to connect as */
908 NULL);
/* no out_dbname */
910 /* it had better not gotten out of "init" mode yet */
913 (
errmsg(
"invalid processing mode in background worker")));
918 * Block/unblock signals in a background worker
923 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
933 * Register a new static background worker.
935 * This can only be called directly from postmaster or in the _PG_init
936 * function of a module library that's loaded by shared_preload_libraries;
937 * otherwise it will have no effect.
943 static int numworkers = 0;
946 * Static background workers can only be registered in the postmaster
952 * In EXEC_BACKEND or single-user mode, we process
953 * shared_preload_libraries in backend processes too. We cannot
954 * register static background workers at that stage, but many
955 * libraries' _PG_init() functions don't distinguish whether they're
956 * being loaded in the postmaster or in a backend, they just check
957 * process_shared_preload_libraries_in_progress. It's a bit sloppy,
958 * but for historical reasons we tolerate it. In EXEC_BACKEND mode,
959 * the background workers should already have been registered when the
960 * library was loaded in postmaster.
965 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
966 errmsg(
"background worker \"%s\": must be registered in \"shared_preload_libraries\"",
972 * Cannot register static background workers after calling
973 * BackgroundWorkerShmemInit().
976 elog(
ERROR,
"cannot register background worker \"%s\" after shmem init",
988 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
989 errmsg(
"background worker \"%s\": only dynamic background workers can request notification",
995 * Enforce maximum number of workers. Note this is overly restrictive: we
996 * could allow more non-shmem-connected workers, because these don't count
997 * towards the MAX_BACKENDS limit elsewhere. For now, it doesn't seem
998 * important to relax this restriction.
1003 (
errcode(ERRCODE_CONFIGURATION_LIMIT_EXCEEDED),
1004 errmsg(
"too many background workers"),
1005 errdetail_plural(
"Up to %d background worker can be registered with the current settings.",
1006 "Up to %d background workers can be registered with the current settings.",
1009 errhint(
"Consider increasing the configuration parameter \"%s\".",
"max_worker_processes")));
1014 * Copy the registration data into the registered workers list.
1022 (
errcode(ERRCODE_OUT_OF_MEMORY),
1023 errmsg(
"out of memory")));
1036 * Register a new background worker from a regular backend.
1038 * Returns true on success and false on failure. Failure typically indicates
1039 * that no background worker slots are currently available.
1041 * If handle != NULL, we'll set *handle to a pointer that can subsequently
1042 * be used as an argument to GetBackgroundWorkerPid(). The caller can
1043 * free this pointer using pfree(), if desired.
1055 * We can't register dynamic background workers from the postmaster. If
1056 * this is a standalone backend, we're the only process and can't start
1057 * any more. In a multi-process environment, it might be theoretically
1058 * possible, but we don't currently support it due to locking
1059 * considerations; see comments on the BackgroundWorkerSlot data
1073 * If this is a parallel worker, check whether there are already too many
1074 * parallel workers; if so, don't register another one. Our view of
1075 * parallel_terminate_count may be slightly stale, but that doesn't really
1076 * matter: we would have gotten the same result if we'd arrived here
1077 * slightly earlier anyway. There's no help for it, either, since the
1078 * postmaster must not take locks; a memory barrier wouldn't guarantee
1093 * Look for an unused slot. If we find one, grab it.
1110 * Make sure postmaster doesn't see the slot as in use before it
1111 * sees the new contents.
1123 /* If we found a slot, tell the postmaster to notice the change. */
1128 * If we found a slot and the user has provided a handle, initialize it.
1133 (*handle)->slot = slotno;
1134 (*handle)->generation = generation;
1141 * Get the PID of a dynamically-registered background worker.
1143 * If the worker is determined to be running, the return value will be
1144 * BGWH_STARTED and *pidp will get the PID of the worker process. If the
1145 * postmaster has not yet attempted to start the worker, the return value will
1146 * be BGWH_NOT_YET_STARTED. Otherwise, the return value is BGWH_STOPPED.
1148 * BGWH_STOPPED can indicate either that the worker is temporarily stopped
1149 * (because it is configured for automatic restart and exited non-zero),
1150 * or that the worker is permanently stopped (because it exited with exit
1151 * code 0, or was not configured for automatic restart), or even that the
1152 * worker was unregistered without ever starting (either because startup
1153 * failed and the worker is not configured for automatic restart, or because
1154 * TerminateBackgroundWorker was used before the worker was successfully
1167 * We could probably arrange to synchronize access to data using memory
1168 * barriers only, but for now, let's just keep it simple and grab the
1169 * lock. It seems unlikely that there will be enough traffic here to
1170 * result in meaningful contention.
1175 * The generation number can't be concurrently changed while we hold the
1176 * lock. The pid, which is updated by the postmaster, can change at any
1177 * time, but we assume such changes are atomic. So the value we read
1178 * won't be garbage, but it might be out of date by the time the caller
1179 * examines it (but that's unavoidable anyway).
1181 * The in_use flag could be in the process of changing from true to false,
1182 * but if it is already false then it can't change further.
1201 * Wait for a background worker to start up.
1203 * This is like GetBackgroundWorkerPid(), except that if the worker has not
1204 * yet started, we wait for it to do so; thus, BGWH_NOT_YET_STARTED is never
1205 * returned. However, if the postmaster has died, we give up and return
1206 * BGWH_POSTMASTER_DIED, since it that case we know that startup will not
1209 * The caller *must* have set our PID as the worker's bgw_notify_pid,
1210 * else we will not be awoken promptly when the worker's state changes.
1232 WAIT_EVENT_BGWORKER_STARTUP);
1247 * Wait for a background worker to stop.
1249 * If the worker hasn't yet started, or is running, we wait for it to stop
1250 * and then return BGWH_STOPPED. However, if the postmaster has died, we give
1251 * up and return BGWH_POSTMASTER_DIED, because it's the postmaster that
1252 * notifies us when a worker's state changes.
1254 * The caller *must* have set our PID as the worker's bgw_notify_pid,
1255 * else we will not be awoken promptly when the worker's state changes.
1275 WAIT_EVENT_BGWORKER_SHUTDOWN);
1290 * Instruct the postmaster to terminate a background worker.
1292 * Note that it's safe to do this without regard to whether the worker is
1293 * still running, or even if the worker may already have exited and been
1300 bool signal_postmaster =
false;
1305 /* Set terminate flag in shared memory, unless slot has been reused. */
1310 signal_postmaster =
true;
1314 /* Make sure the postmaster notices the change to shared memory. */
1315 if (signal_postmaster)
1320 * Look up (and possibly load) a bgworker entry point function.
1322 * For functions contained in the core code, we use library name "postgres"
1323 * and consult the InternalBGWorkers array. External functions are
1324 * looked up, and loaded if necessary, using load_external_function().
1326 * The point of this is to pass function names as strings across process
1327 * boundaries. We can't pass actual function addresses because of the
1328 * possibility that the function has been loaded at a different address
1329 * in a different process. This is obviously a hazard for functions in
1330 * loadable libraries, but it can happen even for functions in the core code
1331 * on platforms using EXEC_BACKEND (e.g., Windows).
1333 * At some point it might be worthwhile to get rid of InternalBGWorkers[]
1334 * in favor of applying load_external_function() for core functions too;
1335 * but that raises portability issues that are not worth addressing now.
1341 * If the function is to be loaded from postgres itself, search the
1342 * InternalBGWorkers array.
1344 if (strcmp(libraryname,
"postgres") == 0)
1354 /* We can only reach this by programming error. */
1358 /* Otherwise load from external library. */
1364 * Given a PID, get the bgw_type of the background worker. Returns NULL if
1365 * not a valid background worker.
1367 * The return value is in static memory belonging to this function, so it has
1368 * to be used before calling this function again. This is so that the caller
1369 * doesn't have to worry about the background worker locking protocol.
1384 if (slot->
pid > 0 && slot->
pid == pid)
void ParallelApplyWorkerMain(Datum main_arg)
void ascii_safe_strlcpy(char *dest, const char *src, size_t destsiz)
#define pg_memory_barrier()
#define pg_read_barrier()
#define pg_write_barrier()
void ParallelWorkerMain(Datum main_arg)
void ApplyWorkerMain(Datum main_arg)
void RegisterBackgroundWorker(BackgroundWorker *worker)
BgwHandleStatus WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
void BackgroundWorkerInitializeConnection(const char *dbname, const char *username, uint32 flags)
static bool SanityCheckBackgroundWorker(BackgroundWorker *worker, int elevel)
void ReportBackgroundWorkerPID(RegisteredBgWorker *rw)
void TerminateBackgroundWorker(BackgroundWorkerHandle *handle)
static const struct @18 InternalBGWorkers[]
void ReportBackgroundWorkerExit(RegisteredBgWorker *rw)
BgwHandleStatus WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *handle)
void ResetBackgroundWorkerCrashTimes(void)
void BackgroundWorkerShmemInit(void)
void BackgroundWorkerUnblockSignals(void)
struct BackgroundWorkerSlot BackgroundWorkerSlot
void BackgroundWorkerInitializeConnectionByOid(Oid dboid, Oid useroid, uint32 flags)
void BackgroundWorkerBlockSignals(void)
dlist_head BackgroundWorkerList
void ForgetBackgroundWorker(RegisteredBgWorker *rw)
BgwHandleStatus GetBackgroundWorkerPid(BackgroundWorkerHandle *handle, pid_t *pidp)
static BackgroundWorkerArray * BackgroundWorkerData
static RegisteredBgWorker * FindRegisteredWorkerBySlotNumber(int slotno)
static bgworker_main_type LookupBackgroundWorkerFunction(const char *libraryname, const char *funcname)
static void bgworker_die(SIGNAL_ARGS)
void BackgroundWorkerStopNotifications(pid_t pid)
Size BackgroundWorkerShmemSize(void)
void BackgroundWorkerStateChange(bool allow_new_workers)
const char * GetBackgroundWorkerTypeByPid(pid_t pid)
bool RegisterDynamicBackgroundWorker(BackgroundWorker *worker, BackgroundWorkerHandle **handle)
void BackgroundWorkerMain(const void *startup_data, size_t startup_data_len)
bgworker_main_type fn_addr
void ForgetUnstartedBackgroundWorkers(void)
struct BackgroundWorkerArray BackgroundWorkerArray
#define BGW_NEVER_RESTART
#define BGWORKER_BYPASS_ROLELOGINCHECK
#define BGWORKER_CLASS_PARALLEL
@ BgWorkerStart_PostmasterStart
#define BGWORKER_BACKEND_DATABASE_CONNECTION
#define BGWORKER_BYPASS_ALLOWCONN
#define BGWORKER_SHMEM_ACCESS
void(* bgworker_main_type)(Datum main_arg)
#define MAX_PARALLEL_WORKER_LIMIT
#define FLEXIBLE_ARRAY_MEMBER
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
int errmsg_internal(const char *fmt,...)
void EmitErrorReport(void)
ErrorContextCallback * error_context_stack
int errdetail_plural(const char *fmt_singular, const char *fmt_plural, unsigned long n,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
sigjmp_buf * PG_exception_stack
#define ereport(elevel,...)
#define MCXT_ALLOC_NO_OOM
bool IsPostmasterEnvironment
Assert(PointerIsAligned(start, uint64))
#define dlist_foreach(iter, lhead)
static void dlist_delete(dlist_node *node)
static void dlist_push_head(dlist_head *head, dlist_node *node)
#define dlist_foreach_modify(iter, lhead)
#define DLIST_STATIC_INIT(name)
#define dlist_container(type, membername, ptr)
void ResetLatch(Latch *latch)
int WaitLatch(Latch *latch, int wakeEvents, long timeout, uint32 wait_event_info)
void ApplyLauncherMain(Datum main_arg)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void * MemoryContextAlloc(MemoryContext context, Size size)
void pfree(void *pointer)
MemoryContext TopMemoryContext
void * MemoryContextAllocExtended(MemoryContext context, Size size, int flags)
MemoryContext PostmasterContext
void MemoryContextDelete(MemoryContext context)
#define GetProcessingMode()
#define CHECK_FOR_INTERRUPTS()
#define HOLD_INTERRUPTS()
#define IsInitProcessingMode()
#define SetProcessingMode(mode)
#define INIT_PG_OVERRIDE_ROLE_LOGIN
#define INIT_PG_OVERRIDE_ALLOW_CONNS
BackendType MyBackendType
bool process_shared_preload_libraries_in_progress
void SendPostmasterSignal(PMSignalReason reason)
@ PMSIGNAL_BACKGROUND_WORKER_CHANGE
void FloatExceptionHandler(SIGNAL_ARGS)
void StatementCancelHandler(SIGNAL_ARGS)
void InitPostgres(const char *in_dbname, Oid dboid, const char *username, Oid useroid, bits32 flags, char *out_dbname)
BackgroundWorker * MyBgworkerEntry
bool PostmasterMarkPIDForWorkerNotify(int pid)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
void init_ps_display(const char *fixed_part)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
void pg_usleep(long microsec)
uint32 parallel_terminate_count
uint32 parallel_register_count
BackgroundWorkerSlot slot[FLEXIBLE_ARRAY_MEMBER]
char bgw_function_name[BGW_MAXLEN]
char bgw_name[BGW_MAXLEN]
char bgw_type[BGW_MAXLEN]
BgWorkerStartTime bgw_start_time
char bgw_extra[BGW_EXTRALEN]
char bgw_library_name[MAXPGPATH]
TimestampTz rw_crashed_at
BackgroundWorker rw_worker
void TablesyncWorkerMain(Datum main_arg)
void InitializeTimeouts(void)
#define WL_POSTMASTER_DEATH