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

132 {
133  /*
134  * Check if we were requested to re-read config file.
135  */
136  if (got_SIGHUP)
137  {
138  got_SIGHUP = false;
140  }
141 
142  /*
143  * Check if we were requested to exit without finishing recovery.
144  */
145  if (shutdown_requested)
146  proc_exit(1);
147 
148  /*
149  * Emergency bailout if postmaster has died. This is to avoid the
150  * necessity for manual cleanup of all postmaster children.
151  */
153  exit(1);
154 }
void ProcessConfigFile(GucContext context)
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:43
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t got_SIGHUP
Definition: startup.c:42
bool IsUnderPostmaster
Definition: globals.c:109
#define PostmasterIsAlive()
Definition: pmsignal.h:91
Definition: guc.h:72

◆ IsPromoteTriggered()

bool IsPromoteTriggered ( void  )

Definition at line 226 of file startup.c.

References promote_triggered.

Referenced by CheckForStandbyTrigger().

227 {
228  return promote_triggered;
229 }
static volatile sig_atomic_t promote_triggered
Definition: startup.c:44

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 220 of file startup.c.

References in_restore_command.

Referenced by RestoreArchivedFile().

221 {
222  in_restore_command = false;
223 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:50

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 206 of file startup.c.

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

207 {
208  /*
209  * Set in_restore_command to tell the signal handler that we should exit
210  * right away on SIGTERM. We know that we're at a safe point to do that.
211  * Check if we had already received the signal, so that we don't miss a
212  * shutdown request received just before this.
213  */
214  in_restore_command = true;
215  if (shutdown_requested)
216  proc_exit(1);
217 }
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:43
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t in_restore_command
Definition: startup.c:50

◆ ResetPromoteTriggered()

void ResetPromoteTriggered ( void  )

Definition at line 232 of file startup.c.

References promote_triggered.

Referenced by CheckForStandbyTrigger().

233 {
234  promote_triggered = false;
235 }
static volatile sig_atomic_t promote_triggered
Definition: startup.c:44

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 162 of file startup.c.

References InitializeTimeouts(), PG_SETMASK, pqsignal(), proc_exit(), procsignal_sigusr1_handler(), 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(), StartupProcTriggerHandler(), StartupXLOG(), and UnBlockSig.

Referenced by AuxiliaryProcessMain().

163 {
164  /*
165  * Properly accept or ignore signals the postmaster might send us.
166  */
167  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
168  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
169  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
170  pqsignal(SIGQUIT, startupproc_quickdie); /* hard crash time */
171  InitializeTimeouts(); /* establishes SIGALRM handler */
175 
176  /*
177  * Reset some signals that are accepted by postmaster but not here
178  */
180 
181  /*
182  * Register timeouts needed for standby mode
183  */
187 
188  /*
189  * Unblock signals (they were blocked when the postmaster forked us)
190  */
192 
193  /*
194  * Do what we came for.
195  */
196  StartupXLOG();
197 
198  /*
199  * Exit normally. Exit code 0 tells postmaster that we completed recovery
200  * successfully.
201  */
202  proc_exit(0);
203 }
void InitializeTimeouts(void)
Definition: timeout.c:346
#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:104
#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
void StartupXLOG(void)
Definition: xlog.c:6205
#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:380
#define SIG_DFL
Definition: win32_port.h:149
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:92
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:116
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:260