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 IsPromoteSignaled (void)
 
void ResetPromoteSignaled (void)
 

Function Documentation

◆ HandleStartupProcInterrupts()

void HandleStartupProcInterrupts ( void  )

Definition at line 135 of file startup.c.

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

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

136 {
137  /*
138  * Process any requests or signals received recently.
139  */
140  if (got_SIGHUP)
141  {
142  got_SIGHUP = false;
144  }
145 
146  /*
147  * Check if we were requested to exit without finishing recovery.
148  */
149  if (shutdown_requested)
150  proc_exit(1);
151 
152  /*
153  * Emergency bailout if postmaster has died. This is to avoid the
154  * necessity for manual cleanup of all postmaster children.
155  */
157  exit(1);
158 
159  /* Process barrier events */
162 }
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:452
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
static void StartupRereadConfig(void)
Definition: startup.c:106
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:35

◆ IsPromoteSignaled()

bool IsPromoteSignaled ( void  )

Definition at line 234 of file startup.c.

References promote_signaled.

Referenced by CheckForStandbyTrigger().

235 {
236  return promote_signaled;
237 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:42

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 228 of file startup.c.

References in_restore_command.

Referenced by RestoreArchivedFile().

229 {
230  in_restore_command = false;
231 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:48

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 214 of file startup.c.

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

215 {
216  /*
217  * Set in_restore_command to tell the signal handler that we should exit
218  * right away on SIGTERM. We know that we're at a safe point to do that.
219  * Check if we had already received the signal, so that we don't miss a
220  * shutdown request received just before this.
221  */
222  in_restore_command = true;
223  if (shutdown_requested)
224  proc_exit(1);
225 }
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

◆ ResetPromoteSignaled()

void ResetPromoteSignaled ( void  )

Definition at line 240 of file startup.c.

References promote_signaled.

Referenced by CheckForStandbyTrigger().

241 {
242  promote_signaled = false;
243 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:42

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 170 of file startup.c.

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

Referenced by AuxiliaryProcessMain().

171 {
172  /*
173  * Properly accept or ignore signals the postmaster might send us.
174  */
175  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
176  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
177  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
178  /* SIGQUIT handler was already set up by InitPostmasterChild */
179  InitializeTimeouts(); /* establishes SIGALRM handler */
183 
184  /*
185  * Reset some signals that are accepted by postmaster but not here
186  */
188 
189  /*
190  * Register timeouts needed for standby mode
191  */
195 
196  /*
197  * Unblock signals (they were blocked when the postmaster forked us)
198  */
200 
201  /*
202  * Do what we came for.
203  */
204  StartupXLOG();
205 
206  /*
207  * Exit normally. Exit code 0 tells postmaster that we completed recovery
208  * successfully.
209  */
210  proc_exit(0);
211 }
void InitializeTimeouts(void)
Definition: timeout.c:346
void StandbyTimeoutHandler(void)
Definition: standby.c:607
#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
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:74
#define SIGHUP
Definition: win32_port.h:153
void StandbyLockTimeoutHandler(void)
Definition: standby.c:620
void StandbyDeadLockHandler(void)
Definition: standby.c:596
sigset_t UnBlockSig
Definition: pqsignal.c:22
void StartupXLOG(void)
Definition: xlog.c:6303
#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:551