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 1881 of file postmaster.c.

1882{
1883 /* Release resources held by the postmaster's WaitEventSet. */
1884 if (pm_wait_set)
1885 {
1887 pm_wait_set = NULL;
1888 }
1889
1890#ifndef WIN32
1891
1892 /*
1893 * Close the write end of postmaster death watch pipe. It's important to
1894 * do this as early as possible, so that if postmaster dies, others won't
1895 * think that it's still running because we're holding the pipe open.
1896 */
1898 ereport(FATAL,
1900 errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
1902 /* Notify fd.c that we released one pipe FD. */
1904#endif
1905
1906 /*
1907 * Close the postmaster's listen sockets. These aren't tracked by fd.c,
1908 * so we don't call ReleaseExternalFD() here.
1909 *
1910 * The listen sockets are marked as FD_CLOEXEC, so this isn't needed in
1911 * EXEC_BACKEND mode.
1912 */
1913#ifndef EXEC_BACKEND
1914 if (ListenSockets)
1915 {
1916 for (int i = 0; i < NumListenSockets; i++)
1917 {
1918 if (closesocket(ListenSockets[i]) != 0)
1919 elog(LOG, "could not close listen socket: %m");
1920 }
1922 }
1923 NumListenSockets = 0;
1925#endif
1926
1927 /*
1928 * If using syslogger, close the read side of the pipe. We don't bother
1929 * tracking this in fd.c, either.
1930 */
1931 if (!am_syslogger)
1932 {
1933#ifndef WIN32
1934 if (syslogPipe[0] >= 0)
1935 close(syslogPipe[0]);
1936 syslogPipe[0] = -1;
1937#else
1938 if (syslogPipe[0])
1940 syslogPipe[0] = 0;
1941#endif
1942 }
1943
1944#ifdef USE_BONJOUR
1945 /* If using Bonjour, close the connection to the mDNS daemon */
1946 if (bonjour_sdref)
1948#endif
1949}
int errcode_for_file_access(void)
Definition elog.c:898
#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:487
static WaitEventSet * pm_wait_set
Definition postmaster.c:401
#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 1958 of file postmaster.c.

1959{
1962
1963 /* initialize timing infrastructure (required for INSTR_* calls) */
1965
1966 /*
1967 * Set a different global seed in every process. We want something
1968 * unpredictable, so if possible, use high-quality random bits for the
1969 * seed. Otherwise, fall back to a seed based on timestamp and PID.
1970 */
1972 {
1973 uint64 rseed;
1974
1975 /*
1976 * Since PIDs and timestamps tend to change more frequently in their
1977 * least significant bits, shift the timestamp left to allow a larger
1978 * total number of seeds in a given time period. Since that would
1979 * leave only 20 bits of the timestamp that cycle every ~1 second,
1980 * also mix in some higher bits.
1981 */
1982 rseed = ((uint64) MyProcPid) ^
1983 ((uint64) MyStartTimestamp << 12) ^
1984 ((uint64) MyStartTimestamp >> 20);
1985
1987 }
1988
1989 /*
1990 * Also make sure that we've set a good seed for random(3). Use of that
1991 * is deprecated in core Postgres, but extensions might use it.
1992 */
1993#ifndef WIN32
1995#endif
1996}
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 497 of file postmaster.c.

498{
500 int opt;
501 int status;
502 char *userDoption = NULL;
503 bool listen_addr_saved = false;
505
507
509
511
512 /*
513 * Start our win32 signal implementation
514 */
515#ifdef WIN32
517#endif
518
519 /*
520 * We should not be creating any files or directories before we check the
521 * data directory (see checkDataDir()), but just in case set the umask to
522 * the most restrictive (owner-only) permissions.
523 *
524 * checkDataDir() will reset the umask based on the data directory
525 * permissions.
526 */
528
529 /*
530 * By default, palloc() requests in the postmaster will be allocated in
531 * the PostmasterContext, which is space that can be recycled by backends.
532 * Allocated data that needs to be available to backends should be
533 * allocated in TopMemoryContext.
534 */
536 "Postmaster",
539
540 /* Initialize paths to installation files */
541 getInstallationPaths(argv[0]);
542
543 /*
544 * Set up signal handlers for the postmaster process.
545 *
546 * CAUTION: when changing this list, check for side-effects on the signal
547 * handling setup of child processes. See tcop/postgres.c,
548 * bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
549 * postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/syslogger.c,
550 * postmaster/bgworker.c and postmaster/checkpointer.c.
551 */
552 pqinitmask();
554
559 pqsignal(SIGALRM, PG_SIG_IGN); /* ignored */
560 pqsignal(SIGPIPE, PG_SIG_IGN); /* ignored */
562 pqsignal(SIGUSR2, dummy_handler); /* unused, reserve for children */
564
565 /* This may configure SIGURG, depending on platform. */
568
569 /*
570 * No other place in Postgres should touch SIGTTIN/SIGTTOU handling. We
571 * ignore those signals in a postmaster environment, so that there is no
572 * risk of a child process freezing up due to writing to stderr. But for
573 * a standalone backend, their default handling is reasonable. Hence, all
574 * child processes should just allow the inherited settings to stand.
575 */
576#ifdef SIGTTIN
577 pqsignal(SIGTTIN, PG_SIG_IGN); /* ignored */
578#endif
579#ifdef SIGTTOU
580 pqsignal(SIGTTOU, PG_SIG_IGN); /* ignored */
581#endif
582
583 /* ignore SIGXFSZ, so that ulimit violations work like disk full */
584#ifdef SIGXFSZ
585 pqsignal(SIGXFSZ, PG_SIG_IGN); /* ignored */
586#endif
587
588 /* Begin accepting signals. */
590
591 /*
592 * Options setup
593 */
595
596 /*
597 * Parse command-line options. CAUTION: keep this in sync with
598 * tcop/postgres.c (the option sets should not conflict) and with the
599 * common help() function in main/main.c.
600 */
601 pg_getopt_start(&optctx, argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:OPp:r:S:sTt:W:-:");
602 optctx.opterr = 1;
603 while ((opt = pg_getopt_next(&optctx)) != -1)
604 {
605 switch (opt)
606 {
607 case 'B':
608 SetConfigOption("shared_buffers", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
609 break;
610
611 case 'b':
612 /* Undocumented flag used for binary upgrades */
613 IsBinaryUpgrade = true;
614 break;
615
616 case 'C':
618 break;
619
620 case '-':
621
622 /*
623 * Error if the user misplaced a special must-be-first option
624 * for dispatching to a subprogram. parse_dispatch_option()
625 * returns DISPATCH_POSTMASTER if it doesn't find a match, so
626 * error for anything else.
627 */
631 errmsg("--%s must be first argument", optctx.optarg)));
632
634 case 'c':
635 {
636 char *name,
637 *value;
638
639 ParseLongOption(optctx.optarg, &name, &value);
640 if (!value)
641 {
642 if (opt == '-')
645 errmsg("--%s requires a value",
646 optctx.optarg)));
647 else
650 errmsg("-c %s requires a value",
651 optctx.optarg)));
652 }
653
655 pfree(name);
656 pfree(value);
657 break;
658 }
659
660 case 'D':
661 userDoption = strdup(optctx.optarg);
662 break;
663
664 case 'd':
666 break;
667
668 case 'E':
669 SetConfigOption("log_statement", "all", PGC_POSTMASTER, PGC_S_ARGV);
670 break;
671
672 case 'e':
673 SetConfigOption("datestyle", "euro", PGC_POSTMASTER, PGC_S_ARGV);
674 break;
675
676 case 'F':
677 SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
678 break;
679
680 case 'f':
682 {
683 write_stderr("%s: invalid argument for option -f: \"%s\"\n",
684 progname, optctx.optarg);
686 }
687 break;
688
689 case 'h':
690 SetConfigOption("listen_addresses", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
691 break;
692
693 case 'i':
694 SetConfigOption("listen_addresses", "*", PGC_POSTMASTER, PGC_S_ARGV);
695 break;
696
697 case 'j':
698 /* only used by interactive backend */
699 break;
700
701 case 'k':
702 SetConfigOption("unix_socket_directories", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
703 break;
704
705 case 'l':
707 break;
708
709 case 'N':
710 SetConfigOption("max_connections", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
711 break;
712
713 case 'O':
714 SetConfigOption("allow_system_table_mods", "true", PGC_POSTMASTER, PGC_S_ARGV);
715 break;
716
717 case 'P':
718 SetConfigOption("ignore_system_indexes", "true", PGC_POSTMASTER, PGC_S_ARGV);
719 break;
720
721 case 'p':
723 break;
724
725 case 'r':
726 /* only used by single-user backend */
727 break;
728
729 case 'S':
730 SetConfigOption("work_mem", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
731 break;
732
733 case 's':
734 SetConfigOption("log_statement_stats", "true", PGC_POSTMASTER, PGC_S_ARGV);
735 break;
736
737 case 'T':
738
739 /*
740 * This option used to be defined as sending SIGSTOP after a
741 * backend crash, but sending SIGABRT seems more useful.
742 */
743 SetConfigOption("send_abort_for_crash", "true", PGC_POSTMASTER, PGC_S_ARGV);
744 break;
745
746 case 't':
747 {
748 const char *tmp = get_stats_option_name(optctx.optarg);
749
750 if (tmp)
751 {
753 }
754 else
755 {
756 write_stderr("%s: invalid argument for option -t: \"%s\"\n",
757 progname, optctx.optarg);
759 }
760 break;
761 }
762
763 case 'W':
764 SetConfigOption("post_auth_delay", optctx.optarg, PGC_POSTMASTER, PGC_S_ARGV);
765 break;
766
767 default:
768 write_stderr("Try \"%s --help\" for more information.\n",
769 progname);
771 }
772 }
773
774 /*
775 * Postmaster accepts no non-option switch arguments.
776 */
777 if (optctx.optind < argc)
778 {
779 write_stderr("%s: invalid argument: \"%s\"\n",
780 progname, argv[optctx.optind]);
781 write_stderr("Try \"%s --help\" for more information.\n",
782 progname);
784 }
785
786 /*
787 * Locate the proper configuration files and data directory, and read
788 * postgresql.conf for the first time.
789 */
792
794 {
795 /*
796 * If this is a runtime-computed GUC, it hasn't yet been initialized,
797 * and the present value is not useful. However, this is a convenient
798 * place to print the value for most GUCs because it is safe to run
799 * postmaster startup to this point even if the server is already
800 * running. For the handful of runtime-computed GUCs that we cannot
801 * provide meaningful values for yet, we wait until later in
802 * postmaster startup to print the value. We won't be able to use -C
803 * on running servers for those GUCs, but using this option now would
804 * lead to incorrect results for them.
805 */
807
808 if ((flags & GUC_RUNTIME_COMPUTED) == 0)
809 {
810 /*
811 * "-C guc" was specified, so print GUC's value and exit. No
812 * extra permission check is needed because the user is reading
813 * inside the data dir.
814 */
816 false, false);
817
818 puts(config_val ? config_val : "");
820 }
821
822 /*
823 * A runtime-computed GUC will be printed later on. As we initialize
824 * a server startup sequence, silence any log messages that may show
825 * up in the output generated. FATAL and more severe messages are
826 * useful to show, even if one would only expect at least PANIC. LOG
827 * entries are hidden.
828 */
829 SetConfigOption("log_min_messages", "FATAL", PGC_SUSET,
831 }
832
833 /* Verify that DataDir looks reasonable */
834 checkDataDir();
835
836 /* Check that pg_control exists */
838
839 /* And switch working directory into it */
841
842 /*
843 * Check for invalid combinations of GUC settings.
844 */
846 {
847 write_stderr("%s: \"superuser_reserved_connections\" (%d) plus \"reserved_connections\" (%d) must be less than \"max_connections\" (%d)\n",
848 progname,
852 }
855 (errmsg("WAL archival cannot be enabled when \"wal_level\" is \"minimal\"")));
858 (errmsg("WAL streaming (\"max_wal_senders\" > 0) requires \"wal_level\" to be \"replica\" or \"logical\"")));
861 (errmsg("WAL cannot be summarized when \"wal_level\" is \"minimal\"")));
864 (errmsg("replication slot synchronization (\"sync_replication_slots\" = on) requires \"wal_level\" to be \"replica\" or \"logical\"")));
865
866 /*
867 * Other one-time internal sanity checks can go here, if they are fast.
868 * (Put any slow processing further down, after postmaster.pid creation.)
869 */
871 {
872 write_stderr("%s: invalid datetoken tables, please fix\n", progname);
874 }
875
876 /* For debugging: display postmaster environment */
878 {
879#if !defined(WIN32)
880 extern char **environ;
881#endif
882 char **p;
884
886
887 appendStringInfoString(&si, "initial environment dump:");
888 for (p = environ; *p; ++p)
889 appendStringInfo(&si, "\n%s", *p);
890
891 ereport(DEBUG3, errmsg_internal("%s", si.data));
892 pfree(si.data);
893 }
894
895 /*
896 * Create lockfile for data directory.
897 *
898 * We want to do this before we try to grab the input sockets, because the
899 * data directory interlock is more reliable than the socket-file
900 * interlock (thanks to whoever decided to put socket files in /tmp :-().
901 * For the same reason, it's best to grab the TCP socket(s) before the
902 * Unix socket(s).
903 *
904 * Also note that this internally sets up the on_proc_exit function that
905 * is responsible for removing both data directory and socket lockfiles;
906 * so it must happen before opening sockets so that at exit, the socket
907 * lockfiles go away after CloseServerPorts runs.
908 */
910
911 /*
912 * Read the control file (for error checking and config info).
913 *
914 * Since we verify the control file's CRC, this has a useful side effect
915 * on machines where we need a run-time test for CRC support instructions.
916 * The postmaster will do the test once at startup, and then its child
917 * processes will inherit the correct function pointer and not need to
918 * repeat the test.
919 */
921
922 /*
923 * Register the apply launcher. It's probably a good idea to call this
924 * before any modules had a chance to take the background worker slots.
925 */
927
928 /*
929 * Register the shared memory needs of all core subsystems.
930 */
932
933 /*
934 * process any libraries that should be preloaded at postmaster start
935 */
937
938 /*
939 * Initialize SSL library, if specified.
940 */
941#ifdef USE_SSL
942 if (EnableSSL)
943 {
944 (void) secure_initialize(true);
945 LoadedSSL = true;
946 }
947#endif
948
949 /*
950 * Now that loadable modules have had their chance to alter any GUCs,
951 * calculate MaxBackends and initialize the machinery to track child
952 * processes.
953 */
956
957 /*
958 * Calculate the size of the PGPROC fast-path lock arrays.
959 */
961
962 /*
963 * Also call any legacy shmem request hooks that might've been installed
964 * by preloaded libraries.
965 *
966 * Note: this must be done before ShmemCallRequestCallbacks(), because the
967 * hooks may request LWLocks with RequestNamedLWLockTranche(), which in
968 * turn affects the size of the LWLock array calculated in lwlock.c.
969 */
971
972 /*
973 * Ask all subsystems, including preloaded libraries, to register their
974 * shared memory needs.
975 */
977
978 /*
979 * Now that loadable modules have had their chance to request additional
980 * shared memory, determine the value of any runtime-computed GUCs that
981 * depend on the amount of shared memory required.
982 */
984
985 /*
986 * Now that modules have been loaded, we can process any custom resource
987 * managers specified in the wal_consistency_checking GUC.
988 */
990
991 /*
992 * If -C was specified with a runtime-computed GUC, we held off printing
993 * the value earlier, as the GUC was not yet initialized. We handle -C
994 * for most GUCs before we lock the data directory so that the option may
995 * be used on a running server. However, a handful of GUCs are runtime-
996 * computed and do not have meaningful values until after locking the data
997 * directory, and we cannot safely calculate their values earlier on a
998 * running server. At this point, such GUCs should be properly
999 * initialized, and we haven't yet set up shared memory, so this is a good
1000 * time to handle the -C option for these special GUCs.
1001 */
1003 {
1005 false, false);
1006
1007 puts(config_val ? config_val : "");
1008 ExitPostmaster(0);
1009 }
1010
1011 /*
1012 * Set up shared memory and semaphores.
1013 *
1014 * Note: if using SysV shmem and/or semas, each postmaster startup will
1015 * normally choose the same IPC keys. This helps ensure that we will
1016 * clean up dead IPC objects if the postmaster crashes and is restarted.
1017 */
1019
1020 /*
1021 * Estimate number of openable files. This must happen after setting up
1022 * semaphores, because on some platforms semaphores count as open files.
1023 */
1025
1026 /*
1027 * Initialize pipe (or process handle on Windows) that allows children to
1028 * wake up from sleep on postmaster death.
1029 */
1031
1032#ifdef WIN32
1033
1034 /*
1035 * Initialize I/O completion port used to deliver list of dead children.
1036 */
1038 if (win32ChildQueue == NULL)
1039 ereport(FATAL,
1040 (errmsg("could not create I/O completion port for child queue")));
1041#endif
1042
1043#ifdef EXEC_BACKEND
1044 /* Write out nondefault GUC settings for child processes to use */
1046
1047 /*
1048 * Clean out the temp directory used to transmit parameters to child
1049 * processes (see internal_forkexec). We must do this before launching
1050 * any child processes, else we have a race condition: we could remove a
1051 * parameter file before the child can read it. It should be safe to do
1052 * so now, because we verified earlier that there are no conflicting
1053 * Postgres processes in this data directory.
1054 */
1056#endif
1057
1058 /*
1059 * Forcibly remove the files signaling a standby promotion request.
1060 * Otherwise, the existence of those files triggers a promotion too early,
1061 * whether a user wants that or not.
1062 *
1063 * This removal of files is usually unnecessary because they can exist
1064 * only during a few moments during a standby promotion. However there is
1065 * a race condition: if pg_ctl promote is executed and creates the files
1066 * during a promotion, the files can stay around even after the server is
1067 * brought up to be the primary. Then, if a new standby starts by using
1068 * the backup taken from the new primary, the files can exist at server
1069 * startup and must be removed in order to avoid an unexpected promotion.
1070 *
1071 * Note that promotion signal files need to be removed before the startup
1072 * process is invoked. Because, after that, they can be used by
1073 * postmaster's SIGUSR1 signal handler.
1074 */
1076
1077 /* Do the same for logrotate signal file */
1079
1080 /* Remove any outdated file holding the current log filenames. */
1082 ereport(LOG,
1084 errmsg("could not remove file \"%s\": %m",
1086
1087 /*
1088 * If enabled, start up syslogger collection subprocess
1089 */
1092
1093 /*
1094 * Reset whereToSendOutput from DestDebug (its starting state) to
1095 * DestNone. This stops ereport from sending log messages to stderr unless
1096 * Log_destination permits. We don't do this until the postmaster is
1097 * fully launched, since startup failures may as well be reported to
1098 * stderr.
1099 *
1100 * If we are in fact disabling logging to stderr, first emit a log message
1101 * saying so, to provide a breadcrumb trail for users who may not remember
1102 * that their logging is configured to go somewhere else.
1103 */
1105 ereport(LOG,
1106 (errmsg("ending log output to stderr"),
1107 errhint("Future log output will go to log destination \"%s\".",
1109
1111
1112 /*
1113 * Report server startup in log. While we could emit this much earlier,
1114 * it seems best to do so after starting the log collector, if we intend
1115 * to use one.
1116 */
1117 ereport(LOG,
1118 (errmsg("starting %s", PG_VERSION_STR)));
1119
1120 /*
1121 * Establish input sockets.
1122 *
1123 * First set up an on_proc_exit function that's charged with closing the
1124 * sockets again at postmaster shutdown.
1125 */
1128
1129 if (ListenAddresses)
1130 {
1131 char *rawstring;
1132 List *elemlist;
1133 ListCell *l;
1134 int success = 0;
1135
1136 /* Need a modifiable copy of ListenAddresses */
1138
1139 /* Parse string into list of hostnames */
1140 if (!SplitGUCList(rawstring, ',', &elemlist))
1141 {
1142 /* syntax error in list */
1143 ereport(FATAL,
1145 errmsg("invalid list syntax in parameter \"%s\"",
1146 "listen_addresses")));
1147 }
1148
1149 foreach(l, elemlist)
1150 {
1151 char *curhost = (char *) lfirst(l);
1152
1153 if (strcmp(curhost, "*") == 0)
1155 (unsigned short) PostPortNumber,
1156 NULL,
1159 MAXLISTEN);
1160 else
1162 (unsigned short) PostPortNumber,
1163 NULL,
1166 MAXLISTEN);
1167
1168 if (status == STATUS_OK)
1169 {
1170 success++;
1171 /* record the first successful host addr in lockfile */
1172 if (!listen_addr_saved)
1173 {
1175 listen_addr_saved = true;
1176 }
1177 }
1178 else
1180 (errmsg("could not create listen socket for \"%s\"",
1181 curhost)));
1182 }
1183
1184 if (!success && elemlist != NIL)
1185 ereport(FATAL,
1186 (errmsg("could not create any TCP/IP sockets")));
1187
1190 }
1191
1192#ifdef USE_BONJOUR
1193 /* Register for Bonjour only if we opened TCP socket(s) */
1195 {
1197
1198 /*
1199 * We pass 0 for interface_index, which will result in registering on
1200 * all "applicable" interfaces. It's not entirely clear from the
1201 * DNS-SD docs whether this would be appropriate if we have bound to
1202 * just a subset of the available network interfaces.
1203 */
1205 0,
1206 0,
1208 "_postgresql._tcp.",
1209 NULL,
1210 NULL,
1212 0,
1213 NULL,
1214 NULL,
1215 NULL);
1217 ereport(LOG,
1218 (errmsg("DNSServiceRegister() failed: error code %ld",
1219 (long) err)));
1220
1221 /*
1222 * We don't bother to read the mDNS daemon's reply, and we expect that
1223 * it will automatically terminate our registration when the socket is
1224 * closed at postmaster termination. So there's nothing more to be
1225 * done here. However, the bonjour_sdref is kept around so that
1226 * forked children can close their copies of the socket.
1227 */
1228 }
1229#endif
1230
1232 {
1233 char *rawstring;
1234 List *elemlist;
1235 ListCell *l;
1236 int success = 0;
1237
1238 /* Need a modifiable copy of Unix_socket_directories */
1240
1241 /* Parse string into list of directories */
1243 {
1244 /* syntax error in list */
1245 ereport(FATAL,
1247 errmsg("invalid list syntax in parameter \"%s\"",
1248 "unix_socket_directories")));
1249 }
1250
1251 foreach(l, elemlist)
1252 {
1253 char *socketdir = (char *) lfirst(l);
1254
1255 status = ListenServerPort(AF_UNIX, NULL,
1256 (unsigned short) PostPortNumber,
1257 socketdir,
1260 MAXLISTEN);
1261
1262 if (status == STATUS_OK)
1263 {
1264 success++;
1265 /* record the first successful Unix socket in lockfile */
1266 if (success == 1)
1268 }
1269 else
1271 (errmsg("could not create Unix-domain socket in directory \"%s\"",
1272 socketdir)));
1273 }
1274
1275 if (!success && elemlist != NIL)
1276 ereport(FATAL,
1277 (errmsg("could not create any Unix-domain sockets")));
1278
1281 }
1282
1283 /*
1284 * check that we have some socket to listen on
1285 */
1286 if (NumListenSockets == 0)
1287 ereport(FATAL,
1288 (errmsg("no socket created for listening")));
1289
1290 /*
1291 * If no valid TCP ports, write an empty line for listen address,
1292 * indicating the Unix socket must be used. Note that this line is not
1293 * added to the lock file until there is a socket backing it.
1294 */
1295 if (!listen_addr_saved)
1297
1298 /*
1299 * Record postmaster options. We delay this till now to avoid recording
1300 * bogus options (eg, unusable port number).
1301 */
1302 if (!CreateOptsFile(argc, argv, my_exec_path))
1303 ExitPostmaster(1);
1304
1305 /*
1306 * Write the external PID file if requested
1307 */
1309 {
1311
1312 if (fpidfile)
1313 {
1314 fprintf(fpidfile, "%d\n", MyProcPid);
1316
1317 /* Make PID file world readable */
1319 write_stderr("%s: could not change permissions of external PID file \"%s\": %m\n",
1321 }
1322 else
1323 write_stderr("%s: could not write external PID file \"%s\": %m\n",
1325
1327 }
1328
1329 /*
1330 * Remove old temporary files. At this point there can be no other
1331 * Postgres processes running in this directory, so this should be safe.
1332 */
1334
1335 /*
1336 * Initialize the autovacuum subsystem (again, no process start yet)
1337 */
1338 autovac_init();
1339
1340 /*
1341 * Load configuration files for client authentication.
1342 */
1343 if (!load_hba())
1344 {
1345 /*
1346 * It makes no sense to continue if we fail to load the HBA file,
1347 * since there is no way to connect to the database in this case.
1348 */
1349 ereport(FATAL,
1350 /* translator: %s is a configuration file */
1351 (errmsg("could not load %s", HbaFileName)));
1352 }
1353 if (!load_ident())
1354 {
1355 /*
1356 * We can start up without the IDENT file, although it means that you
1357 * cannot log in using any of the authentication methods that need a
1358 * user name mapping. load_ident() already logged the details of error
1359 * to the log.
1360 */
1361 }
1362
1363#ifdef HAVE_PTHREAD_IS_THREADED_NP
1364
1365 /*
1366 * On macOS, libintl replaces setlocale() with a version that calls
1367 * CFLocaleCopyCurrent() when its second argument is "" and every relevant
1368 * environment variable is unset or empty. CFLocaleCopyCurrent() makes
1369 * the process multithreaded. The postmaster calls sigprocmask() and
1370 * calls fork() without an immediate exec(), both of which have undefined
1371 * behavior in a multithreaded program. A multithreaded postmaster is the
1372 * normal case on Windows, which offers neither fork() nor sigprocmask().
1373 * Currently, macOS is the only platform having pthread_is_threaded_np(),
1374 * so we need not worry whether this HINT is appropriate elsewhere.
1375 */
1376 if (pthread_is_threaded_np() != 0)
1377 ereport(FATAL,
1379 errmsg("postmaster became multithreaded during startup"),
1380 errhint("Set the LC_ALL environment variable to a valid locale.")));
1381#endif
1382
1383 /*
1384 * Remember postmaster startup time
1385 */
1387
1388 /*
1389 * Report postmaster status in the postmaster.pid file, to allow pg_ctl to
1390 * see what's happening.
1391 */
1393
1395
1396 /* Make sure we can perform I/O while starting up. */
1398
1399 /* Start bgwriter and checkpointer so they can help with recovery */
1402 if (BgWriterPMChild == NULL)
1404
1405 /*
1406 * We're ready to rock and roll...
1407 */
1411
1412 /* Some workers may be scheduled to start now */
1414
1415 status = ServerLoop();
1416
1417 /*
1418 * ServerLoop probably shouldn't ever return, but if it does, close down.
1419 */
1420 ExitPostmaster(status != STATUS_OK);
1421
1422 abort(); /* not reached */
1423}
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:116
bool message_level_is_interesting(int elevel)
Definition elog.c:285
char * Log_destination_string
Definition elog.c:117
int errcode(int sqlerrcode)
Definition elog.c:875
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
#define PG_SIG_IGN
Definition port.h:551
int pgsocket
Definition port.h:29
void set_debug_options(int debug_flag, GucContext context, GucSource source)
Definition postgres.c:3760
CommandDest whereToSendOutput
Definition postgres.c:97
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition postgres.c:3792
const char * get_stats_option_name(const char *arg)
Definition postgres.c:3834
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:339
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:5194
void LocalProcessControlFile(bool reset)
Definition xlog.c:5275
@ 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_SIG_IGN, 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 4560 of file postmaster.c.

4561{
4562 dlist_iter iter;
4563 PMChild *bp;
4564
4566 {
4567 bp = dlist_container(PMChild, elem, iter.cur);
4568 if (bp->pid == pid)
4569 {
4570 bp->bgworker_notify = true;
4571 return true;
4572 }
4573 }
4574 return false;
4575}

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