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  IgnoreSystemIndexes = true;
59 
60  /*
61  * As an auxiliary process, we aren't going to do the full InitPostgres
62  * pushups, but there are a couple of things that need to get lit up even
63  * in an auxiliary process.
64  */
65 
66  /*
67  * Create a PGPROC so we can use LWLocks and access shared memory.
68  */
70 
71  BaseInit();
72 
74 
75  /*
76  * Auxiliary processes don't run transactions, but they may need a
77  * resource owner anyway to manage buffer pins acquired outside
78  * transactions (and, perhaps, other things in future).
79  */
81 
82 
83  /* Initialize backend status information */
84  pgstat_beinit();
86 
87  /* register a before-shutdown callback for LWLock cleanup */
89 
91 }
92 
93 /*
94  * Begin shutdown of an auxiliary process. This is approximately the equivalent
95  * of ShutdownPostgres() in postinit.c. We can't run transactions in an
96  * auxiliary process, so most of the work of AbortTransaction() is not needed,
97  * but we do need to make sure we've released any LWLocks we are holding.
98  * (This is only critical during an error exit.)
99  */
100 static void
102 {
106 }
void AuxiliaryProcessMainCommon(void)
Definition: auxprocess.c:44
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: auxprocess.c:101
void pgstat_beinit(void)
void pgstat_bestart(void)
#define Assert(condition)
Definition: c.h:858
bool ConditionVariableCancelSleep(void)
bool IsUnderPostmaster
Definition: globals.c:117
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:337
void LWLockReleaseAll(void)
Definition: lwlock.c:1878
MemoryContext PostmasterContext
Definition: mcxt.c:151
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454
@ NormalProcessing
Definition: miscadmin.h:449
@ BootstrapProcessing
Definition: miscadmin.h:447
#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:645
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:104