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 142 of file startup.c.

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

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

143 {
144  /*
145  * Check if we were requested to re-read config file.
146  */
147  if (got_SIGHUP)
148  {
149  got_SIGHUP = false;
151  }
152 
153  /*
154  * Check if we were requested to exit without finishing recovery.
155  */
156  if (shutdown_requested)
157  proc_exit(1);
158 
159  /*
160  * Emergency bailout if postmaster has died. This is to avoid the
161  * necessity for manual cleanup of all postmaster children.
162  */
164  exit(1);
165 }
void ProcessConfigFile(GucContext context)
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:42
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t got_SIGHUP
Definition: startup.c:41
bool IsUnderPostmaster
Definition: globals.c:109
#define PostmasterIsAlive()
Definition: pmsignal.h:91
Definition: guc.h:72

◆ IsPromoteTriggered()

bool IsPromoteTriggered ( void  )

Definition at line 237 of file startup.c.

References promote_triggered.

Referenced by CheckForStandbyTrigger().

238 {
239  return promote_triggered;
240 }
static volatile sig_atomic_t promote_triggered
Definition: startup.c:43

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 231 of file startup.c.

References in_restore_command.

Referenced by RestoreArchivedFile().

232 {
233  in_restore_command = false;
234 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:49

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 217 of file startup.c.

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

218 {
219  /*
220  * Set in_restore_command to tell the signal handler that we should exit
221  * right away on SIGTERM. We know that we're at a safe point to do that.
222  * Check if we had already received the signal, so that we don't miss a
223  * shutdown request received just before this.
224  */
225  in_restore_command = true;
226  if (shutdown_requested)
227  proc_exit(1);
228 }
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:42
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t in_restore_command
Definition: startup.c:49

◆ ResetPromoteTriggered()

void ResetPromoteTriggered ( void  )

Definition at line 243 of file startup.c.

References promote_triggered.

Referenced by CheckForStandbyTrigger().

244 {
245  promote_triggered = false;
246 }
static volatile sig_atomic_t promote_triggered
Definition: startup.c:43

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 173 of file startup.c.

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

Referenced by AuxiliaryProcessMain().

174 {
175  /*
176  * Properly accept or ignore signals the postmaster might send us.
177  */
178  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
179  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
180  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
181  pqsignal(SIGQUIT, startupproc_quickdie); /* hard crash time */
182  InitializeTimeouts(); /* establishes SIGALRM handler */
186 
187  /*
188  * Reset some signals that are accepted by postmaster but not here
189  */
191 
192  /*
193  * Register timeouts needed for standby mode
194  */
198 
199  /*
200  * Unblock signals (they were blocked when the postmaster forked us)
201  */
203 
204  /*
205  * Do what we came for.
206  */
207  StartupXLOG();
208 
209  /*
210  * Exit normally. Exit code 0 tells postmaster that we completed recovery
211  * successfully.
212  */
213  proc_exit(0);
214 }
void InitializeTimeouts(void)
Definition: timeout.c:340
#define SIGQUIT
Definition: win32_port.h:155
void StandbyTimeoutHandler(void)
Definition: standby.c:585
static void startupproc_quickdie(SIGNAL_ARGS)
Definition: startup.c:70
#define SIGUSR1
Definition: win32_port.h:166
#define SIGCHLD
Definition: win32_port.h:164
void proc_exit(int code)
Definition: ipc.c:104
#define SIGPIPE
Definition: win32_port.h:159
#define SIGUSR2
Definition: win32_port.h:167
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:115
#define SIGHUP
Definition: win32_port.h:154
void StandbyLockTimeoutHandler(void)
Definition: standby.c:598
void StandbyDeadLockHandler(void)
Definition: standby.c:574
sigset_t UnBlockSig
Definition: pqsignal.c:22
static void StartupProcSigUsr1Handler(SIGNAL_ARGS)
Definition: startup.c:92
void StartupXLOG(void)
Definition: xlog.c:6197
#define SIG_IGN
Definition: win32_port.h:151
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:373
#define SIG_DFL
Definition: win32_port.h:149
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:103
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:127