PostgreSQL Source Code  git master
startup.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void HandleStartupProcInterrupts (void)
 
void StartupProcessMain (void) pg_attribute_noreturn()
 
void PreRestoreCommand (void)
 
void PostRestoreCommand (void)
 
bool IsPromoteTriggered (void)
 
void ResetPromoteTriggered (void)
 

Function Documentation

◆ HandleStartupProcInterrupts()

void HandleStartupProcInterrupts ( void  )

Definition at line 101 of file startup.c.

References got_SIGHUP, IsUnderPostmaster, PGC_SIGHUP, PostmasterIsAlive, proc_exit(), ProcessConfigFile(), ProcessProcSignalBarrier(), ProcSignalBarrierPending, and shutdown_requested.

Referenced by recoveryApplyDelay(), recoveryPausesHere(), ShutdownWalRcv(), StartupXLOG(), and WaitForWALToBecomeAvailable().

102 {
103  /*
104  * Check if we were requested to re-read config file.
105  */
106  if (got_SIGHUP)
107  {
108  got_SIGHUP = false;
110  }
111 
112  /*
113  * Check if we were requested to exit without finishing recovery.
114  */
115  if (shutdown_requested)
116  proc_exit(1);
117 
118  /*
119  * Emergency bailout if postmaster has died. This is to avoid the
120  * necessity for manual cleanup of all postmaster children.
121  */
123  exit(1);
124 
125  /* Process barrier events */
128 }
void ProcessConfigFile(GucContext context)
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:429
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:41
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t got_SIGHUP
Definition: startup.c:40
bool IsUnderPostmaster
Definition: globals.c:109
#define PostmasterIsAlive()
Definition: pmsignal.h:91
Definition: guc.h:72
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:35

◆ IsPromoteTriggered()

bool IsPromoteTriggered ( void  )

Definition at line 200 of file startup.c.

References promote_triggered.

Referenced by CheckForStandbyTrigger().

201 {
202  return promote_triggered;
203 }
static volatile sig_atomic_t promote_triggered
Definition: startup.c:42

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 194 of file startup.c.

References in_restore_command.

Referenced by RestoreArchivedFile().

195 {
196  in_restore_command = false;
197 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:48

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 180 of file startup.c.

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

181 {
182  /*
183  * Set in_restore_command to tell the signal handler that we should exit
184  * right away on SIGTERM. We know that we're at a safe point to do that.
185  * Check if we had already received the signal, so that we don't miss a
186  * shutdown request received just before this.
187  */
188  in_restore_command = true;
189  if (shutdown_requested)
190  proc_exit(1);
191 }
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:41
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t in_restore_command
Definition: startup.c:48

◆ ResetPromoteTriggered()

void ResetPromoteTriggered ( void  )

Definition at line 206 of file startup.c.

References promote_triggered.

Referenced by CheckForStandbyTrigger().

207 {
208  promote_triggered = false;
209 }
static volatile sig_atomic_t promote_triggered
Definition: startup.c:42

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 136 of file startup.c.

References InitializeTimeouts(), PG_SETMASK, pqsignal(), proc_exit(), procsignal_sigusr1_handler(), RegisterTimeout(), SIG_DFL, SIG_IGN, SIGCHLD, SIGHUP, SignalHandlerForCrashExit(), SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, STANDBY_DEADLOCK_TIMEOUT, STANDBY_LOCK_TIMEOUT, STANDBY_TIMEOUT, StandbyDeadLockHandler(), StandbyLockTimeoutHandler(), StandbyTimeoutHandler(), StartupProcShutdownHandler(), StartupProcSigHupHandler(), StartupProcTriggerHandler(), StartupXLOG(), and UnBlockSig.

Referenced by AuxiliaryProcessMain().

137 {
138  /*
139  * Properly accept or ignore signals the postmaster might send us.
140  */
141  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
142  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
143  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
145  InitializeTimeouts(); /* establishes SIGALRM handler */
149 
150  /*
151  * Reset some signals that are accepted by postmaster but not here
152  */
154 
155  /*
156  * Register timeouts needed for standby mode
157  */
161 
162  /*
163  * Unblock signals (they were blocked when the postmaster forked us)
164  */
166 
167  /*
168  * Do what we came for.
169  */
170  StartupXLOG();
171 
172  /*
173  * Exit normally. Exit code 0 tells postmaster that we completed recovery
174  * successfully.
175  */
176  proc_exit(0);
177 }
void InitializeTimeouts(void)
Definition: timeout.c:346
#define SIGQUIT
Definition: win32_port.h:154
void StandbyTimeoutHandler(void)
Definition: standby.c:585
#define SIGUSR1
Definition: win32_port.h:165
#define SIGCHLD
Definition: win32_port.h:163
void proc_exit(int code)
Definition: ipc.c:104
#define SIGPIPE
Definition: win32_port.h:158
#define SIGUSR2
Definition: win32_port.h:166
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
void SignalHandlerForCrashExit(SIGNAL_ARGS)
Definition: interrupt.c:72
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:74
#define SIGHUP
Definition: win32_port.h:153
void StandbyLockTimeoutHandler(void)
Definition: standby.c:598
void StandbyDeadLockHandler(void)
Definition: standby.c:574
sigset_t UnBlockSig
Definition: pqsignal.c:22
void StartupXLOG(void)
Definition: xlog.c:6206
#define SIG_IGN
Definition: win32_port.h:150
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:380
#define SIG_DFL
Definition: win32_port.h:148
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:62
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:86
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:533