PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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
52#endif
53
54/* GUC options */
55extern PGDLLIMPORT bool EnableSSL;
62extern PGDLLIMPORT char *ListenAddresses;
64extern PGDLLIMPORT int PreAuthDelay;
66extern PGDLLIMPORT bool log_hostname;
67extern PGDLLIMPORT bool enable_bonjour;
68extern PGDLLIMPORT char *bonjour_name;
73
74#ifdef WIN32
75extern PGDLLIMPORT HANDLE PostmasterHandle;
76#else
78
79/*
80 * Constants that represent which of postmaster_alive_fds is held by
81 * postmaster, and which is used in children to check for postmaster death.
82 */
83#define POSTMASTER_FD_WATCH 0 /* used in children to check for
84 * postmaster death */
85#define POSTMASTER_FD_OWN 1 /* kept open by postmaster only */
86#endif
87
88extern PGDLLIMPORT const char *progname;
89
91extern PGDLLIMPORT bool LoadedSSL;
92
93pg_noreturn extern void PostmasterMain(int argc, char *argv[]);
94extern void ClosePostmasterPorts(bool am_syslogger);
95extern void InitProcessGlobals(void);
96
97extern int MaxLivePostmasterChildren(void);
98
100
101#ifdef WIN32
102extern void pgwin32_register_deadchild_callback(HANDLE procHandle, DWORD procId);
103#endif
104
105/* defined in globals.c */
107
108/* prototypes for functions in launch_backend.c */
109extern pid_t postmaster_child_launch(BackendType child_type,
110 int child_slot,
111 const void *startup_data,
112 size_t startup_data_len,
113 struct ClientSocket *client_sock);
114const char *PostmasterChildName(BackendType child_type);
115#ifdef EXEC_BACKEND
116pg_noreturn extern void SubPostmasterMain(int argc, char *argv[]);
117#endif
118
119/* defined in pmchild.c */
121
122extern void InitPostmasterChildSlots(void);
124extern PMChild *AllocDeadEndChild(void);
125extern bool ReleasePostmasterChildSlot(PMChild *pmchild);
126extern PMChild *FindPostmasterChildByPid(int pid);
127
128/*
129 * These values correspond to the special must-be-first options for dispatching
130 * to various subprograms. parse_dispatch_option() can be used to convert an
131 * option name to one of these values.
132 */
133typedef enum DispatchOption
140 DISPATCH_POSTMASTER, /* must be last */
142
143extern DispatchOption parse_dispatch_option(const char *name);
144
145#endif /* _POSTMASTER_H */
#define PGDLLIMPORT
Definition: c.h:1291
#define pg_noreturn
Definition: c.h:165
BackendType
Definition: miscadmin.h:338
NON_EXEC_STATIC int num_pmchild_slots
Definition: pmchild.c:55
PGDLLIMPORT bool enable_bonjour
Definition: postmaster.c:245
PGDLLIMPORT bool log_hostname
Definition: postmaster.c:243
PGDLLIMPORT int PostPortNumber
Definition: postmaster.c:203
PGDLLIMPORT bool send_abort_for_kill
Definition: postmaster.c:257
PGDLLIMPORT int Unix_socket_permissions
Definition: pqcomm.c:106
PGDLLIMPORT char * ListenAddresses
Definition: postmaster.c:209
PGDLLIMPORT bool send_abort_for_crash
Definition: postmaster.c:256
void InitProcessGlobals(void)
Definition: postmaster.c:1932
pg_noreturn void PostmasterMain(int argc, char *argv[])
Definition: postmaster.c:493
PGDLLIMPORT int postmaster_alive_fds[2]
Definition: postmaster.c:483
PGDLLIMPORT char * Unix_socket_directories
Definition: postmaster.c:206
PGDLLIMPORT dlist_head ActiveChildList
Definition: pmchild.c:60
PGDLLIMPORT bool redirection_done
Definition: postmaster.c:375
PGDLLIMPORT const char * progname
Definition: main.c:44
PGDLLIMPORT int AuthenticationTimeout
Definition: postmaster.c:241
PGDLLIMPORT bool ClientAuthInProgress
Definition: postmaster.c:372
PGDLLIMPORT char * bonjour_name
Definition: postmaster.c:246
PMChild * AssignPostmasterChildSlot(BackendType btype)
Definition: pmchild.c:162
PGDLLIMPORT int SuperuserReservedConnections
Definition: postmaster.c:229
PGDLLIMPORT int PreAuthDelay
Definition: postmaster.c:240
bool ReleasePostmasterChildSlot(PMChild *pmchild)
Definition: pmchild.c:236
PGDLLIMPORT char * Unix_socket_group
Definition: pqcomm.c:107
DispatchOption
Definition: postmaster.h:133
@ DISPATCH_SINGLE
Definition: postmaster.h:138
@ DISPATCH_DESCRIBE_CONFIG
Definition: postmaster.h:137
@ DISPATCH_BOOT
Definition: postmaster.h:135
@ DISPATCH_CHECK
Definition: postmaster.h:134
@ DISPATCH_FORKCHILD
Definition: postmaster.h:136
@ DISPATCH_POSTMASTER
Definition: postmaster.h:139
bool PostmasterMarkPIDForWorkerNotify(int)
Definition: postmaster.c:4436
PGDLLIMPORT bool remove_temp_files_after_crash
Definition: postmaster.c:248
const char * PostmasterChildName(BackendType child_type)
DispatchOption parse_dispatch_option(const char *name)
Definition: main.c:240
void InitPostmasterChildSlots(void)
Definition: pmchild.c:86
PGDLLIMPORT int ReservedConnections
Definition: postmaster.c:230
PGDLLIMPORT bool LoadedSSL
PGDLLIMPORT bool EnableSSL
Definition: postmaster.c:238
PMChild * AllocDeadEndChild(void)
Definition: pmchild.c:208
int MaxLivePostmasterChildren(void)
Definition: pmchild.c:70
void ClosePostmasterPorts(bool am_syslogger)
Definition: postmaster.c:1855
PMChild * FindPostmasterChildByPid(int pid)
Definition: pmchild.c:274
pid_t postmaster_child_launch(BackendType child_type, int child_slot, const void *startup_data, size_t startup_data_len, struct ClientSocket *client_sock)
PGDLLIMPORT bool restart_after_crash
Definition: postmaster.c:247
PGDLLIMPORT struct ClientSocket * MyClientSocket
Definition: globals.c:51
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