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

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

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

151 {
152 #ifdef POSTMASTER_POLL_RATE_LIMIT
153  static uint32 postmaster_poll_count = 0;
154 #endif
155 
156  /*
157  * Process any requests or signals received recently.
158  */
159  if (got_SIGHUP)
160  {
161  got_SIGHUP = false;
163  }
164 
165  /*
166  * Check if we were requested to exit without finishing recovery.
167  */
168  if (shutdown_requested)
169  proc_exit(1);
170 
171  /*
172  * Emergency bailout if postmaster has died. This is to avoid the
173  * necessity for manual cleanup of all postmaster children. Do this less
174  * frequently on systems for which we don't have signals to make that
175  * cheap.
176  */
177  if (IsUnderPostmaster &&
179  postmaster_poll_count++ % POSTMASTER_POLL_RATE_LIMIT == 0 &&
180 #endif
182  exit(1);
183 
184  /* Process barrier events */
187 }
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:453
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:53
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t got_SIGHUP
Definition: startup.c:52
#define POSTMASTER_POLL_RATE_LIMIT
Definition: startup.c:46
bool IsUnderPostmaster
Definition: globals.c:112
#define PostmasterIsAlive()
Definition: pmsignal.h:102
unsigned int uint32
Definition: c.h:441
static void StartupRereadConfig(void)
Definition: startup.c:121
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:37

◆ IsPromoteSignaled()

bool IsPromoteSignaled ( void  )

Definition at line 275 of file startup.c.

References promote_signaled.

Referenced by CheckForStandbyTrigger().

276 {
277  return promote_signaled;
278 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:54

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 269 of file startup.c.

References in_restore_command.

Referenced by RestoreArchivedFile().

270 {
271  in_restore_command = false;
272 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:60

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 255 of file startup.c.

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

256 {
257  /*
258  * Set in_restore_command to tell the signal handler that we should exit
259  * right away on SIGTERM. We know that we're at a safe point to do that.
260  * Check if we had already received the signal, so that we don't miss a
261  * shutdown request received just before this.
262  */
263  in_restore_command = true;
264  if (shutdown_requested)
265  proc_exit(1);
266 }
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:53
void proc_exit(int code)
Definition: ipc.c:104
static volatile sig_atomic_t in_restore_command
Definition: startup.c:60

◆ ResetPromoteSignaled()

void ResetPromoteSignaled ( void  )

Definition at line 281 of file startup.c.

References promote_signaled.

Referenced by CheckForStandbyTrigger().

282 {
283  promote_signaled = false;
284 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:54

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 208 of file startup.c.

References InitializeTimeouts(), on_shmem_exit(), 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(), StartupProcExit(), StartupProcShutdownHandler(), StartupProcSigHupHandler(), StartupProcTriggerHandler(), StartupXLOG(), and UnBlockSig.

Referenced by AuxiliaryProcessMain().

209 {
210  /* Arrange to clean up at startup process exit */
212 
213  /*
214  * Properly accept or ignore signals the postmaster might send us.
215  */
216  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
217  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
218  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
219  /* SIGQUIT handler was already set up by InitPostmasterChild */
220  InitializeTimeouts(); /* establishes SIGALRM handler */
224 
225  /*
226  * Reset some signals that are accepted by postmaster but not here
227  */
229 
230  /*
231  * Register timeouts needed for standby mode
232  */
236 
237  /*
238  * Unblock signals (they were blocked when the postmaster forked us)
239  */
241 
242  /*
243  * Do what we came for.
244  */
245  StartupXLOG();
246 
247  /*
248  * Exit normally. Exit code 0 tells postmaster that we completed recovery
249  * successfully.
250  */
251  proc_exit(0);
252 }
void InitializeTimeouts(void)
Definition: timeout.c:435
void StandbyTimeoutHandler(void)
Definition: standby.c:904
#define SIGUSR1
Definition: win32_port.h:171
#define SIGCHLD
Definition: win32_port.h:169
void proc_exit(int code)
Definition: ipc.c:104
#define SIGPIPE
Definition: win32_port.h:164
#define SIGUSR2
Definition: win32_port.h:172
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:89
#define SIGHUP
Definition: win32_port.h:159
void StandbyLockTimeoutHandler(void)
Definition: standby.c:916
void StandbyDeadLockHandler(void)
Definition: standby.c:893
sigset_t UnBlockSig
Definition: pqsignal.c:22
void StartupXLOG(void)
Definition: xlog.c:6495
#define SIG_IGN
Definition: win32_port.h:156
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:170
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:469
#define SIG_DFL
Definition: win32_port.h:154
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:77
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:101
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:642
static void StartupProcExit(int code, Datum arg)
Definition: startup.c:195