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

Definition at line 18 of file startup.h.

Function Documentation

◆ begin_startup_progress_phase()

void begin_startup_progress_phase ( void  )

Definition at line 321 of file startup.c.

322 {
323  TimestampTz fin_time;
324 
325  /* Feature is disabled. */
327  return;
328 
336 }
static volatile sig_atomic_t startup_progress_timer_expired
Definition: startup.c:73
static TimestampTz startup_progress_phase_start_time
Definition: startup.c:67
int log_startup_progress_interval
Definition: startup.c:78
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1574
int64 TimestampTz
Definition: timestamp.h:39
void enable_timeout_every(TimeoutId id, TimestampTz fin_time, int delay_ms)
Definition: timeout.c:588
void disable_timeout(TimeoutId id, bool keep_indicator)
Definition: timeout.c:689
@ STARTUP_PROGRESS_TIMEOUT
Definition: timeout.h:37
#define TimestampTzPlusMilliseconds(tz, ms)
Definition: timestamp.h:56

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

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

◆ HandleStartupProcInterrupts()

void HandleStartupProcInterrupts ( void  )

Definition at line 168 of file startup.c.

169 {
170 #ifdef POSTMASTER_POLL_RATE_LIMIT
171  static uint32 postmaster_poll_count = 0;
172 #endif
173 
174  /*
175  * Process any requests or signals received recently.
176  */
177  if (got_SIGHUP)
178  {
179  got_SIGHUP = false;
181  }
182 
183  /*
184  * Check if we were requested to exit without finishing recovery.
185  */
186  if (shutdown_requested)
187  proc_exit(1);
188 
189  /*
190  * Emergency bailout if postmaster has died. This is to avoid the
191  * necessity for manual cleanup of all postmaster children. Do this less
192  * frequently on systems for which we don't have signals to make that
193  * cheap.
194  */
195  if (IsUnderPostmaster &&
197  postmaster_poll_count++ % POSTMASTER_POLL_RATE_LIMIT == 0 &&
198 #endif
200  exit(1);
201 
202  /* Process barrier events */
205 
206  /* Perform logging of memory contexts of this process */
209 }
#define POSTMASTER_POLL_RATE_LIMIT
Definition: startup.c:48
static volatile sig_atomic_t shutdown_requested
Definition: startup.c:55
static volatile sig_atomic_t got_SIGHUP
Definition: startup.c:54
static void StartupRereadConfig(void)
Definition: startup.c:139
unsigned int uint32
Definition: c.h:441
volatile sig_atomic_t LogMemoryContextPending
Definition: globals.c:38
volatile sig_atomic_t ProcSignalBarrierPending
Definition: globals.c:37
bool IsUnderPostmaster
Definition: globals.c:113
void proc_exit(int code)
Definition: ipc.c:104
exit(1)
void ProcessLogMemoryContextInterrupt(void)
Definition: mcxt.c:1041
#define PostmasterIsAlive()
Definition: pmsignal.h:102
void ProcessProcSignalBarrier(void)
Definition: procsignal.c:467

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

345 {
346  long seconds;
347  int useconds;
349 
350  /* No timeout has occurred. */
352  return false;
353 
354  /* Calculate the elapsed time. */
357 
358  *secs = seconds;
359  *usecs = useconds;
361 
362  return true;
363 }
void TimestampDifference(TimestampTz start_time, TimestampTz stop_time, long *secs, int *microsecs)
Definition: timestamp.c:1650
Datum now(PG_FUNCTION_ARGS)
Definition: timestamp.c:1538

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

◆ IsPromoteSignaled()

bool IsPromoteSignaled ( void  )

Definition at line 297 of file startup.c.

298 {
299  return promote_signaled;
300 }
static volatile sig_atomic_t promote_signaled
Definition: startup.c:56

References promote_signaled.

Referenced by CheckForStandbyTrigger().

◆ PostRestoreCommand()

void PostRestoreCommand ( void  )

Definition at line 291 of file startup.c.

292 {
293  in_restore_command = false;
294 }
static volatile sig_atomic_t in_restore_command
Definition: startup.c:62

References in_restore_command.

Referenced by RestoreArchivedFile().

◆ PreRestoreCommand()

void PreRestoreCommand ( void  )

Definition at line 277 of file startup.c.

278 {
279  /*
280  * Set in_restore_command to tell the signal handler that we should exit
281  * right away on SIGTERM. We know that we're at a safe point to do that.
282  * Check if we had already received the signal, so that we don't miss a
283  * shutdown request received just before this.
284  */
285  in_restore_command = true;
286  if (shutdown_requested)
287  proc_exit(1);
288 }

References in_restore_command, proc_exit(), and shutdown_requested.

Referenced by RestoreArchivedFile().

◆ ResetPromoteSignaled()

void ResetPromoteSignaled ( void  )

Definition at line 303 of file startup.c.

304 {
305  promote_signaled = false;
306 }

References promote_signaled.

Referenced by CheckForStandbyTrigger().

◆ startup_progress_timeout_handler()

void startup_progress_timeout_handler ( void  )

Definition at line 312 of file startup.c.

313 {
315 }

References startup_progress_timer_expired.

Referenced by StartupXLOG().

◆ StartupProcessMain()

void StartupProcessMain ( void  )

Definition at line 230 of file startup.c.

231 {
232  /* Arrange to clean up at startup process exit */
234 
235  /*
236  * Properly accept or ignore signals the postmaster might send us.
237  */
238  pqsignal(SIGHUP, StartupProcSigHupHandler); /* reload config file */
239  pqsignal(SIGINT, SIG_IGN); /* ignore query cancel */
240  pqsignal(SIGTERM, StartupProcShutdownHandler); /* request shutdown */
241  /* SIGQUIT handler was already set up by InitPostmasterChild */
242  InitializeTimeouts(); /* establishes SIGALRM handler */
246 
247  /*
248  * Reset some signals that are accepted by postmaster but not here
249  */
251 
252  /*
253  * Register timeouts needed for standby mode
254  */
258 
259  /*
260  * Unblock signals (they were blocked when the postmaster forked us)
261  */
263 
264  /*
265  * Do what we came for.
266  */
267  StartupXLOG();
268 
269  /*
270  * Exit normally. Exit code 0 tells postmaster that we completed recovery
271  * successfully.
272  */
273  proc_exit(0);
274 }
sigset_t UnBlockSig
Definition: pqsignal.c:22
static void StartupProcExit(int code, Datum arg)
Definition: startup.c:217
static void StartupProcShutdownHandler(SIGNAL_ARGS)
Definition: startup.c:119
static void StartupProcSigHupHandler(SIGNAL_ARGS)
Definition: startup.c:107
static void StartupProcTriggerHandler(SIGNAL_ARGS)
Definition: startup.c:95
void on_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:361
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
void procsignal_sigusr1_handler(SIGNAL_ARGS)
Definition: procsignal.c:638
pqsigfunc pqsignal(int signum, pqsigfunc handler)
Definition: signal.c:180
void StandbyTimeoutHandler(void)
Definition: standby.c:907
void StandbyLockTimeoutHandler(void)
Definition: standby.c:916
void StandbyDeadLockHandler(void)
Definition: standby.c:898
void InitializeTimeouts(void)
Definition: timeout.c:474
TimeoutId RegisterTimeout(TimeoutId id, timeout_handler_proc handler)
Definition: timeout.c:509
@ 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:177
#define SIGHUP
Definition: win32_port.h:167
#define SIG_DFL
Definition: win32_port.h:162
#define SIGPIPE
Definition: win32_port.h:172
#define SIGUSR1
Definition: win32_port.h:179
#define SIGUSR2
Definition: win32_port.h:180
#define SIG_IGN
Definition: win32_port.h:164
void StartupXLOG(void)
Definition: xlog.c:4886

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

Variable Documentation

◆ log_startup_progress_interval

PGDLLIMPORT int log_startup_progress_interval
extern

Definition at line 78 of file startup.c.

Referenced by begin_startup_progress_phase().