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 and access shared memory.
101  */
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  */
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  */
124 
125 
126  /* Initialize backend status information */
127  pgstat_beinit();
128  pgstat_bestart();
129 
130  /* register a before-shutdown callback for LWLock cleanup */
132 
134 
135  switch (MyAuxProcType)
136  {
137  case StartupProcess:
139  proc_exit(1);
140 
141  case ArchiverProcess:
142  PgArchiverMain();
143  proc_exit(1);
144 
145  case BgWriterProcess:
147  proc_exit(1);
148 
149  case CheckpointerProcess:
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 }
AuxProcType MyAuxProcType
Definition: auxprocess.c:45
static void ShutdownAuxiliaryProcess(int code, Datum arg)
Definition: auxprocess.c:175
void StartupProcessMain(void)
Definition: startup.c:245
void pgstat_beinit(void)
void pgstat_bestart(void)
void BackgroundWriterMain(void)
Definition: bgwriter.c:91
void CheckpointerMain(void)
Definition: checkpointer.c:172
#define PANIC
Definition: elog.h:42
bool IsUnderPostmaster
Definition: globals.c:115
int MaxBackends
Definition: globals.c:142
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:337
void proc_exit(int code)
Definition: ipc.c:104
Assert(fmt[strlen(fmt) - 1] !='\n')
@ NormalProcessing
Definition: miscadmin.h:412
@ BootstrapProcessing
Definition: miscadmin.h:410
#define SetProcessingMode(mode)
Definition: miscadmin.h:423
@ B_WAL_WRITER
Definition: miscadmin.h:343
@ B_WAL_RECEIVER
Definition: miscadmin.h:341
@ B_CHECKPOINTER
Definition: miscadmin.h:337
@ B_STARTUP
Definition: miscadmin.h:340
@ B_INVALID
Definition: miscadmin.h:330
@ B_BG_WRITER
Definition: miscadmin.h:336
@ B_ARCHIVER
Definition: miscadmin.h:331
@ BgWriterProcess
Definition: miscadmin.h:444
@ StartupProcess
Definition: miscadmin.h:443
@ ArchiverProcess
Definition: miscadmin.h:445
@ WalWriterProcess
Definition: miscadmin.h:447
@ WalReceiverProcess
Definition: miscadmin.h:448
@ CheckpointerProcess
Definition: miscadmin.h:446
bool IgnoreSystemIndexes
Definition: miscinit.c:80
BackendType MyBackendType
Definition: miscinit.c:63
void PgArchiverMain(void)
Definition: pgarch.c:212
void BaseInit(void)
Definition: postinit.c:629
void ProcSignalInit(int pss_idx)
Definition: procsignal.c:162
void init_ps_display(const char *fixed_part)
Definition: ps_status.c:242
void CreateAuxProcessResourceOwner(void)
Definition: resowner.c:983
void InitAuxiliaryProcess(void)
Definition: proc.c:519
void WalReceiverMain(void)
Definition: walreceiver.c:186
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 175 of file auxprocess.c.

176 {
180 }
bool ConditionVariableCancelSleep(void)
void LWLockReleaseAll(void)
Definition: lwlock.c:1903
static void pgstat_report_wait_end(void)
Definition: wait_event.h:104

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().