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-2023, 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 "
libpq/pqsignal.h
"
19
#include "
miscadmin.h
"
20
#include "
pgstat.h
"
21
#include "
postmaster/auxprocess.h
"
22
#include "
postmaster/bgwriter.h
"
23
#include "
postmaster/startup.h
"
24
#include "
postmaster/walwriter.h
"
25
#include "
replication/walreceiver.h
"
26
#include "
storage/bufmgr.h
"
27
#include "
storage/bufpage.h
"
28
#include "
storage/condition_variable.h
"
29
#include "
storage/ipc.h
"
30
#include "
storage/proc.h
"
31
#include "
tcop/tcopprot.h
"
32
#include "
utils/memutils.h
"
33
#include "
utils/ps_status.h
"
34
#include "
utils/rel.h
"
35
36
37
static
void
ShutdownAuxiliaryProcess
(
int
code,
Datum
arg
);
38
39
40
/* ----------------
41
* global variables
42
* ----------------
43
*/
44
45
AuxProcType
MyAuxProcType
=
NotAnAuxProcess
;
/* declared in miscadmin.h */
46
47
48
/*
49
* AuxiliaryProcessMain
50
*
51
* The main entry point for auxiliary processes, such as the bgwriter,
52
* walwriter, walreceiver, bootstrapper and the shared memory checker code.
53
*
54
* This code is here just because of historical reasons.
55
*/
56
void
57
AuxiliaryProcessMain
(
AuxProcType
auxtype)
58
{
59
Assert
(
IsUnderPostmaster
);
60
61
MyAuxProcType
= auxtype;
62
63
switch
(
MyAuxProcType
)
64
{
65
case
StartupProcess
:
66
MyBackendType
=
B_STARTUP
;
67
break
;
68
case
ArchiverProcess
:
69
MyBackendType
=
B_ARCHIVER
;
70
break
;
71
case
BgWriterProcess
:
72
MyBackendType
=
B_BG_WRITER
;
73
break
;
74
case
CheckpointerProcess
:
75
MyBackendType
=
B_CHECKPOINTER
;
76
break
;
77
case
WalWriterProcess
:
78
MyBackendType
=
B_WAL_WRITER
;
79
break
;
80
case
WalReceiverProcess
:
81
MyBackendType
=
B_WAL_RECEIVER
;
82
break
;
83
default
:
84
elog
(
PANIC
,
"unrecognized process type: %d"
, (
int
)
MyAuxProcType
);
85
MyBackendType
=
B_INVALID
;
86
}
87
88
init_ps_display
(NULL);
89
90
SetProcessingMode
(
BootstrapProcessing
);
91
IgnoreSystemIndexes
=
true
;
92
93
/*
94
* As an auxiliary process, we aren't going to do the full InitPostgres
95
* pushups, but there are a couple of things that need to get lit up even
96
* in an auxiliary process.
97
*/
98
99
/*
100
* Create a PGPROC so we can use LWLocks and access shared memory.
101
*/
102
InitAuxiliaryProcess
();
103
104
BaseInit
();
105
106
/*
107
* Assign the ProcSignalSlot for an auxiliary process. Since it doesn't
108
* have a BackendId, the slot is statically allocated based on the
109
* auxiliary process type (MyAuxProcType). Backends use slots indexed in
110
* the range from 1 to MaxBackends (inclusive), so we use MaxBackends +
111
* AuxProcType + 1 as the index of the slot for an auxiliary process.
112
*
113
* This will need rethinking if we ever want more than one of a particular
114
* auxiliary process type.
115
*/
116
ProcSignalInit
(
MaxBackends
+
MyAuxProcType
+ 1);
117
118
/*
119
* Auxiliary processes don't run transactions, but they may need a
120
* resource owner anyway to manage buffer pins acquired outside
121
* transactions (and, perhaps, other things in future).
122
*/
123
CreateAuxProcessResourceOwner
();
124
125
126
/* Initialize backend status information */
127
pgstat_beinit
();
128
pgstat_bestart
();
129
130
/* register a before-shutdown callback for LWLock cleanup */
131
before_shmem_exit
(
ShutdownAuxiliaryProcess
, 0);
132
133
SetProcessingMode
(
NormalProcessing
);
134
135
switch
(
MyAuxProcType
)
136
{
137
case
StartupProcess
:
138
StartupProcessMain
();
139
proc_exit
(1);
140
141
case
ArchiverProcess
:
142
PgArchiverMain
();
143
proc_exit
(1);
144
145
case
BgWriterProcess
:
146
BackgroundWriterMain
();
147
proc_exit
(1);
148
149
case
CheckpointerProcess
:
150
CheckpointerMain
();
151
proc_exit
(1);
152
153
case
WalWriterProcess
:
154
WalWriterMain
();
155
proc_exit
(1);
156
157
case
WalReceiverProcess
:
158
WalReceiverMain
();
159
proc_exit
(1);
160
161
default
:
162
elog
(
PANIC
,
"unrecognized process type: %d"
, (
int
)
MyAuxProcType
);
163
proc_exit
(1);
164
}
165
}
166
167
/*
168
* Begin shutdown of an auxiliary process. This is approximately the equivalent
169
* of ShutdownPostgres() in postinit.c. We can't run transactions in an
170
* auxiliary process, so most of the work of AbortTransaction() is not needed,
171
* but we do need to make sure we've released any LWLocks we are holding.
172
* (This is only critical during an error exit.)
173
*/
174
static
void
175
ShutdownAuxiliaryProcess
(
int
code,
Datum
arg
)
176
{
177
LWLockReleaseAll
();
178
ConditionVariableCancelSleep
();
179
pgstat_report_wait_end
();
180
}
MyAuxProcType
AuxProcType MyAuxProcType
Definition:
auxprocess.c:45
AuxiliaryProcessMain
void AuxiliaryProcessMain(AuxProcType auxtype)
Definition:
auxprocess.c:57
ShutdownAuxiliaryProcess
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition:
auxprocess.c:175
auxprocess.h
StartupProcessMain
void StartupProcessMain(void)
Definition:
startup.c:244
pgstat_beinit
void pgstat_beinit(void)
Definition:
backend_status.c:249
pgstat_bestart
void pgstat_bestart(void)
Definition:
backend_status.c:292
BackgroundWriterMain
void BackgroundWriterMain(void)
Definition:
bgwriter.c:91
bgwriter.h
bufmgr.h
bufpage.h
CheckpointerMain
void CheckpointerMain(void)
Definition:
checkpointer.c:172
ConditionVariableCancelSleep
bool ConditionVariableCancelSleep(void)
Definition:
condition_variable.c:230
condition_variable.h
elog
elog(ERROR, "%s: %s", p2, msg)
PANIC
#define PANIC
Definition:
elog.h:42
IsUnderPostmaster
bool IsUnderPostmaster
Definition:
globals.c:115
MaxBackends
int MaxBackends
Definition:
globals.c:142
before_shmem_exit
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition:
ipc.c:337
proc_exit
void proc_exit(int code)
Definition:
ipc.c:104
ipc.h
Assert
Assert(fmt[strlen(fmt) - 1] !='\n')
LWLockReleaseAll
void LWLockReleaseAll(void)
Definition:
lwlock.c:1903
memutils.h
miscadmin.h
NormalProcessing
@ NormalProcessing
Definition:
miscadmin.h:408
BootstrapProcessing
@ BootstrapProcessing
Definition:
miscadmin.h:406
SetProcessingMode
#define SetProcessingMode(mode)
Definition:
miscadmin.h:419
B_WAL_WRITER
@ B_WAL_WRITER
Definition:
miscadmin.h:339
B_WAL_RECEIVER
@ B_WAL_RECEIVER
Definition:
miscadmin.h:337
B_CHECKPOINTER
@ B_CHECKPOINTER
Definition:
miscadmin.h:333
B_STARTUP
@ B_STARTUP
Definition:
miscadmin.h:336
B_INVALID
@ B_INVALID
Definition:
miscadmin.h:326
B_BG_WRITER
@ B_BG_WRITER
Definition:
miscadmin.h:332
B_ARCHIVER
@ B_ARCHIVER
Definition:
miscadmin.h:327
AuxProcType
AuxProcType
Definition:
miscadmin.h:437
BgWriterProcess
@ BgWriterProcess
Definition:
miscadmin.h:440
StartupProcess
@ StartupProcess
Definition:
miscadmin.h:439
NotAnAuxProcess
@ NotAnAuxProcess
Definition:
miscadmin.h:438
ArchiverProcess
@ ArchiverProcess
Definition:
miscadmin.h:441
WalWriterProcess
@ WalWriterProcess
Definition:
miscadmin.h:443
WalReceiverProcess
@ WalReceiverProcess
Definition:
miscadmin.h:444
CheckpointerProcess
@ CheckpointerProcess
Definition:
miscadmin.h:442
IgnoreSystemIndexes
bool IgnoreSystemIndexes
Definition:
miscinit.c:80
MyBackendType
BackendType MyBackendType
Definition:
miscinit.c:63
arg
void * arg
Definition:
pg_backup_utils.c:27
PgArchiverMain
void PgArchiverMain(void)
Definition:
pgarch.c:212
pgstat.h
postgres.h
Datum
uintptr_t Datum
Definition:
postgres.h:64
BaseInit
void BaseInit(void)
Definition:
postinit.c:629
pqsignal.h
proc.h
ProcSignalInit
void ProcSignalInit(int pss_idx)
Definition:
procsignal.c:162
init_ps_display
void init_ps_display(const char *fixed_part)
Definition:
ps_status.c:242
ps_status.h
rel.h
CreateAuxProcessResourceOwner
void CreateAuxProcessResourceOwner(void)
Definition:
resowner.c:983
InitAuxiliaryProcess
void InitAuxiliaryProcess(void)
Definition:
proc.c:519
startup.h
tcopprot.h
unistd.h
pgstat_report_wait_end
static void pgstat_report_wait_end(void)
Definition:
wait_event.h:104
WalReceiverMain
void WalReceiverMain(void)
Definition:
walreceiver.c:186
walreceiver.h
WalWriterMain
void WalWriterMain(void)
Definition:
walwriter.c:91
walwriter.h
src
backend
postmaster
auxprocess.c
Generated on Mon Dec 11 2023 12:13:18 for PostgreSQL Source Code by
1.9.1