PostgreSQL Source Code git master
postmaster.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * postmaster.h
4 * Exports from postmaster/postmaster.c.
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 * src/include/postmaster/postmaster.h
10 *
11 *-------------------------------------------------------------------------
12 */
13#ifndef _POSTMASTER_H
14#define _POSTMASTER_H
15
16#include "lib/ilist.h"
17#include "miscadmin.h"
18
19/*
20 * A struct representing an active postmaster child process. This is used
21 * mainly to keep track of how many children we have and send them appropriate
22 * signals when necessary. All postmaster child processes are assigned a
23 * PMChild entry. That includes "normal" client sessions, but also autovacuum
24 * workers, walsenders, background workers, and aux processes. (Note that at
25 * the time of launch, walsenders are labeled B_BACKEND; we relabel them to
26 * B_WAL_SENDER upon noticing they've changed their PMChildFlags entry. Hence
27 * that check must be done before any operation that needs to distinguish
28 * walsenders from normal backends.)
29 *
30 * "dead-end" children are also allocated a PMChild entry: these are children
31 * launched just for the purpose of sending a friendly rejection message to a
32 * would-be client. We must track them because they are attached to shared
33 * memory, but we know they will never become live backends.
34 *
35 * child_slot is an identifier that is unique across all running child
36 * processes. It is used as an index into the PMChildFlags array. dead-end
37 * children are not assigned a child_slot and have child_slot == 0 (valid
38 * child_slot ids start from 1).
39 */
40typedef struct
41{
42 pid_t pid; /* process id of backend */
43 int child_slot; /* PMChildSlot for this backend, if any */
44 BackendType bkend_type; /* child process flavor, see above */
45 struct RegisteredBgWorker *rw; /* bgworker info, if this is a bgworker */
46 bool bgworker_notify; /* gets bgworker start/stop notifications */
47 dlist_node elem; /* list link in ActiveChildList */
48} PMChild;
49
50#ifdef EXEC_BACKEND
51extern int num_pmchild_slots;
52#endif
53
54/* GUC options */
55extern PGDLLIMPORT bool EnableSSL;
62extern PGDLLIMPORT char *ListenAddresses;
64extern PGDLLIMPORT int PreAuthDelay;
67extern PGDLLIMPORT bool log_hostname;
68extern PGDLLIMPORT bool enable_bonjour;
69extern PGDLLIMPORT char *bonjour_name;
74
75#ifdef WIN32
76extern PGDLLIMPORT HANDLE PostmasterHandle;
77#else
79
80/*
81 * Constants that represent which of postmaster_alive_fds is held by
82 * postmaster, and which is used in children to check for postmaster death.
83 */
84#define POSTMASTER_FD_WATCH 0 /* used in children to check for
85 * postmaster death */
86#define POSTMASTER_FD_OWN 1 /* kept open by postmaster only */
87#endif
88
89extern PGDLLIMPORT const char *progname;
90
92extern PGDLLIMPORT bool LoadedSSL;
93
94extern void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn();
95extern void ClosePostmasterPorts(bool am_syslogger);
96extern void InitProcessGlobals(void);
97
98extern int MaxLivePostmasterChildren(void);
99
100extern bool PostmasterMarkPIDForWorkerNotify(int);
101
102#ifdef WIN32
103extern void pgwin32_register_deadchild_callback(HANDLE procHandle, DWORD procId);
104#endif
105
106/* defined in globals.c */
108
109/* prototypes for functions in launch_backend.c */
110extern pid_t postmaster_child_launch(BackendType child_type,
111 int child_slot,
112 char *startup_data,
113 size_t startup_data_len,
114 struct ClientSocket *client_sock);
115const char *PostmasterChildName(BackendType child_type);
116#ifdef EXEC_BACKEND
117extern void SubPostmasterMain(int argc, char *argv[]) pg_attribute_noreturn();
118#endif
119
120/* defined in pmchild.c */
122
123extern void InitPostmasterChildSlots(void);
125extern PMChild *AllocDeadEndChild(void);
126extern bool ReleasePostmasterChildSlot(PMChild *pmchild);
127extern PMChild *FindPostmasterChildByPid(int pid);
128
129/*
130 * Note: MAX_BACKENDS is limited to 2^18-1 because that's the width reserved
131 * for buffer references in buf_internals.h. This limitation could be lifted
132 * by using a 64bit state; but it's unlikely to be worthwhile as 2^18-1
133 * backends exceed currently realistic configurations. Even if that limitation
134 * were removed, we still could not a) exceed 2^23-1 because inval.c stores
135 * the ProcNumber as a 3-byte signed integer, b) INT_MAX/4 because some places
136 * compute 4*MaxBackends without any overflow check. This is rechecked in the
137 * relevant GUC check hooks and in RegisterBackgroundWorker().
138 */
139#define MAX_BACKENDS 0x3FFFF
140
141/*
142 * These values correspond to the special must-be-first options for dispatching
143 * to various subprograms. parse_dispatch_option() can be used to convert an
144 * option name to one of these values.
145 */
146typedef enum DispatchOption
153 DISPATCH_POSTMASTER, /* must be last */
155
156extern DispatchOption parse_dispatch_option(const char *name);
157
158#endif /* _POSTMASTER_H */
#define PGDLLIMPORT
Definition: c.h:1277
#define pg_attribute_noreturn()
Definition: c.h:239
BackendType
Definition: miscadmin.h:337
NON_EXEC_STATIC int num_pmchild_slots
Definition: pmchild.c:55
PGDLLIMPORT bool enable_bonjour
Definition: postmaster.c:242
PGDLLIMPORT bool log_hostname
Definition: postmaster.c:239
PGDLLIMPORT int PostPortNumber
Definition: postmaster.c:199
PGDLLIMPORT bool send_abort_for_kill
Definition: postmaster.c:254
PGDLLIMPORT int Unix_socket_permissions
Definition: pqcomm.c:106
PGDLLIMPORT char * ListenAddresses
Definition: postmaster.c:205
PGDLLIMPORT bool send_abort_for_crash
Definition: postmaster.c:253
void InitProcessGlobals(void)
Definition: postmaster.c:1919
PGDLLIMPORT int postmaster_alive_fds[2]
Definition: postmaster.c:473
PGDLLIMPORT char * Unix_socket_directories
Definition: postmaster.c:202
PGDLLIMPORT bool redirection_done
Definition: postmaster.c:371
PGDLLIMPORT const char * progname
Definition: main.c:44
PGDLLIMPORT int AuthenticationTimeout
Definition: postmaster.c:237
PGDLLIMPORT bool ClientAuthInProgress
Definition: postmaster.c:368
PGDLLIMPORT char * bonjour_name
Definition: postmaster.c:243
PMChild * AssignPostmasterChildSlot(BackendType btype)
Definition: pmchild.c:161
PGDLLIMPORT int SuperuserReservedConnections
Definition: postmaster.c:225
PGDLLIMPORT int PreAuthDelay
Definition: postmaster.c:236
bool ReleasePostmasterChildSlot(PMChild *pmchild)
Definition: pmchild.c:235
void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn()
Definition: postmaster.c:483
PGDLLIMPORT char * Unix_socket_group
Definition: pqcomm.c:107
DispatchOption
Definition: postmaster.h:146
@ DISPATCH_SINGLE
Definition: postmaster.h:151
@ DISPATCH_DESCRIBE_CONFIG
Definition: postmaster.h:150
@ DISPATCH_BOOT
Definition: postmaster.h:148
@ DISPATCH_CHECK
Definition: postmaster.h:147
@ DISPATCH_FORKCHILD
Definition: postmaster.h:149
@ DISPATCH_POSTMASTER
Definition: postmaster.h:152
bool PostmasterMarkPIDForWorkerNotify(int)
Definition: postmaster.c:4274
PGDLLIMPORT bool remove_temp_files_after_crash
Definition: postmaster.c:245
const char * PostmasterChildName(BackendType child_type)
DispatchOption parse_dispatch_option(const char *name)
Definition: main.c:243
void InitPostmasterChildSlots(void)
Definition: pmchild.c:86
PGDLLIMPORT int ReservedConnections
Definition: postmaster.c:226
PGDLLIMPORT bool LoadedSSL
PGDLLIMPORT bool Log_connections
Definition: postmaster.c:240
PGDLLIMPORT bool EnableSSL
Definition: postmaster.c:234
PMChild * AllocDeadEndChild(void)
Definition: pmchild.c:207
pid_t postmaster_child_launch(BackendType child_type, int child_slot, char *startup_data, size_t startup_data_len, struct ClientSocket *client_sock)
int MaxLivePostmasterChildren(void)
Definition: pmchild.c:70
dlist_head ActiveChildList
Definition: pmchild.c:60
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:1842
PMChild * FindPostmasterChildByPid(int pid)
Definition: pmchild.c:273
PGDLLIMPORT bool restart_after_crash
Definition: postmaster.c:244
PGDLLIMPORT struct ClientSocket * MyClientSocket
Definition: globals.c:49
struct RegisteredBgWorker * rw
Definition: postmaster.h:45
bool bgworker_notify
Definition: postmaster.h:46
BackendType bkend_type
Definition: postmaster.h:44
dlist_node elem
Definition: postmaster.h:47
pid_t pid
Definition: postmaster.h:42
int child_slot
Definition: postmaster.h:43
const char * name