PostgreSQL Source Code git master
Loading...
Searching...
No Matches
postmaster.h File Reference
#include "lib/ilist.h"
#include "miscadmin.h"
Include dependency graph for postmaster.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PMChild
 

Macros

#define POSTMASTER_FD_WATCH
 
#define POSTMASTER_FD_OWN   1 /* kept open by postmaster only */
 

Typedefs

typedef enum DispatchOption DispatchOption
 

Enumerations

enum  DispatchOption {
  DISPATCH_CHECK , DISPATCH_BOOT , DISPATCH_FORKCHILD , DISPATCH_DESCRIBE_CONFIG ,
  DISPATCH_SINGLE , DISPATCH_POSTMASTER
}
 

Functions

pg_noreturn void PostmasterMain (int argc, char *argv[])
 
void ClosePostmasterPorts (bool am_syslogger)
 
void InitProcessGlobals (void)
 
int MaxLivePostmasterChildren (void)
 
bool PostmasterMarkPIDForWorkerNotify (int)
 
pid_t postmaster_child_launch (BackendType child_type, int child_slot, void *startup_data, size_t startup_data_len, const struct ClientSocket *client_sock)
 
const charPostmasterChildName (BackendType child_type)
 
void InitPostmasterChildSlots (void)
 
PMChildAssignPostmasterChildSlot (BackendType btype)
 
PMChildAllocDeadEndChild (void)
 
bool ReleasePostmasterChildSlot (PMChild *pmchild)
 
PMChildFindPostmasterChildByPid (int pid)
 
DispatchOption parse_dispatch_option (const char *name)
 

Variables

PGDLLIMPORT bool EnableSSL
 
PGDLLIMPORT int SuperuserReservedConnections
 
PGDLLIMPORT int ReservedConnections
 
PGDLLIMPORT int PostPortNumber
 
PGDLLIMPORT int Unix_socket_permissions
 
PGDLLIMPORT charUnix_socket_group
 
PGDLLIMPORT charUnix_socket_directories
 
PGDLLIMPORT charListenAddresses
 
PGDLLIMPORT bool ClientAuthInProgress
 
PGDLLIMPORT int PreAuthDelay
 
PGDLLIMPORT int AuthenticationTimeout
 
PGDLLIMPORT bool log_hostname
 
PGDLLIMPORT bool enable_bonjour
 
PGDLLIMPORT charbonjour_name
 
PGDLLIMPORT bool restart_after_crash
 
PGDLLIMPORT bool remove_temp_files_after_crash
 
PGDLLIMPORT bool send_abort_for_crash
 
PGDLLIMPORT bool send_abort_for_kill
 
PGDLLIMPORT int postmaster_alive_fds [2]
 
PGDLLIMPORT const charprogname
 
PGDLLIMPORT bool redirection_done
 
PGDLLIMPORT bool LoadedSSL
 
PGDLLIMPORT struct ClientSocketMyClientSocket
 
PGDLLIMPORT dlist_head ActiveChildList
 

Macro Definition Documentation

◆ POSTMASTER_FD_OWN

#define POSTMASTER_FD_OWN   1 /* kept open by postmaster only */

Definition at line 84 of file postmaster.h.

◆ POSTMASTER_FD_WATCH

#define POSTMASTER_FD_WATCH
Value:
0 /* used in children to check for
* postmaster death */

Definition at line 83 of file postmaster.h.

134{
140 DISPATCH_POSTMASTER, /* must be last */
142
143extern DispatchOption parse_dispatch_option(const char *name);
144
145#endif /* _POSTMASTER_H */
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
DispatchOption parse_dispatch_option(const char *name)
Definition main.c:244
const char * name

Typedef Documentation

◆ DispatchOption

Enumeration Type Documentation

◆ DispatchOption

Enumerator
DISPATCH_CHECK 
DISPATCH_BOOT 
DISPATCH_FORKCHILD 
DISPATCH_DESCRIBE_CONFIG 
DISPATCH_SINGLE 
DISPATCH_POSTMASTER 

Definition at line 132 of file postmaster.h.

Function Documentation

◆ AllocDeadEndChild()

PMChild * AllocDeadEndChild ( void  )
extern

Definition at line 224 of file pmchild.c.

225{
227
228 elog(DEBUG2, "allocating dead-end child");
229
231 if (pmchild)
232 {
233 pmchild->pid = 0;
234 pmchild->child_slot = 0;
235 pmchild->bkend_type = B_DEAD_END_BACKEND;
236 pmchild->rw = NULL;
237 pmchild->bgworker_notify = false;
238
240 }
241
242 return pmchild;
243}
#define DEBUG2
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:228
#define MCXT_ALLOC_NO_OOM
Definition fe_memutils.h:29
static void dlist_push_head(dlist_head *head, dlist_node *node)
Definition ilist.h:347
void * palloc_extended(Size size, int flags)
Definition mcxt.c:1439
@ B_DEAD_END_BACKEND
Definition miscadmin.h:355
dlist_head ActiveChildList
Definition pmchild.c:60
static int fb(int x)

References ActiveChildList, B_DEAD_END_BACKEND, DEBUG2, dlist_push_head(), elog, fb(), MCXT_ALLOC_NO_OOM, and palloc_extended().

Referenced by BackendStartup().

◆ AssignPostmasterChildSlot()

PMChild * AssignPostmasterChildSlot ( BackendType  btype)
extern

Definition at line 178 of file pmchild.c.

179{
180 dlist_head *freelist;
182
183 if (pmchild_pools[btype].size == 0)
184 elog(ERROR, "cannot allocate a PMChild slot for backend type %d", btype);
185
186 freelist = &pmchild_pools[btype].freelist;
187 if (dlist_is_empty(freelist))
188 return NULL;
189
191 pmchild->pid = 0;
192 pmchild->bkend_type = btype;
193 pmchild->rw = NULL;
194 pmchild->bgworker_notify = true;
195
196 /*
197 * pmchild->child_slot for each entry was initialized when the array of
198 * slots was allocated. Sanity check it.
199 */
200 if (!(pmchild->child_slot >= pmchild_pools[btype].first_slotno &&
201 pmchild->child_slot < pmchild_pools[btype].first_slotno + pmchild_pools[btype].size))
202 {
203 elog(ERROR, "pmchild freelist for backend type %d is corrupt",
204 pmchild->bkend_type);
205 }
206
208
209 /* Update the status in the shared memory array */
211
212 elog(DEBUG2, "assigned pm child slot %d for %s",
213 pmchild->child_slot, PostmasterChildName(btype));
214
215 return pmchild;
216}
#define ERROR
Definition elog.h:40
static dlist_node * dlist_pop_head_node(dlist_head *head)
Definition ilist.h:450
static bool dlist_is_empty(const dlist_head *head)
Definition ilist.h:336
#define dlist_container(type, membername, ptr)
Definition ilist.h:593
const char * PostmasterChildName(BackendType child_type)
static PMChildPool pmchild_pools[BACKEND_NUM_TYPES]
Definition pmchild.c:54
void MarkPostmasterChildSlotAssigned(int slot)
Definition pmsignal.c:229
int first_slotno
Definition pmchild.c:50
dlist_head freelist
Definition pmchild.c:51

References ActiveChildList, DEBUG2, dlist_container, dlist_is_empty(), dlist_pop_head_node(), dlist_push_head(), elog, ERROR, fb(), PMChildPool::first_slotno, PMChildPool::freelist, MarkPostmasterChildSlotAssigned(), pmchild_pools, PostmasterChildName(), and PMChildPool::size.

Referenced by BackendStartup(), StartBackgroundWorker(), StartChildProcess(), and StartSysLogger().

◆ ClosePostmasterPorts()

void ClosePostmasterPorts ( bool  am_syslogger)
extern

Definition at line 1880 of file postmaster.c.

1881{
1882 /* Release resources held by the postmaster's WaitEventSet. */
1883 if (pm_wait_set)
1884 {
1886 pm_wait_set = NULL;
1887 }
1888
1889#ifndef WIN32
1890
1891 /*
1892 * Close the write end of postmaster death watch pipe. It's important to
1893 * do this as early as possible, so that if postmaster dies, others won't
1894 * think that it's still running because we're holding the pipe open.
1895 */
1897 ereport(FATAL,
1899 errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
1901 /* Notify fd.c that we released one pipe FD. */
1903#endif
1904
1905 /*
1906 * Close the postmaster's listen sockets. These aren't tracked by fd.c,
1907 * so we don't call ReleaseExternalFD() here.
1908 *
1909 * The listen sockets are marked as FD_CLOEXEC, so this isn't needed in
1910 * EXEC_BACKEND mode.
1911 */
1912#ifndef EXEC_BACKEND
1913 if (ListenSockets)
1914 {
1915 for (int i = 0; i < NumListenSockets; i++)
1916 {
1917 if (closesocket(ListenSockets[i]) != 0)
1918 elog(LOG, "could not close listen socket: %m");
1919 }
1921 }
1922 NumListenSockets = 0;
1924#endif
1925
1926 /*
1927 * If using syslogger, close the read side of the pipe. We don't bother
1928 * tracking this in fd.c, either.
1929 */
1930 if (!am_syslogger)
1931 {
1932#ifndef WIN32
1933 if (syslogPipe[0] >= 0)
1934 close(syslogPipe[0]);
1935 syslogPipe[0] = -1;
1936#else
1937 if (syslogPipe[0])
1939 syslogPipe[0] = 0;
1940#endif
1941 }
1942
1943#ifdef USE_BONJOUR
1944 /* If using Bonjour, close the connection to the mDNS daemon */
1945 if (bonjour_sdref)
1947#endif
1948}
int errcode_for_file_access(void)
Definition elog.c:897
#define LOG
Definition elog.h:32
#define FATAL
Definition elog.h:42
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define ereport(elevel,...)
Definition elog.h:152
void ReleaseExternalFD(void)
Definition fd.c:1225
#define close(a)
Definition win32.h:12
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1616
#define closesocket
Definition port.h:397
static pgsocket * ListenSockets
Definition postmaster.c:236
static int NumListenSockets
Definition postmaster.c:235
int postmaster_alive_fds[2]
Definition postmaster.c:486
static WaitEventSet * pm_wait_set
Definition postmaster.c:400
#define POSTMASTER_FD_OWN
Definition postmaster.h:84
int syslogPipe[2]
Definition syslogger.c:115
void FreeWaitEventSetAfterFork(WaitEventSet *set)

References close, closesocket, elog, ereport, errcode_for_file_access(), errmsg_internal(), FATAL, fb(), FreeWaitEventSetAfterFork(), i, ListenSockets, LOG, NumListenSockets, pfree(), pm_wait_set, postmaster_alive_fds, POSTMASTER_FD_OWN, ReleaseExternalFD(), and syslogPipe.

Referenced by postmaster_child_launch().

◆ FindPostmasterChildByPid()

PMChild * FindPostmasterChildByPid ( int  pid)
extern

Definition at line 290 of file pmchild.c.

291{
292 dlist_iter iter;
293
295 {
296 PMChild *bp = dlist_container(PMChild, elem, iter.cur);
297
298 if (bp->pid == pid)
299 return bp;
300 }
301 return NULL;
302}
#define dlist_foreach(iter, lhead)
Definition ilist.h:623
dlist_node * cur
Definition ilist.h:179

References ActiveChildList, dlist_iter::cur, dlist_container, dlist_foreach, and fb().

Referenced by process_pm_child_exit().

◆ InitPostmasterChildSlots()

void InitPostmasterChildSlots ( void  )
extern

Definition at line 97 of file pmchild.c.

98{
99 int slotno;
100 PMChild *slots;
101
102 /*
103 * We allow more connections here than we can have backends because some
104 * might still be authenticating; they might fail auth, or some existing
105 * backend might exit before the auth cycle is completed. The exact
106 * MaxConnections limit is enforced when a new backend tries to join the
107 * PGPROC array.
108 *
109 * WAL senders start out as regular backends, so they share the same pool.
110 */
112
116
117 /*
118 * There can be only one of each of these running at a time. They each
119 * get their own pool of just one entry.
120 */
131
132 /* The rest of the pmchild_pools are left at zero size */
133
134 /* Count the total number of slots */
136 for (int i = 0; i < BACKEND_NUM_TYPES; i++)
138
139 /* Allocate enough slots, and make sure Valgrind doesn't complain */
140 slots = palloc(num_pmchild_slots * sizeof(PMChild));
141#ifdef USE_VALGRIND
142 pmchild_array = slots;
143#endif
144
145 /* Initialize them */
146 slotno = 0;
147 for (int btype = 0; btype < BACKEND_NUM_TYPES; btype++)
148 {
149 pmchild_pools[btype].first_slotno = slotno + 1;
150 dlist_init(&pmchild_pools[btype].freelist);
151
152 for (int j = 0; j < pmchild_pools[btype].size; j++)
153 {
154 slots[slotno].pid = 0;
155 slots[slotno].child_slot = slotno + 1;
156 slots[slotno].bkend_type = B_INVALID;
157 slots[slotno].rw = NULL;
158 slots[slotno].bgworker_notify = false;
159 dlist_push_tail(&pmchild_pools[btype].freelist, &slots[slotno].elem);
160 slotno++;
161 }
162 }
164
165 /* Initialize other structures */
167}
int autovacuum_worker_slots
Definition autovacuum.c:124
#define Assert(condition)
Definition c.h:943
int MaxConnections
Definition globals.c:145
int max_worker_processes
Definition globals.c:146
static void dlist_init(dlist_head *head)
Definition ilist.h:314
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition ilist.h:364
int j
Definition isn.c:78
void * palloc(Size size)
Definition mcxt.c:1387
#define BACKEND_NUM_TYPES
Definition miscadmin.h:392
@ B_WAL_SUMMARIZER
Definition miscadmin.h:379
@ B_WAL_WRITER
Definition miscadmin.h:380
@ B_WAL_RECEIVER
Definition miscadmin.h:378
@ B_CHECKPOINTER
Definition miscadmin.h:375
@ B_IO_WORKER
Definition miscadmin.h:376
@ B_LOGGER
Definition miscadmin.h:389
@ B_STARTUP
Definition miscadmin.h:377
@ B_BG_WORKER
Definition miscadmin.h:358
@ B_INVALID
Definition miscadmin.h:351
@ B_BG_WRITER
Definition miscadmin.h:374
@ B_BACKEND
Definition miscadmin.h:354
@ B_ARCHIVER
Definition miscadmin.h:373
@ B_AUTOVAC_LAUNCHER
Definition miscadmin.h:356
@ B_SLOTSYNC_WORKER
Definition miscadmin.h:360
@ B_AUTOVAC_WORKER
Definition miscadmin.h:357
NON_EXEC_STATIC int num_pmchild_slots
Definition pmchild.c:55
#define MAX_IO_WORKERS
Definition proc.h:526
struct RegisteredBgWorker * rw
Definition postmaster.h:45
bool bgworker_notify
Definition postmaster.h:46
BackendType bkend_type
Definition postmaster.h:44
pid_t pid
Definition postmaster.h:42
int child_slot
Definition postmaster.h:43
int max_wal_senders
Definition walsender.c:141

References ActiveChildList, Assert, autovacuum_worker_slots, B_ARCHIVER, B_AUTOVAC_LAUNCHER, B_AUTOVAC_WORKER, B_BACKEND, B_BG_WORKER, B_BG_WRITER, B_CHECKPOINTER, B_INVALID, B_IO_WORKER, B_LOGGER, B_SLOTSYNC_WORKER, B_STARTUP, B_WAL_RECEIVER, B_WAL_SUMMARIZER, B_WAL_WRITER, BACKEND_NUM_TYPES, PMChild::bgworker_notify, PMChild::bkend_type, PMChild::child_slot, dlist_init(), dlist_push_tail(), fb(), PMChildPool::first_slotno, i, j, MAX_IO_WORKERS, max_wal_senders, max_worker_processes, MaxConnections, num_pmchild_slots, palloc(), PMChild::pid, pmchild_pools, PMChild::rw, and PMChildPool::size.

Referenced by BootstrapModeMain(), PostgresSingleUserMain(), and PostmasterMain().

◆ InitProcessGlobals()

void InitProcessGlobals ( void  )
extern

Definition at line 1957 of file postmaster.c.

1958{
1961
1962 /* initialize timing infrastructure (required for INSTR_* calls) */
1964
1965 /*
1966 * Set a different global seed in every process. We want something
1967 * unpredictable, so if possible, use high-quality random bits for the
1968 * seed. Otherwise, fall back to a seed based on timestamp and PID.
1969 */
1971 {
1972 uint64 rseed;
1973
1974 /*
1975 * Since PIDs and timestamps tend to change more frequently in their
1976 * least significant bits, shift the timestamp left to allow a larger
1977 * total number of seeds in a given time period. Since that would
1978 * leave only 20 bits of the timestamp that cycle every ~1 second,
1979 * also mix in some higher bits.
1980 */
1981 rseed = ((uint64) MyProcPid) ^
1982 ((uint64) MyStartTimestamp << 12) ^
1983 ((uint64) MyStartTimestamp >> 20);
1984
1986 }
1987
1988 /*
1989 * Also make sure that we've set a good seed for random(3). Use of that
1990 * is deprecated in core Postgres, but extensions might use it.
1991 */
1992#ifndef WIN32
1994#endif
1995}
TimestampTz GetCurrentTimestamp(void)
Definition timestamp.c:1639
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition timestamp.c:1836
uint64_t uint64
Definition c.h:625
#define unlikely(x)
Definition c.h:438
int MyProcPid
Definition globals.c:49
TimestampTz MyStartTimestamp
Definition globals.c:51
pg_time_t MyStartTime
Definition globals.c:50
void pg_initialize_timing(void)
Definition instr_time.c:82
uint32 pg_prng_uint32(pg_prng_state *state)
Definition pg_prng.c:227
void pg_prng_seed(pg_prng_state *state, uint64 seed)
Definition pg_prng.c:89
pg_prng_state pg_global_prng_state
Definition pg_prng.c:34
#define pg_prng_strong_seed(state)
Definition pg_prng.h:46

References fb(), GetCurrentTimestamp(), MyProcPid, MyStartTime, MyStartTimestamp, pg_global_prng_state, pg_initialize_timing(), pg_prng_seed(), pg_prng_strong_seed, pg_prng_uint32(), timestamptz_to_time_t(), and unlikely.

Referenced by InitPostmasterChild(), InitStandaloneProcess(), and PostmasterMain().

◆ MaxLivePostmasterChildren()

int MaxLivePostmasterChildren ( void  )
extern

Definition at line 81 of file pmchild.c.

82{
83 if (num_pmchild_slots == 0)
84 elog(ERROR, "PM child array not initialized yet");
85 return num_pmchild_slots;
86}

References elog, ERROR, and num_pmchild_slots.

Referenced by PMSignalShmemRequest().

◆ parse_dispatch_option()

DispatchOption parse_dispatch_option ( const char name)
extern

Definition at line 244 of file main.c.

245{
246 for (int i = 0; i < lengthof(DispatchOptionNames); i++)
247 {
248 /*
249 * Unlike the other dispatch options, "forkchild" takes an argument,
250 * so we just look for the prefix for that one. For non-EXEC_BACKEND
251 * builds, we never want to return DISPATCH_FORKCHILD, so skip over it
252 * in that case.
253 */
254 if (i == DISPATCH_FORKCHILD)
255 {
256#ifdef EXEC_BACKEND
259 return DISPATCH_FORKCHILD;
260#endif
261 continue;
262 }
263
264 if (strcmp(DispatchOptionNames[i], name) == 0)
265 return (DispatchOption) i;
266 }
267
268 /* no match means this is a postmaster */
269 return DISPATCH_POSTMASTER;
270}
#define lengthof(array)
Definition c.h:873
static const char *const DispatchOptionNames[]
Definition main.c:48

References DISPATCH_FORKCHILD, DISPATCH_POSTMASTER, DispatchOptionNames, fb(), i, lengthof, and name.

Referenced by BootstrapModeMain(), main(), PostmasterMain(), and process_postgres_switches().

◆ postmaster_child_launch()

pid_t postmaster_child_launch ( BackendType  child_type,
int  child_slot,
void startup_data,
size_t  startup_data_len,
const struct ClientSocket client_sock 
)
extern

◆ PostmasterChildName()

const char * PostmasterChildName ( BackendType  child_type)

Definition at line 187 of file launch_backend.c.

188{
190}
static child_process_kind child_process_kinds[]

References child_process_kinds, fb(), and child_process_kind::name.

Referenced by AssignPostmasterChildSlot(), and StartChildProcess().

◆ PostmasterMain()

pg_noreturn void PostmasterMain ( int  argc,
char argv[] 
)
extern

Definition at line 496 of file postmaster.c.

497{
499 int opt;
500 int status;
501 char *userDoption = NULL;
502 bool listen_addr_saved = false;
504
506
508
510
511 /*
512 * Start our win32 signal implementation
513 */
514#ifdef WIN32
516#endif
517
518 /*
519 * We should not be creating any files or directories before we check the
520 * data directory (see checkDataDir()), but just in case set the umask to
521 * the most restrictive (owner-only) permissions.
522 *
523 * checkDataDir() will reset the umask based on the data directory
524 * permissions.
525 */
527
528 /*
529 * By default, palloc() requests in the postmaster will be allocated in
530 * the PostmasterContext, which is space that can be recycled by backends.
531 * Allocated data that needs to be available to backends should be
532 * allocated in TopMemoryContext.
533 */
535 "Postmaster",
538
539 /* Initialize paths to installation files */
540 getInstallationPaths(argv[0]);
541
542 /*
543 * Set up signal handlers for the postmaster process.
544 *
545 * CAUTION: when changing this list, check for side-effects on the signal
546 * handling setup of child processes. See tcop/postgres.c,
547 * bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
548 * postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/syslogger.c,
549 * postmaster/bgworker.c and postmaster/checkpointer.c.
550 */
551 pqinitmask();
553
558 pqsignal(SIGALRM, SIG_IGN); /* ignored */
559 pqsignal(SIGPIPE, SIG_IGN); /* ignored */
561 pqsignal(SIGUSR2, dummy_handler); /* unused, reserve for children */
563
564 /* This may configure SIGURG, depending on platform. */
567
568 /*
569 * No other place in Postgres should touch SIGTTIN/SIGTTOU handling. We
570 * ignore those signals in a postmaster environment, so that there is no
571 * risk of a child process freezing up due to writing to stderr. But for
572 * a standalone backend, their default handling is reasonable. Hence, all
573 * child processes should just allow the inherited settings to stand.
574 */
575#ifdef SIGTTIN
576 pqsignal(SIGTTIN, SIG_IGN); /* ignored */
577#endif
578#ifdef SIGTTOU
579 pqsignal(SIGTTOU, SIG_IGN); /* ignored */
580#endif
581
582 /* ignore SIGXFSZ, so that ulimit violations work like disk full */
583#ifdef SIGXFSZ
584 pqsignal(SIGXFSZ, SIG_IGN); /* ignored */
585#endif
586
587 /* Begin accepting signals. */
589
590 /*
591 * Options setup
592 */
594
595 /*
596 * Parse command-line options. CAUTION: keep this in sync with
597 * tcop/postgres.c (the option sets should not conflict) and with the
598 * common help() function in main/main.c.
599 */
600 pg_getopt_start(&optctx, argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:OPp:r:S:sTt:W:-:");
601 optctx.opterr = 1;
602 while ((opt = pg_getopt_next(&optctx)) != -1)
603 {
604 switch (opt)
605 {
606 case 'B':
607 SetConfigOption("shared_buffers", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
608 break;
609
610 case 'b':
611 /* Undocumented flag used for binary upgrades */
612 IsBinaryUpgrade = true;
613 break;
614
615 case 'C':
617 break;
618
619 case '-':
620
621 /*
622 * Error if the user misplaced a special must-be-first option
623 * for dispatching to a subprogram. parse_dispatch_option()
624 * returns DISPATCH_POSTMASTER if it doesn't find a match, so
625 * error for anything else.
626 */
630 errmsg("--%s must be first argument", optctx.optarg)));
631
633 case 'c':
634 {
635 char *name,
636 *value;
637
638 ParseLongOption(optctx.optarg, &name, &value);
639 if (!value)
640 {
641 if (opt == '-')
644 errmsg("--%s requires a value",
645 optctx.optarg)));
646 else
649 errmsg("-c %s requires a value",
650 optctx.optarg)));
651 }
652
654 pfree(name);
655 pfree(value);
656 break;
657 }
658
659 case 'D':
660 userDoption = strdup(optctx.optarg);
661 break;
662
663 case 'd':
665 break;
666
667 case 'E':
668 SetConfigOption("log_statement", "all", PGC_POSTMASTER, PGC_S_ARGV);
669 break;
670
671 case 'e':
672 SetConfigOption("datestyle", "euro", PGC_POSTMASTER, PGC_S_ARGV);
673 break;
674
675 case 'F':
676 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
677 break;
678
679 case 'f':
681 {
682 write_stderr("%s: invalid argument for option -f: \"%s\"\n",
683 progname, optctx.optarg);
685 }
686 break;
687
688 case 'h':
689 SetConfigOption("listen_addresses", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
690 break;
691
692 case 'i':
693 SetConfigOption("listen_addresses", "*", PGC_POSTMASTER, PGC_S_ARGV);
694 break;
695
696 case 'j':
697 /* only used by interactive backend */
698 break;
699
700 case 'k':
701 SetConfigOption("unix_socket_directories", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
702 break;
703
704 case 'l':
706 break;
707
708 case 'N':
709 SetConfigOption("max_connections", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
710 break;
711
712 case 'O':
713 SetConfigOption("allow_system_table_mods", "true", PGC_POSTMASTER, PGC_S_ARGV);
714 break;
715
716 case 'P':
717 SetConfigOption("ignore_system_indexes", "true", PGC_POSTMASTER, PGC_S_ARGV);
718 break;
719
720 case 'p':
722 break;
723
724 case 'r':
725 /* only used by single-user backend */
726 break;
727
728 case 'S':
729 SetConfigOption("work_mem", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
730 break;
731
732 case 's':
733 SetConfigOption("log_statement_stats", "true", PGC_POSTMASTER, PGC_S_ARGV);
734 break;
735
736 case 'T':
737
738 /*
739 * This option used to be defined as sending SIGSTOP after a
740 * backend crash, but sending SIGABRT seems more useful.
741 */
742 SetConfigOption("send_abort_for_crash", "true", PGC_POSTMASTER, PGC_S_ARGV);
743 break;
744
745 case 't':
746 {
747 const char *tmp = get_stats_option_name(optctx.optarg);
748
749 if (tmp)
750 {
752 }
753 else
754 {
755 write_stderr("%s: invalid argument for option -t: \"%s\"\n",
756 progname, optctx.optarg);
758 }
759 break;
760 }
761
762 case 'W':
763 SetConfigOption("post_auth_delay", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
764 break;
765
766 default:
767 write_stderr("Try \"%s --help\" for more information.\n",
768 progname);
770 }
771 }
772
773 /*
774 * Postmaster accepts no non-option switch arguments.
775 */
776 if (optctx.optind < argc)
777 {
778 write_stderr("%s: invalid argument: \"%s\"\n",
779 progname, argv[optctx.optind]);
780 write_stderr("Try \"%s --help\" for more information.\n",
781 progname);
783 }
784
785 /*
786 * Locate the proper configuration files and data directory, and read
787 * postgresql.conf for the first time.
788 */
791
793 {
794 /*
795 * If this is a runtime-computed GUC, it hasn't yet been initialized,
796 * and the present value is not useful. However, this is a convenient
797 * place to print the value for most GUCs because it is safe to run
798 * postmaster startup to this point even if the server is already
799 * running. For the handful of runtime-computed GUCs that we cannot
800 * provide meaningful values for yet, we wait until later in
801 * postmaster startup to print the value. We won't be able to use -C
802 * on running servers for those GUCs, but using this option now would
803 * lead to incorrect results for them.
804 */
806
807 if ((flags & GUC_RUNTIME_COMPUTED) == 0)
808 {
809 /*
810 * "-C guc" was specified, so print GUC's value and exit. No
811 * extra permission check is needed because the user is reading
812 * inside the data dir.
813 */
815 false, false);
816
817 puts(config_val ? config_val : "");
819 }
820
821 /*
822 * A runtime-computed GUC will be printed later on. As we initialize
823 * a server startup sequence, silence any log messages that may show
824 * up in the output generated. FATAL and more severe messages are
825 * useful to show, even if one would only expect at least PANIC. LOG
826 * entries are hidden.
827 */
828 SetConfigOption("log_min_messages", "FATAL", PGC_SUSET,
830 }
831
832 /* Verify that DataDir looks reasonable */
833 checkDataDir();
834
835 /* Check that pg_control exists */
837
838 /* And switch working directory into it */
840
841 /*
842 * Check for invalid combinations of GUC settings.
843 */
845 {
846 write_stderr("%s: \"superuser_reserved_connections\" (%d) plus \"reserved_connections\" (%d) must be less than \"max_connections\" (%d)\n",
847 progname,
851 }
854 (errmsg("WAL archival cannot be enabled when \"wal_level\" is \"minimal\"")));
857 (errmsg("WAL streaming (\"max_wal_senders\" > 0) requires \"wal_level\" to be \"replica\" or \"logical\"")));
860 (errmsg("WAL cannot be summarized when \"wal_level\" is \"minimal\"")));
863 (errmsg("replication slot synchronization (\"sync_replication_slots\" = on) requires \"wal_level\" to be \"replica\" or \"logical\"")));
864
865 /*
866 * Other one-time internal sanity checks can go here, if they are fast.
867 * (Put any slow processing further down, after postmaster.pid creation.)
868 */
870 {
871 write_stderr("%s: invalid datetoken tables, please fix\n", progname);
873 }
874
875 /* For debugging: display postmaster environment */
877 {
878#if !defined(WIN32)
879 extern char **environ;
880#endif
881 char **p;
883
885
886 appendStringInfoString(&si, "initial environment dump:");
887 for (p = environ; *p; ++p)
888 appendStringInfo(&si, "\n%s", *p);
889
890 ereport(DEBUG3, errmsg_internal("%s", si.data));
891 pfree(si.data);
892 }
893
894 /*
895 * Create lockfile for data directory.
896 *
897 * We want to do this before we try to grab the input sockets, because the
898 * data directory interlock is more reliable than the socket-file
899 * interlock (thanks to whoever decided to put socket files in /tmp :-().
900 * For the same reason, it's best to grab the TCP socket(s) before the
901 * Unix socket(s).
902 *
903 * Also note that this internally sets up the on_proc_exit function that
904 * is responsible for removing both data directory and socket lockfiles;
905 * so it must happen before opening sockets so that at exit, the socket
906 * lockfiles go away after CloseServerPorts runs.
907 */
909
910 /*
911 * Read the control file (for error checking and config info).
912 *
913 * Since we verify the control file's CRC, this has a useful side effect
914 * on machines where we need a run-time test for CRC support instructions.
915 * The postmaster will do the test once at startup, and then its child
916 * processes will inherit the correct function pointer and not need to
917 * repeat the test.
918 */
920
921 /*
922 * Register the apply launcher. It's probably a good idea to call this
923 * before any modules had a chance to take the background worker slots.
924 */
926
927 /*
928 * Register the shared memory needs of all core subsystems.
929 */
931
932 /*
933 * process any libraries that should be preloaded at postmaster start
934 */
936
937 /*
938 * Initialize SSL library, if specified.
939 */
940#ifdef USE_SSL
941 if (EnableSSL)
942 {
943 (void) secure_initialize(true);
944 LoadedSSL = true;
945 }
946#endif
947
948 /*
949 * Now that loadable modules have had their chance to alter any GUCs,
950 * calculate MaxBackends and initialize the machinery to track child
951 * processes.
952 */
955
956 /*
957 * Calculate the size of the PGPROC fast-path lock arrays.
958 */
960
961 /*
962 * Also call any legacy shmem request hooks that might've been installed
963 * by preloaded libraries.
964 *
965 * Note: this must be done before ShmemCallRequestCallbacks(), because the
966 * hooks may request LWLocks with RequestNamedLWLockTranche(), which in
967 * turn affects the size of the LWLock array calculated in lwlock.c.
968 */
970
971 /*
972 * Ask all subsystems, including preloaded libraries, to register their
973 * shared memory needs.
974 */
976
977 /*
978 * Now that loadable modules have had their chance to request additional
979 * shared memory, determine the value of any runtime-computed GUCs that
980 * depend on the amount of shared memory required.
981 */
983
984 /*
985 * Now that modules have been loaded, we can process any custom resource
986 * managers specified in the wal_consistency_checking GUC.
987 */
989
990 /*
991 * If -C was specified with a runtime-computed GUC, we held off printing
992 * the value earlier, as the GUC was not yet initialized. We handle -C
993 * for most GUCs before we lock the data directory so that the option may
994 * be used on a running server. However, a handful of GUCs are runtime-
995 * computed and do not have meaningful values until after locking the data
996 * directory, and we cannot safely calculate their values earlier on a
997 * running server. At this point, such GUCs should be properly
998 * initialized, and we haven't yet set up shared memory, so this is a good
999 * time to handle the -C option for these special GUCs.
1000 */
1002 {
1004 false, false);
1005
1006 puts(config_val ? config_val : "");
1007 ExitPostmaster(0);
1008 }
1009
1010 /*
1011 * Set up shared memory and semaphores.
1012 *
1013 * Note: if using SysV shmem and/or semas, each postmaster startup will
1014 * normally choose the same IPC keys. This helps ensure that we will
1015 * clean up dead IPC objects if the postmaster crashes and is restarted.
1016 */
1018
1019 /*
1020 * Estimate number of openable files. This must happen after setting up
1021 * semaphores, because on some platforms semaphores count as open files.
1022 */
1024
1025 /*
1026 * Initialize pipe (or process handle on Windows) that allows children to
1027 * wake up from sleep on postmaster death.
1028 */
1030
1031#ifdef WIN32
1032
1033 /*
1034 * Initialize I/O completion port used to deliver list of dead children.
1035 */
1037 if (win32ChildQueue == NULL)
1038 ereport(FATAL,
1039 (errmsg("could not create I/O completion port for child queue")));
1040#endif
1041
1042#ifdef EXEC_BACKEND
1043 /* Write out nondefault GUC settings for child processes to use */
1045
1046 /*
1047 * Clean out the temp directory used to transmit parameters to child
1048 * processes (see internal_forkexec). We must do this before launching
1049 * any child processes, else we have a race condition: we could remove a
1050 * parameter file before the child can read it. It should be safe to do
1051 * so now, because we verified earlier that there are no conflicting
1052 * Postgres processes in this data directory.
1053 */
1055#endif
1056
1057 /*
1058 * Forcibly remove the files signaling a standby promotion request.
1059 * Otherwise, the existence of those files triggers a promotion too early,
1060 * whether a user wants that or not.
1061 *
1062 * This removal of files is usually unnecessary because they can exist
1063 * only during a few moments during a standby promotion. However there is
1064 * a race condition: if pg_ctl promote is executed and creates the files
1065 * during a promotion, the files can stay around even after the server is
1066 * brought up to be the primary. Then, if a new standby starts by using
1067 * the backup taken from the new primary, the files can exist at server
1068 * startup and must be removed in order to avoid an unexpected promotion.
1069 *
1070 * Note that promotion signal files need to be removed before the startup
1071 * process is invoked. Because, after that, they can be used by
1072 * postmaster's SIGUSR1 signal handler.
1073 */
1075
1076 /* Do the same for logrotate signal file */
1078
1079 /* Remove any outdated file holding the current log filenames. */
1081 ereport(LOG,
1083 errmsg("could not remove file \"%s\": %m",
1085
1086 /*
1087 * If enabled, start up syslogger collection subprocess
1088 */
1091
1092 /*
1093 * Reset whereToSendOutput from DestDebug (its starting state) to
1094 * DestNone. This stops ereport from sending log messages to stderr unless
1095 * Log_destination permits. We don't do this until the postmaster is
1096 * fully launched, since startup failures may as well be reported to
1097 * stderr.
1098 *
1099 * If we are in fact disabling logging to stderr, first emit a log message
1100 * saying so, to provide a breadcrumb trail for users who may not remember
1101 * that their logging is configured to go somewhere else.
1102 */
1104 ereport(LOG,
1105 (errmsg("ending log output to stderr"),
1106 errhint("Future log output will go to log destination \"%s\".",
1108
1110
1111 /*
1112 * Report server startup in log. While we could emit this much earlier,
1113 * it seems best to do so after starting the log collector, if we intend
1114 * to use one.
1115 */
1116 ereport(LOG,
1117 (errmsg("starting %s", PG_VERSION_STR)));
1118
1119 /*
1120 * Establish input sockets.
1121 *
1122 * First set up an on_proc_exit function that's charged with closing the
1123 * sockets again at postmaster shutdown.
1124 */
1127
1128 if (ListenAddresses)
1129 {
1130 char *rawstring;
1131 List *elemlist;
1132 ListCell *l;
1133 int success = 0;
1134
1135 /* Need a modifiable copy of ListenAddresses */
1137
1138 /* Parse string into list of hostnames */
1139 if (!SplitGUCList(rawstring, ',', &elemlist))
1140 {
1141 /* syntax error in list */
1142 ereport(FATAL,
1144 errmsg("invalid list syntax in parameter \"%s\"",
1145 "listen_addresses")));
1146 }
1147
1148 foreach(l, elemlist)
1149 {
1150 char *curhost = (char *) lfirst(l);
1151
1152 if (strcmp(curhost, "*") == 0)
1154 (unsigned short) PostPortNumber,
1155 NULL,
1158 MAXLISTEN);
1159 else
1161 (unsigned short) PostPortNumber,
1162 NULL,
1165 MAXLISTEN);
1166
1167 if (status == STATUS_OK)
1168 {
1169 success++;
1170 /* record the first successful host addr in lockfile */
1171 if (!listen_addr_saved)
1172 {
1174 listen_addr_saved = true;
1175 }
1176 }
1177 else
1179 (errmsg("could not create listen socket for \"%s\"",
1180 curhost)));
1181 }
1182
1183 if (!success && elemlist != NIL)
1184 ereport(FATAL,
1185 (errmsg("could not create any TCP/IP sockets")));
1186
1189 }
1190
1191#ifdef USE_BONJOUR
1192 /* Register for Bonjour only if we opened TCP socket(s) */
1194 {
1196
1197 /*
1198 * We pass 0 for interface_index, which will result in registering on
1199 * all "applicable" interfaces. It's not entirely clear from the
1200 * DNS-SD docs whether this would be appropriate if we have bound to
1201 * just a subset of the available network interfaces.
1202 */
1204 0,
1205 0,
1207 "_postgresql._tcp.",
1208 NULL,
1209 NULL,
1211 0,
1212 NULL,
1213 NULL,
1214 NULL);
1216 ereport(LOG,
1217 (errmsg("DNSServiceRegister() failed: error code %ld",
1218 (long) err)));
1219
1220 /*
1221 * We don't bother to read the mDNS daemon's reply, and we expect that
1222 * it will automatically terminate our registration when the socket is
1223 * closed at postmaster termination. So there's nothing more to be
1224 * done here. However, the bonjour_sdref is kept around so that
1225 * forked children can close their copies of the socket.
1226 */
1227 }
1228#endif
1229
1231 {
1232 char *rawstring;
1233 List *elemlist;
1234 ListCell *l;
1235 int success = 0;
1236
1237 /* Need a modifiable copy of Unix_socket_directories */
1239
1240 /* Parse string into list of directories */
1242 {
1243 /* syntax error in list */
1244 ereport(FATAL,
1246 errmsg("invalid list syntax in parameter \"%s\"",
1247 "unix_socket_directories")));
1248 }
1249
1250 foreach(l, elemlist)
1251 {
1252 char *socketdir = (char *) lfirst(l);
1253
1254 status = ListenServerPort(AF_UNIX, NULL,
1255 (unsigned short) PostPortNumber,
1256 socketdir,
1259 MAXLISTEN);
1260
1261 if (status == STATUS_OK)
1262 {
1263 success++;
1264 /* record the first successful Unix socket in lockfile */
1265 if (success == 1)
1267 }
1268 else
1270 (errmsg("could not create Unix-domain socket in directory \"%s\"",
1271 socketdir)));
1272 }
1273
1274 if (!success && elemlist != NIL)
1275 ereport(FATAL,
1276 (errmsg("could not create any Unix-domain sockets")));
1277
1280 }
1281
1282 /*
1283 * check that we have some socket to listen on
1284 */
1285 if (NumListenSockets == 0)
1286 ereport(FATAL,
1287 (errmsg("no socket created for listening")));
1288
1289 /*
1290 * If no valid TCP ports, write an empty line for listen address,
1291 * indicating the Unix socket must be used. Note that this line is not
1292 * added to the lock file until there is a socket backing it.
1293 */
1294 if (!listen_addr_saved)
1296
1297 /*
1298 * Record postmaster options. We delay this till now to avoid recording
1299 * bogus options (eg, unusable port number).
1300 */
1301 if (!CreateOptsFile(argc, argv, my_exec_path))
1302 ExitPostmaster(1);
1303
1304 /*
1305 * Write the external PID file if requested
1306 */
1308 {
1310
1311 if (fpidfile)
1312 {
1313 fprintf(fpidfile, "%d\n", MyProcPid);
1315
1316 /* Make PID file world readable */
1318 write_stderr("%s: could not change permissions of external PID file \"%s\": %m\n",
1320 }
1321 else
1322 write_stderr("%s: could not write external PID file \"%s\": %m\n",
1324
1326 }
1327
1328 /*
1329 * Remove old temporary files. At this point there can be no other
1330 * Postgres processes running in this directory, so this should be safe.
1331 */
1333
1334 /*
1335 * Initialize the autovacuum subsystem (again, no process start yet)
1336 */
1337 autovac_init();
1338
1339 /*
1340 * Load configuration files for client authentication.
1341 */
1342 if (!load_hba())
1343 {
1344 /*
1345 * It makes no sense to continue if we fail to load the HBA file,
1346 * since there is no way to connect to the database in this case.
1347 */
1348 ereport(FATAL,
1349 /* translator: %s is a configuration file */
1350 (errmsg("could not load %s", HbaFileName)));
1351 }
1352 if (!load_ident())
1353 {
1354 /*
1355 * We can start up without the IDENT file, although it means that you
1356 * cannot log in using any of the authentication methods that need a
1357 * user name mapping. load_ident() already logged the details of error
1358 * to the log.
1359 */
1360 }
1361
1362#ifdef HAVE_PTHREAD_IS_THREADED_NP
1363
1364 /*
1365 * On macOS, libintl replaces setlocale() with a version that calls
1366 * CFLocaleCopyCurrent() when its second argument is "" and every relevant
1367 * environment variable is unset or empty. CFLocaleCopyCurrent() makes
1368 * the process multithreaded. The postmaster calls sigprocmask() and
1369 * calls fork() without an immediate exec(), both of which have undefined
1370 * behavior in a multithreaded program. A multithreaded postmaster is the
1371 * normal case on Windows, which offers neither fork() nor sigprocmask().
1372 * Currently, macOS is the only platform having pthread_is_threaded_np(),
1373 * so we need not worry whether this HINT is appropriate elsewhere.
1374 */
1375 if (pthread_is_threaded_np() != 0)
1376 ereport(FATAL,
1378 errmsg("postmaster became multithreaded during startup"),
1379 errhint("Set the LC_ALL environment variable to a valid locale.")));
1380#endif
1381
1382 /*
1383 * Remember postmaster startup time
1384 */
1386
1387 /*
1388 * Report postmaster status in the postmaster.pid file, to allow pg_ctl to
1389 * see what's happening.
1390 */
1392
1394
1395 /* Make sure we can perform I/O while starting up. */
1397
1398 /* Start bgwriter and checkpointer so they can help with recovery */
1401 if (BgWriterPMChild == NULL)
1403
1404 /*
1405 * We're ready to rock and roll...
1406 */
1410
1411 /* Some workers may be scheduled to start now */
1413
1414 status = ServerLoop();
1415
1416 /*
1417 * ServerLoop probably shouldn't ever return, but if it does, close down.
1418 */
1419 ExitPostmaster(status != STATUS_OK);
1420
1421 abort(); /* not reached */
1422}
void autovac_init(void)
void pqinitmask(void)
Definition pqsignal.c:41
sigset_t UnBlockSig
Definition pqsignal.c:22
sigset_t BlockSig
Definition pqsignal.c:23
bool CheckDateTokenTables(void)
Definition datetime.c:4934
TimestampTz PgStartTime
Definition timestamp.c:45
int secure_initialize(bool isServerStart)
Definition be-secure.c:79
#define write_stderr(str)
Definition parallel.c:186
#define STATUS_OK
Definition c.h:1258
#define pg_fallthrough
Definition c.h:161
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
@ DestNone
Definition dest.h:87
int Log_destination
Definition elog.c:115
bool message_level_is_interesting(int elevel)
Definition elog.c:284
char * Log_destination_string
Definition elog.c:116
int errcode(int sqlerrcode)
Definition elog.c:874
int errhint(const char *fmt,...) pg_attribute_printf(1
#define DEBUG3
Definition elog.h:29
#define WARNING
Definition elog.h:37
#define LOG_DESTINATION_STDERR
Definition elog.h:487
void err(int eval, const char *fmt,...)
Definition err.c:43
void RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok, bool unlink_all)
Definition fd.c:3383
void RemovePgTempFiles(void)
Definition fd.c:3323
void set_max_safe_fds(void)
Definition fd.c:1045
#define PG_MODE_MASK_OWNER
Definition file_perm.h:24
#define PG_TEMP_FILES_DIR
Definition file_utils.h:63
bool IsBinaryUpgrade
Definition globals.c:123
pid_t PostmasterPid
Definition globals.c:108
bool IsPostmasterEnvironment
Definition globals.c:121
char my_exec_path[MAXPGPATH]
Definition globals.c:83
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition guc.c:4234
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition guc.c:4257
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition guc.c:1656
void ParseLongOption(const char *string, char **name, char **value)
Definition guc.c:6243
void InitializeGUCOptions(void)
Definition guc.c:1408
int GetConfigOptionFlags(const char *name, bool missing_ok)
Definition guc.c:4354
#define GUC_RUNTIME_COMPUTED
Definition guc.h:229
@ PGC_S_OVERRIDE
Definition guc.h:123
@ PGC_S_ARGV
Definition guc.h:117
@ PGC_SUSET
Definition guc.h:78
@ PGC_POSTMASTER
Definition guc.h:74
char * HbaFileName
Definition guc_tables.c:584
char * external_pid_file
Definition guc_tables.c:587
bool load_ident(void)
Definition hba.c:2846
bool load_hba(void)
Definition hba.c:2452
static struct @177 value
static bool success
Definition initdb.c:188
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:316
void RegisterBuiltinShmemCallbacks(void)
Definition ipci.c:168
void InitializeShmemGUCs(void)
Definition ipci.c:189
void CreateSharedMemoryAndSemaphores(void)
Definition ipci.c:120
void ApplyLauncherRegister(void)
Definition launcher.c:1010
void list_free(List *list)
Definition list.c:1546
void list_free_deep(List *list)
Definition list.c:1560
DispatchOption parse_dispatch_option(const char *name)
Definition main.c:244
const char * progname
Definition main.c:44
char * pstrdup(const char *in)
Definition mcxt.c:1781
MemoryContext TopMemoryContext
Definition mcxt.c:166
MemoryContext PostmasterContext
Definition mcxt.c:168
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
void ChangeToDataDir(void)
Definition miscinit.c:410
void process_shmem_requests(void)
Definition miscinit.c:1881
void AddToDataDirLockFile(int target_line, const char *str)
Definition miscinit.c:1521
void InitProcessLocalLatch(void)
Definition miscinit.c:236
void process_shared_preload_libraries(void)
Definition miscinit.c:1853
void checkDataDir(void)
Definition miscinit.c:297
void CreateDataDirLockFile(bool amPostmaster)
Definition miscinit.c:1465
static char * errmsg
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124
#define pg_hton16(x)
Definition pg_bswap.h:120
int pg_getopt_next(pg_getopt_ctx *ctx)
void pg_getopt_start(pg_getopt_ctx *ctx, int nargc, char *const *nargv, const char *ostr)
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
#define PM_STATUS_STARTING
Definition pidfile.h:51
#define LOCK_FILE_LINE_LISTEN_ADDR
Definition pidfile.h:42
#define LOCK_FILE_LINE_PM_STATUS
Definition pidfile.h:44
#define LOCK_FILE_LINE_SOCKET_DIR
Definition pidfile.h:41
void InitPostmasterChildSlots(void)
Definition pmchild.c:97
#define pqsignal
Definition port.h:547
int pgsocket
Definition port.h:29
void set_debug_options(int debug_flag, GucContext context, GucSource source)
Definition postgres.c:3749
CommandDest whereToSendOutput
Definition postgres.c:97
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition postgres.c:3781
const char * get_stats_option_name(const char *arg)
Definition postgres.c:3823
static const char * userDoption
Definition postgres.c:167
void InitializeMaxBackends(void)
Definition postinit.c:559
void InitializeFastPathLocks(void)
Definition postinit.c:584
static void handle_pm_shutdown_request_signal(SIGNAL_ARGS)
static void maybe_start_bgworkers(void)
static void CloseServerPorts(int status, Datum arg)
@ PM_STARTUP
Definition postmaster.c:338
static void InitPostmasterDeathWatchHandle(void)
void InitProcessGlobals(void)
static void handle_pm_reload_request_signal(SIGNAL_ARGS)
static void StartSysLogger(void)
static int ServerLoop(void)
int PostPortNumber
Definition postmaster.c:204
static PMChild * BgWriterPMChild
Definition postmaster.c:262
static void checkControlFile(void)
bool enable_bonjour
Definition postmaster.c:246
static PMChild * StartChildProcess(BackendType type)
int ReservedConnections
Definition postmaster.c:231
static void handle_pm_pmsignal_signal(SIGNAL_ARGS)
static void UpdatePMState(PMState newState)
static PMChild * StartupPMChild
Definition postmaster.c:261
char * Unix_socket_directories
Definition postmaster.c:207
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname)
static pg_noreturn void ExitPostmaster(int status)
static void handle_pm_child_exit_signal(SIGNAL_ARGS)
static void getInstallationPaths(const char *argv0)
@ STARTUP_RUNNING
Definition postmaster.c:276
static void unlink_external_pid_file(int status, Datum arg)
static StartupStatusEnum StartupStatus
Definition postmaster.c:281
#define MAXLISTEN
Definition postmaster.c:234
static void dummy_handler(SIGNAL_ARGS)
bool EnableSSL
Definition postmaster.c:239
static PMChild * CheckpointerPMChild
Definition postmaster.c:263
char * ListenAddresses
Definition postmaster.c:210
int SuperuserReservedConnections
Definition postmaster.c:230
char * bonjour_name
Definition postmaster.c:247
static void maybe_start_io_workers(void)
PGDLLIMPORT bool LoadedSSL
int ListenServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSockets[], int *NumListenSockets, int MaxListen)
Definition pqcomm.c:419
char ** environ
void ShmemCallRequestCallbacks(void)
Definition shmem.c:979
void pgwin32_signal_initialize(void)
Definition signal.c:79
bool sync_replication_slots
Definition slotsync.c:132
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
Definition pg_list.h:54
void RemoveLogrotateSignalFiles(void)
Definition syslogger.c:1588
bool Logging_collector
Definition syslogger.c:71
#define LOG_METAINFO_DATAFILE
Definition syslogger.h:102
bool SplitDirectoriesString(char *rawstring, char separator, List **namelist)
Definition varlena.c:2950
bool SplitGUCList(char *rawstring, char separator, List **namelist)
Definition varlena.c:3060
void InitializeWaitEventSupport(void)
bool summarize_wal
#define S_IROTH
Definition win32_port.h:303
#define SIGCHLD
Definition win32_port.h:168
#define SIGHUP
Definition win32_port.h:158
#define S_IRGRP
Definition win32_port.h:291
#define SIGPIPE
Definition win32_port.h:163
#define SIGQUIT
Definition win32_port.h:159
#define S_IRUSR
Definition win32_port.h:279
#define SIGUSR1
Definition win32_port.h:170
#define SIGALRM
Definition win32_port.h:164
#define SIGUSR2
Definition win32_port.h:171
#define S_IWUSR
Definition win32_port.h:282
int XLogArchiveMode
Definition xlog.c:126
int wal_level
Definition xlog.c:138
void InitializeWalConsistencyChecking(void)
Definition xlog.c:5188
void LocalProcessControlFile(bool reset)
Definition xlog.c:5269
@ ARCHIVE_MODE_OFF
Definition xlog.h:67
@ WAL_LEVEL_MINIMAL
Definition xlog.h:76
void RemovePromoteSignalFiles(void)

References AddToDataDirLockFile(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, appendStringInfo(), appendStringInfoString(), ApplyLauncherRegister(), ARCHIVE_MODE_OFF, Assert, autovac_init(), B_BG_WRITER, B_CHECKPOINTER, B_STARTUP, BgWriterPMChild, BlockSig, bonjour_name, ChangeToDataDir(), checkControlFile(), checkDataDir(), CheckDateTokenTables(), CheckpointerPMChild, CloseServerPorts(), CreateDataDirLockFile(), CreateOptsFile(), CreateSharedMemoryAndSemaphores(), DEBUG3, DestNone, DISPATCH_POSTMASTER, dummy_handler(), enable_bonjour, EnableSSL, environ, ereport, err(), errcode(), errcode_for_file_access(), errhint(), errmsg, errmsg_internal(), ERROR, ExitPostmaster(), external_pid_file, FATAL, fb(), fprintf, get_stats_option_name(), GetConfigOption(), GetConfigOptionFlags(), GetCurrentTimestamp(), getInstallationPaths(), GUC_RUNTIME_COMPUTED, handle_pm_child_exit_signal(), handle_pm_pmsignal_signal(), handle_pm_reload_request_signal(), handle_pm_shutdown_request_signal(), HbaFileName, InitializeFastPathLocks(), InitializeGUCOptions(), InitializeMaxBackends(), InitializeShmemGUCs(), InitializeWaitEventSupport(), InitializeWalConsistencyChecking(), InitPostmasterChildSlots(), InitPostmasterDeathWatchHandle(), InitProcessGlobals(), InitProcessLocalLatch(), initStringInfo(), IsBinaryUpgrade, IsPostmasterEnvironment, lfirst, list_free(), list_free_deep(), ListenAddresses, ListenServerPort(), ListenSockets, load_hba(), load_ident(), LoadedSSL, LocalProcessControlFile(), LOCK_FILE_LINE_LISTEN_ADDR, LOCK_FILE_LINE_PM_STATUS, LOCK_FILE_LINE_SOCKET_DIR, LOG, Log_destination, LOG_DESTINATION_STDERR, Log_destination_string, LOG_METAINFO_DATAFILE, Logging_collector, max_wal_senders, MaxConnections, MAXLISTEN, maybe_start_bgworkers(), maybe_start_io_workers(), MemoryContextSwitchTo(), message_level_is_interesting(), my_exec_path, MyProcPid, name, NIL, NumListenSockets, on_proc_exit(), palloc(), parse_dispatch_option(), ParseLongOption(), pfree(), pg_fallthrough, pg_getopt_next(), pg_getopt_start(), pg_hton16, PG_MODE_MASK_OWNER, PG_TEMP_FILES_DIR, PGC_POSTMASTER, PGC_S_ARGV, PGC_S_OVERRIDE, PGC_SUSET, PgStartTime, pgwin32_signal_initialize(), PM_STARTUP, PM_STATUS_STARTING, PostmasterContext, PostmasterPid, PostPortNumber, pqinitmask(), pqsignal, process_shared_preload_libraries(), process_shmem_requests(), progname, pstrdup(), RegisterBuiltinShmemCallbacks(), RemoveLogrotateSignalFiles(), RemovePgTempFiles(), RemovePgTempFilesInDir(), RemovePromoteSignalFiles(), ReservedConnections, S_IRGRP, S_IROTH, S_IRUSR, S_IWUSR, secure_initialize(), SelectConfigFiles(), ServerLoop(), set_debug_options(), set_max_safe_fds(), set_plan_disabling_options(), SetConfigOption(), ShmemCallRequestCallbacks(), SIGALRM, SIGCHLD, SIGHUP, SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, SplitDirectoriesString(), SplitGUCList(), StartChildProcess(), StartSysLogger(), STARTUP_RUNNING, StartupPMChild, StartupStatus, STATUS_OK, success, summarize_wal, SuperuserReservedConnections, sync_replication_slots, TopMemoryContext, UnBlockSig, Unix_socket_directories, unlink_external_pid_file(), UpdatePMState(), userDoption, value, wal_level, WAL_LEVEL_MINIMAL, WARNING, whereToSendOutput, write_stderr, and XLogArchiveMode.

Referenced by main().

◆ PostmasterMarkPIDForWorkerNotify()

bool PostmasterMarkPIDForWorkerNotify ( int  pid)
extern

Definition at line 4578 of file postmaster.c.

4579{
4580 dlist_iter iter;
4581 PMChild *bp;
4582
4584 {
4585 bp = dlist_container(PMChild, elem, iter.cur);
4586 if (bp->pid == pid)
4587 {
4588 bp->bgworker_notify = true;
4589 return true;
4590 }
4591 }
4592 return false;
4593}

References ActiveChildList, dlist_iter::cur, dlist_container, dlist_foreach, and fb().

Referenced by BackgroundWorkerStateChange().

◆ ReleasePostmasterChildSlot()

bool ReleasePostmasterChildSlot ( PMChild pmchild)
extern

Definition at line 252 of file pmchild.c.

253{
254 dlist_delete(&pmchild->elem);
255 if (pmchild->bkend_type == B_DEAD_END_BACKEND)
256 {
257 elog(DEBUG2, "releasing dead-end backend");
258 pfree(pmchild);
259 return true;
260 }
261 else
262 {
263 PMChildPool *pool;
264
265 elog(DEBUG2, "releasing pm child slot %d", pmchild->child_slot);
266
267 /* WAL senders start out as regular backends, and share the pool */
268 if (pmchild->bkend_type == B_WAL_SENDER)
269 pool = &pmchild_pools[B_BACKEND];
270 else
271 pool = &pmchild_pools[pmchild->bkend_type];
272
273 /* sanity check that we return the entry to the right pool */
274 if (!(pmchild->child_slot >= pool->first_slotno &&
275 pmchild->child_slot < pool->first_slotno + pool->size))
276 {
277 elog(ERROR, "pmchild freelist for backend type %d is corrupt",
278 pmchild->bkend_type);
279 }
280
281 dlist_push_head(&pool->freelist, &pmchild->elem);
282 return MarkPostmasterChildSlotUnassigned(pmchild->child_slot);
283 }
284}
static void dlist_delete(dlist_node *node)
Definition ilist.h:405
@ B_WAL_SENDER
Definition miscadmin.h:359
bool MarkPostmasterChildSlotUnassigned(int slot)
Definition pmsignal.c:248

References B_BACKEND, B_DEAD_END_BACKEND, B_WAL_SENDER, DEBUG2, dlist_delete(), dlist_push_head(), elog, ERROR, fb(), PMChildPool::first_slotno, PMChildPool::freelist, MarkPostmasterChildSlotUnassigned(), pfree(), pmchild_pools, and PMChildPool::size.

Referenced by BackendStartup(), CleanupBackend(), maybe_reap_io_worker(), process_pm_child_exit(), StartBackgroundWorker(), StartChildProcess(), and StartSysLogger().

Variable Documentation

◆ ActiveChildList

◆ AuthenticationTimeout

PGDLLIMPORT int AuthenticationTimeout
extern

Definition at line 242 of file postmaster.c.

Referenced by BackendInitialize(), and PerformAuthentication().

◆ bonjour_name

PGDLLIMPORT char* bonjour_name
extern

Definition at line 247 of file postmaster.c.

Referenced by PostmasterMain().

◆ ClientAuthInProgress

◆ enable_bonjour

PGDLLIMPORT bool enable_bonjour
extern

Definition at line 246 of file postmaster.c.

Referenced by PostmasterMain().

◆ EnableSSL

PGDLLIMPORT bool EnableSSL
extern

◆ ListenAddresses

PGDLLIMPORT char* ListenAddresses
extern

Definition at line 210 of file postmaster.c.

Referenced by PostmasterMain().

◆ LoadedSSL

◆ log_hostname

PGDLLIMPORT bool log_hostname
extern

Definition at line 244 of file postmaster.c.

Referenced by BackendInitialize().

◆ MyClientSocket

PGDLLIMPORT struct ClientSocket* MyClientSocket
extern

Definition at line 52 of file globals.c.

Referenced by BackendMain(), and postmaster_child_launch().

◆ postmaster_alive_fds

PGDLLIMPORT int postmaster_alive_fds[2]
extern

◆ PostPortNumber

PGDLLIMPORT int PostPortNumber
extern

Definition at line 204 of file postmaster.c.

Referenced by CreateLockFile(), and PostmasterMain().

◆ PreAuthDelay

PGDLLIMPORT int PreAuthDelay
extern

Definition at line 241 of file postmaster.c.

Referenced by BackendInitialize().

◆ progname

◆ redirection_done

PGDLLIMPORT bool redirection_done
extern

◆ remove_temp_files_after_crash

PGDLLIMPORT bool remove_temp_files_after_crash
extern

Definition at line 249 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ ReservedConnections

PGDLLIMPORT int ReservedConnections
extern

Definition at line 231 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ restart_after_crash

PGDLLIMPORT bool restart_after_crash
extern

Definition at line 248 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ send_abort_for_crash

PGDLLIMPORT bool send_abort_for_crash
extern

Definition at line 257 of file postmaster.c.

Referenced by HandleFatalError().

◆ send_abort_for_kill

PGDLLIMPORT bool send_abort_for_kill
extern

Definition at line 258 of file postmaster.c.

Referenced by ServerLoop().

◆ SuperuserReservedConnections

PGDLLIMPORT int SuperuserReservedConnections
extern

Definition at line 230 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ Unix_socket_directories

PGDLLIMPORT char* Unix_socket_directories
extern

Definition at line 207 of file postmaster.c.

Referenced by PostmasterMain().

◆ Unix_socket_group

PGDLLIMPORT char* Unix_socket_group
extern

Definition at line 108 of file pqcomm.c.

Referenced by Setup_AF_UNIX().

◆ Unix_socket_permissions

PGDLLIMPORT int Unix_socket_permissions
extern

Definition at line 107 of file pqcomm.c.

Referenced by Setup_AF_UNIX(), and show_unix_socket_permissions().