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 (void) 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:1075
#define LOG
Definition: elog.h:31
bool has_startup_progress_timeout_expired(long *secs, int *usecs)
Definition: startup.c:355

Definition at line 18 of file startup.h.

Function Documentation

◆ begin_startup_progress_phase()

void begin_startup_progress_phase ( void  )

Definition at line 339 of file startup.c.

340 {
341  /* Feature is disabled. */
343  return;
344 
347 }
void disable_startup_progress_timeout(void)
Definition: startup.c:305
int log_startup_progress_interval
Definition: startup.c:77
void enable_startup_progress_timeout(void)
Definition: startup.c:319

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

306 {
307  /* Feature is disabled. */
309  return;
310 
313 }
static volatile sig_atomic_t startup_progress_timer_expired
Definition: startup.c:72
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 319 of file startup.c.

320 {
321  TimestampTz fin_time;
322 
323  /* Feature is disabled. */
325  return;
326 
332 }
static TimestampTz startup_progress_phase_start_time
Definition: startup.c:66
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1655
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 155 of file startup.c.

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

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

356 {
357  long seconds;
358  int useconds;
360 
361  /* No timeout has occurred. */
363  return false;
364 
365  /* Calculate the elapsed time. */
368 
369  *secs = seconds;
370  *usecs = useconds;
372 
373  return true;
374 }
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1731
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1619

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

◆ IsPromoteSignaled()

bool IsPromoteSignaled ( void  )

Definition at line 284 of file startup.c.

285 {
286  return promote_signaled;
287 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:55

References promote_signaled.

Referenced by CheckForStandbyTrigger().

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 278 of file startup.c.

279 {
280  in_restore_command = false;
281 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:61

References in_restore_command.

Referenced by RestoreArchivedFile().

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 264 of file startup.c.

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

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

◆ ResetPromoteSignaled()

void ResetPromoteSignaled ( void  )

Definition at line 290 of file startup.c.

291 {
292  promote_signaled = false;
293 }

References promote_signaled.

Referenced by CheckForStandbyTrigger().

◆ startup_progress_timeout_handler()

void startup_progress_timeout_handler ( void  )

Definition at line 299 of file startup.c.

300 {
302 }

References startup_progress_timer_expired.

Referenced by StartupXLOG().

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 217 of file startup.c.

218 {
219  /* Arrange to clean up at startup process exit */
221 
222  /*
223  * Properly accept or ignore signals the postmaster might send us.
224  */
225  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
226  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
227  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
228  /* SIGQUIT handler was already set up by InitPostmasterChild */
229  InitializeTimeouts(); /* establishes SIGALRM handler */
233 
234  /*
235  * Reset some signals that are accepted by postmaster but not here
236  */
238 
239  /*
240  * Register timeouts needed for standby mode
241  */
245 
246  /*
247  * Unblock signals (they were blocked when the postmaster forked us)
248  */
249  sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
250 
251  /*
252  * Do what we came for.
253  */
254  StartupXLOG();
255 
256  /*
257  * Exit normally. Exit code 0 tells postmaster that we completed recovery
258  * successfully.
259  */
260  proc_exit(0);
261 }
sigset_t UnBlockSig
Definition: pqsignal.c:22
static void StartupProcExit(int code, Datum arg)
Definition: startup.c:204
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:110
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:102
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:94
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:365
pqsigfunc pqsignal(int signo, pqsigfunc func)
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:639
void StandbyTimeoutHandler(void)
Definition: standby.c:945
void StandbyLockTimeoutHandler(void)
Definition: standby.c:954
void StandbyDeadLockHandler(void)
Definition: standby.c:936
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:5319

References InitializeTimeouts(), 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.

Referenced by AuxiliaryProcessMain().

Variable Documentation

◆ log_startup_progress_interval

PGDLLIMPORT int log_startup_progress_interval
extern