PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pmsignal.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * pmsignal.h
4 * routines for signaling between the postmaster and its child processes
5 *
6 *
7 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
9 *
10 * src/include/storage/pmsignal.h
11 *
12 *-------------------------------------------------------------------------
13 */
14#ifndef PMSIGNAL_H
15#define PMSIGNAL_H
16
17#include <signal.h>
18
19#ifdef HAVE_SYS_PRCTL_H
20#include "sys/prctl.h"
21#endif
22
23#ifdef HAVE_SYS_PROCCTL_H
24#include "sys/procctl.h"
25#endif
26
27/*
28 * Reasons for signaling the postmaster. We can cope with simultaneous
29 * signals for different reasons. If the same reason is signaled multiple
30 * times in quick succession, however, the postmaster is likely to observe
31 * only one notification of it. This is okay for the present uses.
32 */
33typedef enum
34{
35 PMSIGNAL_RECOVERY_STARTED, /* recovery has started */
36 PMSIGNAL_BEGIN_HOT_STANDBY, /* begin Hot Standby */
37 PMSIGNAL_ROTATE_LOGFILE, /* send SIGUSR1 to syslogger to rotate logfile */
38 PMSIGNAL_START_AUTOVAC_LAUNCHER, /* start an autovacuum launcher */
39 PMSIGNAL_START_AUTOVAC_WORKER, /* start an autovacuum worker */
40 PMSIGNAL_BACKGROUND_WORKER_CHANGE, /* background worker state change */
41 PMSIGNAL_START_WALRECEIVER, /* start a walreceiver */
42 PMSIGNAL_ADVANCE_STATE_MACHINE, /* advance postmaster's state machine */
44
45#define NUM_PMSIGNALS (PMSIGNAL_ADVANCE_STATE_MACHINE+1)
46
47/*
48 * Reasons why the postmaster would send SIGQUIT to its children.
49 */
50typedef enum
51{
52 PMQUIT_NOT_SENT = 0, /* postmaster hasn't sent SIGQUIT */
53 PMQUIT_FOR_CRASH, /* some other backend bought the farm */
54 PMQUIT_FOR_STOP, /* immediate stop was commanded */
56
57/* PMSignalData is an opaque struct, details known only within pmsignal.c */
59
60#ifdef EXEC_BACKEND
62#endif
63
64/*
65 * prototypes for functions in pmsignal.c
66 */
67extern Size PMSignalShmemSize(void);
68extern void PMSignalShmemInit(void);
69extern void SendPostmasterSignal(PMSignalReason reason);
70extern bool CheckPostmasterSignal(PMSignalReason reason);
71extern void SetQuitSignalReason(QuitSignalReason reason);
73extern void MarkPostmasterChildSlotAssigned(int slot);
74extern bool MarkPostmasterChildSlotUnassigned(int slot);
75extern bool IsPostmasterChildWalSender(int slot);
76extern void RegisterPostmasterChildActive(void);
77extern void MarkPostmasterChildWalSender(void);
78extern bool PostmasterIsAliveInternal(void);
79extern void PostmasterDeathSignalInit(void);
80
81
82/*
83 * Do we have a way to ask for a signal on parent death?
84 *
85 * If we do, pmsignal.c will set up a signal handler, that sets a flag when
86 * the parent dies. Checking the flag first makes PostmasterIsAlive() a lot
87 * cheaper in usual case that the postmaster is alive.
88 */
89#if (defined(HAVE_SYS_PRCTL_H) && defined(PR_SET_PDEATHSIG)) || \
90 (defined(HAVE_SYS_PROCCTL_H) && defined(PROC_PDEATHSIG_CTL))
91#define USE_POSTMASTER_DEATH_SIGNAL
92#endif
93
94#ifdef USE_POSTMASTER_DEATH_SIGNAL
95extern PGDLLIMPORT volatile sig_atomic_t postmaster_possibly_dead;
96
97static inline bool
99{
100 if (likely(!postmaster_possibly_dead))
101 return true;
103}
104#else
105#define PostmasterIsAlive() PostmasterIsAliveInternal()
106#endif
107
108#endif /* PMSIGNAL_H */
#define PGDLLIMPORT
Definition: c.h:1274
#define likely(x)
Definition: c.h:329
size_t Size
Definition: c.h:559
NON_EXEC_STATIC volatile PMSignalData * PMSignalState
Definition: pmsignal.c:84
#define PostmasterIsAlive()
Definition: pmsignal.h:105
Size PMSignalShmemSize(void)
Definition: pmsignal.c:130
bool CheckPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:182
bool PostmasterIsAliveInternal(void)
Definition: pmsignal.c:346
QuitSignalReason GetQuitSignalReason(void)
Definition: pmsignal.c:213
QuitSignalReason
Definition: pmsignal.h:51
@ PMQUIT_FOR_STOP
Definition: pmsignal.h:54
@ PMQUIT_FOR_CRASH
Definition: pmsignal.h:53
@ PMQUIT_NOT_SENT
Definition: pmsignal.h:52
void MarkPostmasterChildSlotAssigned(int slot)
Definition: pmsignal.c:230
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:165
void SetQuitSignalReason(QuitSignalReason reason)
Definition: pmsignal.c:202
bool MarkPostmasterChildSlotUnassigned(int slot)
Definition: pmsignal.c:249
void MarkPostmasterChildWalSender(void)
Definition: pmsignal.c:309
PMSignalReason
Definition: pmsignal.h:34
@ PMSIGNAL_START_AUTOVAC_WORKER
Definition: pmsignal.h:39
@ PMSIGNAL_RECOVERY_STARTED
Definition: pmsignal.h:35
@ PMSIGNAL_START_WALRECEIVER
Definition: pmsignal.h:41
@ PMSIGNAL_START_AUTOVAC_LAUNCHER
Definition: pmsignal.h:38
@ PMSIGNAL_BEGIN_HOT_STANDBY
Definition: pmsignal.h:36
@ PMSIGNAL_BACKGROUND_WORKER_CHANGE
Definition: pmsignal.h:40
@ PMSIGNAL_ROTATE_LOGFILE
Definition: pmsignal.h:37
@ PMSIGNAL_ADVANCE_STATE_MACHINE
Definition: pmsignal.h:42
bool IsPostmasterChildWalSender(int slot)
Definition: pmsignal.c:271
void RegisterPostmasterChildActive(void)
Definition: pmsignal.c:290
void PostmasterDeathSignalInit(void)
Definition: pmsignal.c:407
void PMSignalShmemInit(void)
Definition: pmsignal.c:145