PostgreSQL Source Code git master
auxprocess.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 * auxprocess.c
3 * functions related to auxiliary processes.
4 *
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * IDENTIFICATION
10 * src/backend/postmaster/auxprocess.c
11 *-------------------------------------------------------------------------
12 */
13#include "postgres.h"
14
15#include <unistd.h>
16#include <signal.h>
17
18#include "miscadmin.h"
19#include "pgstat.h"
22#include "storage/ipc.h"
23#include "storage/proc.h"
24#include "storage/procsignal.h"
25#include "utils/memutils.h"
26#include "utils/ps_status.h"
27
28
29static void ShutdownAuxiliaryProcess(int code, Datum arg);
30
31
32/*
33 * AuxiliaryProcessMainCommon
34 *
35 * Common initialization code for auxiliary processes, such as the bgwriter,
36 * walwriter, walreceiver, and the startup process.
37 */
38void
40{
42
43 /* Release postmaster's working memory context */
45 {
47 PostmasterContext = NULL;
48 }
49
50 init_ps_display(NULL);
51
53
55
56 /*
57 * As an auxiliary process, we aren't going to do the full InitPostgres
58 * pushups, but there are a couple of things that need to get lit up even
59 * in an auxiliary process.
60 */
61
62 /*
63 * Create a PGPROC so we can use LWLocks and access shared memory.
64 */
66
67 BaseInit();
68
69 ProcSignalInit(false, 0);
70
71 /*
72 * Auxiliary processes don't run transactions, but they may need a
73 * resource owner anyway to manage buffer pins acquired outside
74 * transactions (and, perhaps, other things in future).
75 */
77
78
79 /* Initialize backend status information */
82
83 /* register a before-shutdown callback for LWLock cleanup */
85
87}
88
89/*
90 * Begin shutdown of an auxiliary process. This is approximately the equivalent
91 * of ShutdownPostgres() in postinit.c. We can't run transactions in an
92 * auxiliary process, so most of the work of AbortTransaction() is not needed,
93 * but we do need to make sure we've released any LWLocks we are holding.
94 * (This is only critical during an error exit.)
95 */
96static void
98{
102}
void AuxiliaryProcessMainCommon(void)
Definition: auxprocess.c:39
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: auxprocess.c:97
void pgstat_beinit(void)
void pgstat_bestart(void)
#define Assert(condition)
Definition: c.h:815
bool ConditionVariableCancelSleep(void)
bool IsUnderPostmaster
Definition: globals.c:119
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:337
void LWLockReleaseAll(void)
Definition: lwlock.c:1876
MemoryContext PostmasterContext
Definition: mcxt.c:151
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
@ NormalProcessing
Definition: miscadmin.h:461
@ InitProcessing
Definition: miscadmin.h:460
#define GetProcessingMode()
Definition: miscadmin.h:470
#define SetProcessingMode(mode)
Definition: miscadmin.h:472
bool IgnoreSystemIndexes
Definition: miscinit.c:81
void * arg
uintptr_t Datum
Definition: postgres.h:69
void BaseInit(void)
Definition: postinit.c:606
void ProcSignalInit(bool cancel_key_valid, int32 cancel_key)
Definition: procsignal.c:166
void init_ps_display(const char *fixed_part)
Definition: ps_status.c:269
void CreateAuxProcessResourceOwner(void)
Definition: resowner.c:982
void InitAuxiliaryProcess(void)
Definition: proc.c:566
static void pgstat_report_wait_end(void)
Definition: wait_event.h:101