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-2024, 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"
20 #include "postmaster/auxprocess.h"
21 #include "postmaster/bgwriter.h"
22 #include "postmaster/startup.h"
24 #include "postmaster/walwriter.h"
27 #include "storage/ipc.h"
28 #include "storage/proc.h"
29 #include "storage/procsignal.h"
30 #include "utils/memutils.h"
31 #include "utils/ps_status.h"
32 
33 
34 static void ShutdownAuxiliaryProcess(int code, Datum arg);
35 
36 
37 /*
38  * AuxiliaryProcessMainCommon
39  *
40  * Common initialization code for auxiliary processes, such as the bgwriter,
41  * walwriter, walreceiver, and the startup process.
42  */
43 void
45 {
47 
48  /* Release postmaster's working memory context */
50  {
52  PostmasterContext = NULL;
53  }
54 
55  init_ps_display(NULL);
56 
58 
59  IgnoreSystemIndexes = true;
60 
61  /*
62  * As an auxiliary process, we aren't going to do the full InitPostgres
63  * pushups, but there are a couple of things that need to get lit up even
64  * in an auxiliary process.
65  */
66 
67  /*
68  * Create a PGPROC so we can use LWLocks and access shared memory.
69  */
71 
72  BaseInit();
73 
75 
76  /*
77  * Auxiliary processes don't run transactions, but they may need a
78  * resource owner anyway to manage buffer pins acquired outside
79  * transactions (and, perhaps, other things in future).
80  */
82 
83 
84  /* Initialize backend status information */
85  pgstat_beinit();
87 
88  /* register a before-shutdown callback for LWLock cleanup */
90 
92 }
93 
94 /*
95  * Begin shutdown of an auxiliary process. This is approximately the equivalent
96  * of ShutdownPostgres() in postinit.c. We can't run transactions in an
97  * auxiliary process, so most of the work of AbortTransaction() is not needed,
98  * but we do need to make sure we've released any LWLocks we are holding.
99  * (This is only critical during an error exit.)
100  */
101 static void
103 {
107 }
void AuxiliaryProcessMainCommon(void)
Definition: auxprocess.c:44
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: auxprocess.c:102
void pgstat_beinit(void)
void pgstat_bestart(void)
#define Assert(condition)
Definition: c.h:858
bool ConditionVariableCancelSleep(void)
bool IsUnderPostmaster
Definition: globals.c:118
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:449
@ InitProcessing
Definition: miscadmin.h:448
#define GetProcessingMode()
Definition: miscadmin.h:458
#define SetProcessingMode(mode)
Definition: miscadmin.h:460
bool IgnoreSystemIndexes
Definition: miscinit.c:80
void * arg
uintptr_t Datum
Definition: postgres.h:64
void BaseInit(void)
Definition: postinit.c:602
void ProcSignalInit(void)
Definition: procsignal.c:158
void init_ps_display(const char *fixed_part)
Definition: ps_status.c:267
void CreateAuxProcessResourceOwner(void)
Definition: resowner.c:982
void InitAuxiliaryProcess(void)
Definition: proc.c:523
static void pgstat_report_wait_end(void)
Definition: wait_event.h:101