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.

Macros

#define ereport_startup_progress(msg, ...)
 

Functions

void HandleStartupProcInterrupts (void)
 
void StartupProcessMain (char *startup_data, size_t startup_data_len) pg_attribute_noreturn()
 
void PreRestoreCommand (void)
 
void PostRestoreCommand (void)
 
bool IsPromoteSignaled (void)
 
void ResetPromoteSignaled (void)
 
void enable_startup_progress_timeout (void)
 
void disable_startup_progress_timeout (void)
 
void begin_startup_progress_phase (void)
 
void startup_progress_timeout_handler (void)
 
bool has_startup_progress_timeout_expired (long *secs, int *usecs)
 

Variables

PGDLLIMPORT int log_startup_progress_interval
 

Macro Definition Documentation

◆ ereport_startup_progress

#define ereport_startup_progress (   msg,
  ... 
)
Value:
do { \
long secs; \
int usecs; \
ereport(LOG, errmsg(msg, secs, (usecs / 10000), __VA_ARGS__ )); \
} while(0)
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define LOG
Definition: elog.h:31
bool has_startup_progress_timeout_expired(long *secs, int *usecs)
Definition: startup.c:359

Definition at line 18 of file startup.h.

Function Documentation

◆ begin_startup_progress_phase()

void begin_startup_progress_phase ( void  )

Definition at line 343 of file startup.c.

344 {
345  /* Feature is disabled. */
347  return;
348 
351 }
void disable_startup_progress_timeout(void)
Definition: startup.c:309
int log_startup_progress_interval
Definition: startup.c:76
void enable_startup_progress_timeout(void)
Definition: startup.c:323

References disable_startup_progress_timeout(), enable_startup_progress_timeout(), and log_startup_progress_interval.

Referenced by PerformWalRecovery(), ResetUnloggedRelations(), and SyncDataDirectory().

◆ disable_startup_progress_timeout()

void disable_startup_progress_timeout ( void  )

Definition at line 309 of file startup.c.

310 {
311  /* Feature is disabled. */
313  return;
314 
317 }
static volatile sig_atomic_t startup_progress_timer_expired
Definition: startup.c:71
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:685
@ STARTUP_PROGRESS_TIMEOUT
Definition: timeout.h:38

References disable_timeout(), log_startup_progress_interval, STARTUP_PROGRESS_TIMEOUT, and startup_progress_timer_expired.

Referenced by begin_startup_progress_phase(), and EnableStandbyMode().

◆ enable_startup_progress_timeout()

void enable_startup_progress_timeout ( void  )

Definition at line 323 of file startup.c.

324 {
325  TimestampTz fin_time;
326 
327  /* Feature is disabled. */
329  return;
330 
336 }
static TimestampTz startup_progress_phase_start_time
Definition: startup.c:65
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1644
int64 TimestampTz
Definition: timestamp.h:39
void enable_timeout_every(TimeoutId id, TimestampTz fin_time, int delay_ms)
Definition: timeout.c:584
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:85

References enable_timeout_every(), GetCurrentTimestamp(), log_startup_progress_interval, startup_progress_phase_start_time, STARTUP_PROGRESS_TIMEOUT, and TimestampTzPlusMilliseconds.

Referenced by begin_startup_progress_phase().

◆ HandleStartupProcInterrupts()

void HandleStartupProcInterrupts ( void  )

Definition at line 154 of file startup.c.

155 {
156 #ifdef POSTMASTER_POLL_RATE_LIMIT
157  static uint32 postmaster_poll_count = 0;
158 #endif
159 
160  /*
161  * Process any requests or signals received recently.
162  */
163  if (got_SIGHUP)
164  {
165  got_SIGHUP = false;
167  }
168 
169  /*
170  * Check if we were requested to exit without finishing recovery.
171  */
172  if (shutdown_requested)
173  proc_exit(1);
174 
175  /*
176  * Emergency bailout if postmaster has died. This is to avoid the
177  * necessity for manual cleanup of all postmaster children. Do this less
178  * frequently on systems for which we don't have signals to make that
179  * cheap.
180  */
181  if (IsUnderPostmaster &&
183  postmaster_poll_count++ % POSTMASTER_POLL_RATE_LIMIT == 0 &&
184 #endif
186  exit(1);
187 
188  /* Process barrier events */
191 
192  /* Perform logging of memory contexts of this process */
195 }
#define POSTMASTER_POLL_RATE_LIMIT
Definition: startup.c:46
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:53
static volatile sig_atomic_t got_SIGHUP
Definition: startup.c:52
static void StartupRereadConfig(void)
Definition: startup.c:125
unsigned int uint32
Definition: c.h:509
volatile sig_atomic_t LogMemoryContextPending
Definition: globals.c:40
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:39
bool IsUnderPostmaster
Definition: globals.c:119
void proc_exit(int code)
Definition: ipc.c:104
exit(1)
void ProcessLogMemoryContextInterrupt(void)
Definition: mcxt.c:1289
#define PostmasterIsAlive()
Definition: pmsignal.h:105
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:496

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

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

◆ has_startup_progress_timeout_expired()

bool has_startup_progress_timeout_expired ( long *  secs,
int *  usecs 
)

Definition at line 359 of file startup.c.

360 {
361  long seconds;
362  int useconds;
364 
365  /* No timeout has occurred. */
367  return false;
368 
369  /* Calculate the elapsed time. */
372 
373  *secs = seconds;
374  *usecs = useconds;
376 
377  return true;
378 }
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1720
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1608

References GetCurrentTimestamp(), now(), startup_progress_phase_start_time, startup_progress_timer_expired, and TimestampDifference().

◆ IsPromoteSignaled()

bool IsPromoteSignaled ( void  )

Definition at line 288 of file startup.c.

289 {
290  return promote_signaled;
291 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:54

References promote_signaled.

Referenced by CheckForStandbyTrigger().

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 282 of file startup.c.

283 {
284  in_restore_command = false;
285 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:60

References in_restore_command.

Referenced by RestoreArchivedFile().

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 268 of file startup.c.

269 {
270  /*
271  * Set in_restore_command to tell the signal handler that we should exit
272  * right away on SIGTERM. We know that we're at a safe point to do that.
273  * Check if we had already received the signal, so that we don't miss a
274  * shutdown request received just before this.
275  */
276  in_restore_command = true;
277  if (shutdown_requested)
278  proc_exit(1);
279 }

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

◆ ResetPromoteSignaled()

void ResetPromoteSignaled ( void  )

Definition at line 294 of file startup.c.

295 {
296  promote_signaled = false;
297 }

References promote_signaled.

Referenced by CheckForStandbyTrigger().

◆ startup_progress_timeout_handler()

void startup_progress_timeout_handler ( void  )

Definition at line 303 of file startup.c.

304 {
306 }

References startup_progress_timer_expired.

Referenced by StartupXLOG().

◆ StartupProcessMain()

void StartupProcessMain ( char *  startup_data,
size_t  startup_data_len 
)

Definition at line 216 of file startup.c.

217 {
218  Assert(startup_data_len == 0);
219 
222 
223  /* Arrange to clean up at startup process exit */
225 
226  /*
227  * Properly accept or ignore signals the postmaster might send us.
228  */
229  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
230  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
231  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
232  /* SIGQUIT handler was already set up by InitPostmasterChild */
233  InitializeTimeouts(); /* establishes SIGALRM handler */
237 
238  /*
239  * Reset some signals that are accepted by postmaster but not here
240  */
242 
243  /*
244  * Register timeouts needed for standby mode
245  */
249 
250  /*
251  * Unblock signals (they were blocked when the postmaster forked us)
252  */
253  sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
254 
255  /*
256  * Do what we came for.
257  */
258  StartupXLOG();
259 
260  /*
261  * Exit normally. Exit code 0 tells postmaster that we completed recovery
262  * successfully.
263  */
264  proc_exit(0);
265 }
void AuxiliaryProcessMainCommon(void)
Definition: auxprocess.c:44
sigset_t UnBlockSig
Definition: pqsignal.c:22
static void StartupProcExit(int code, Datum arg)
Definition: startup.c:203
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:109
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:101
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:93
#define Assert(condition)
Definition: c.h:861
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
@ B_STARTUP
Definition: miscadmin.h:355
BackendType MyBackendType
Definition: miscinit.c:63
pqsigfunc pqsignal(int signo, pqsigfunc func)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:671
void StandbyTimeoutHandler(void)
Definition: standby.c:944
void StandbyLockTimeoutHandler(void)
Definition: standby.c:953
void StandbyDeadLockHandler(void)
Definition: standby.c:935
void InitializeTimeouts(void)
Definition: timeout.c:470
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:505
@ STANDBY_LOCK_TIMEOUT
Definition: timeout.h:32
@ STANDBY_DEADLOCK_TIMEOUT
Definition: timeout.h:30
@ STANDBY_TIMEOUT
Definition: timeout.h:31
#define SIGCHLD
Definition: win32_port.h:178
#define SIGHUP
Definition: win32_port.h:168
#define SIG_DFL
Definition: win32_port.h:163
#define SIGPIPE
Definition: win32_port.h:173
#define SIGUSR1
Definition: win32_port.h:180
#define SIGUSR2
Definition: win32_port.h:181
#define SIG_IGN
Definition: win32_port.h:165
void StartupXLOG(void)
Definition: xlog.c:5422

References Assert, AuxiliaryProcessMainCommon(), B_STARTUP, InitializeTimeouts(), MyBackendType, on_shmem_exit(), 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.

Variable Documentation

◆ log_startup_progress_interval

PGDLLIMPORT int log_startup_progress_interval
extern