PostgreSQL Source Code  git master
auxprocess.c File Reference
#include "postgres.h"
#include <unistd.h>
#include <signal.h>
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "postmaster/auxprocess.h"
#include "postmaster/bgwriter.h"
#include "postmaster/startup.h"
#include "postmaster/walwriter.h"
#include "replication/walreceiver.h"
#include "storage/bufmgr.h"
#include "storage/bufpage.h"
#include "storage/condition_variable.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
#include "utils/rel.h"
Include dependency graph for auxprocess.c:

Go to the source code of this file.

Functions

static void ShutdownAuxiliaryProcess (int code, Datum arg)
 
void AuxiliaryProcessMain (AuxProcType auxtype)
 

Variables

AuxProcType MyAuxProcType = NotAnAuxProcess
 

Function Documentation

◆ AuxiliaryProcessMain()

void AuxiliaryProcessMain ( AuxProcType  auxtype)

Definition at line 57 of file auxprocess.c.

58 {
60 
61  MyAuxProcType = auxtype;
62 
63  switch (MyAuxProcType)
64  {
65  case StartupProcess:
67  break;
68  case ArchiverProcess:
70  break;
71  case BgWriterProcess:
73  break;
76  break;
77  case WalWriterProcess:
79  break;
80  case WalReceiverProcess:
82  break;
83  default:
84  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
86  }
87 
88  init_ps_display(NULL);
89 
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. In the EXEC_BACKEND case, this
101  * was already done by SubPostmasterMain().
102  */
103 #ifndef EXEC_BACKEND
105 #endif
106 
107  BaseInit();
108 
109  /*
110  * Assign the ProcSignalSlot for an auxiliary process. Since it doesn't
111  * have a BackendId, the slot is statically allocated based on the
112  * auxiliary process type (MyAuxProcType). Backends use slots indexed in
113  * the range from 1 to MaxBackends (inclusive), so we use MaxBackends +
114  * AuxProcType + 1 as the index of the slot for an auxiliary process.
115  *
116  * This will need rethinking if we ever want more than one of a particular
117  * auxiliary process type.
118  */
120 
121  /*
122  * Auxiliary processes don't run transactions, but they may need a
123  * resource owner anyway to manage buffer pins acquired outside
124  * transactions (and, perhaps, other things in future).
125  */
127 
128 
129  /* Initialize backend status information */
130  pgstat_beinit();
131  pgstat_bestart();
132 
133  /* register a before-shutdown callback for LWLock cleanup */
135 
137 
138  switch (MyAuxProcType)
139  {
140  case StartupProcess:
142  proc_exit(1);
143 
144  case ArchiverProcess:
145  PgArchiverMain();
146  proc_exit(1);
147 
148  case BgWriterProcess:
150  proc_exit(1);
151 
152  case CheckpointerProcess:
154  proc_exit(1);
155 
156  case WalWriterProcess:
157  WalWriterMain();
158  proc_exit(1);
159 
160  case WalReceiverProcess:
161  WalReceiverMain();
162  proc_exit(1);
163 
164  default:
165  elog(PANIC, "unrecognized process type: %d", (int) MyAuxProcType);
166  proc_exit(1);
167  }
168 }
AuxProcType MyAuxProcType
Definition: auxprocess.c:45
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: auxprocess.c:178
void StartupProcessMain(void)
Definition: startup.c:230
void pgstat_beinit(void)
void pgstat_bestart(void)
void BackgroundWriterMain(void)
Definition: bgwriter.c:91
void CheckpointerMain(void)
Definition: checkpointer.c:181
#define PANIC
Definition: elog.h:42
bool IsUnderPostmaster
Definition: globals.c:113
int MaxBackends
Definition: globals.c:140
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:333
void proc_exit(int code)
Definition: ipc.c:104
Assert(fmt[strlen(fmt) - 1] !='\n')
@ NormalProcessing
Definition: miscadmin.h:397
@ BootstrapProcessing
Definition: miscadmin.h:395
#define SetProcessingMode(mode)
Definition: miscadmin.h:408
@ B_WAL_WRITER
Definition: miscadmin.h:331
@ B_WAL_RECEIVER
Definition: miscadmin.h:329
@ B_CHECKPOINTER
Definition: miscadmin.h:325
@ B_STARTUP
Definition: miscadmin.h:328
@ B_INVALID
Definition: miscadmin.h:318
@ B_BG_WRITER
Definition: miscadmin.h:324
@ B_ARCHIVER
Definition: miscadmin.h:319
@ BgWriterProcess
Definition: miscadmin.h:429
@ StartupProcess
Definition: miscadmin.h:428
@ ArchiverProcess
Definition: miscadmin.h:430
@ WalWriterProcess
Definition: miscadmin.h:432
@ WalReceiverProcess
Definition: miscadmin.h:433
@ CheckpointerProcess
Definition: miscadmin.h:431
bool IgnoreSystemIndexes
Definition: miscinit.c:80
BackendType MyBackendType
Definition: miscinit.c:63
void PgArchiverMain(void)
Definition: pgarch.c:209
void BaseInit(void)
Definition: postinit.c:623
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:161
void init_ps_display(const char *fixed_part)
Definition: ps_status.c:251
void CreateAuxProcessResourceOwner(void)
Definition: resowner.c:892
void InitAuxiliaryProcess(void)
Definition: proc.c:515
void WalReceiverMain(void)
Definition: walreceiver.c:187
void WalWriterMain(void)
Definition: walwriter.c:91

References ArchiverProcess, Assert(), B_ARCHIVER, B_BG_WRITER, B_CHECKPOINTER, B_INVALID, B_STARTUP, B_WAL_RECEIVER, B_WAL_WRITER, BackgroundWriterMain(), BaseInit(), before_shmem_exit(), BgWriterProcess, BootstrapProcessing, CheckpointerMain(), CheckpointerProcess, CreateAuxProcessResourceOwner(), elog(), IgnoreSystemIndexes, init_ps_display(), InitAuxiliaryProcess(), IsUnderPostmaster, MaxBackends, MyAuxProcType, MyBackendType, NormalProcessing, PANIC, PgArchiverMain(), pgstat_beinit(), pgstat_bestart(), proc_exit(), ProcSignalInit(), SetProcessingMode, ShutdownAuxiliaryProcess(), StartupProcess, StartupProcessMain(), WalReceiverMain(), WalReceiverProcess, WalWriterMain(), and WalWriterProcess.

Referenced by StartChildProcess().

◆ ShutdownAuxiliaryProcess()

static void ShutdownAuxiliaryProcess ( int  code,
Datum  arg 
)
static

Definition at line 178 of file auxprocess.c.

179 {
183 }
void ConditionVariableCancelSleep(void)
void LWLockReleaseAll(void)
Definition: lwlock.c:1901
static void pgstat_report_wait_end(void)
Definition: wait_event.h:284

References ConditionVariableCancelSleep(), LWLockReleaseAll(), and pgstat_report_wait_end().

Referenced by AuxiliaryProcessMain().

Variable Documentation

◆ MyAuxProcType

AuxProcType MyAuxProcType = NotAnAuxProcess

Definition at line 45 of file auxprocess.c.

Referenced by AuxiliaryProcessMain(), and pgstat_beinit().