PostgreSQL Source Code  git master
postmaster.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

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

Functions

void PostmasterMain (int argc, char *argv[]) pg_attribute_noreturn()
 
void ClosePostmasterPorts (bool am_syslogger)
 
void InitProcessGlobals (void)
 
int MaxLivePostmasterChildren (void)
 
bool PostmasterMarkPIDForWorkerNotify (int)
 

Variables

PGDLLIMPORT bool EnableSSL
 
PGDLLIMPORT int SuperuserReservedConnections
 
PGDLLIMPORT int ReservedConnections
 
PGDLLIMPORT int PostPortNumber
 
PGDLLIMPORT int Unix_socket_permissions
 
PGDLLIMPORT char * Unix_socket_group
 
PGDLLIMPORT char * Unix_socket_directories
 
PGDLLIMPORT char * ListenAddresses
 
PGDLLIMPORT bool ClientAuthInProgress
 
PGDLLIMPORT int PreAuthDelay
 
PGDLLIMPORT int AuthenticationTimeout
 
PGDLLIMPORT bool Log_connections
 
PGDLLIMPORT bool log_hostname
 
PGDLLIMPORT bool enable_bonjour
 
PGDLLIMPORT char * bonjour_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 char * progname
 

Macro Definition Documentation

◆ MAX_BACKENDS

#define MAX_BACKENDS   0x3FFFF

Definition at line 78 of file postmaster.h.

◆ POSTMASTER_FD_OWN

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

Definition at line 47 of file postmaster.h.

◆ POSTMASTER_FD_WATCH

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

Definition at line 46 of file postmaster.h.

Function Documentation

◆ ClosePostmasterPorts()

void ClosePostmasterPorts ( bool  am_syslogger)

Definition at line 2502 of file postmaster.c.

2503 {
2504  /* Release resources held by the postmaster's WaitEventSet. */
2505  if (pm_wait_set)
2506  {
2508  pm_wait_set = NULL;
2509  }
2510 
2511 #ifndef WIN32
2512 
2513  /*
2514  * Close the write end of postmaster death watch pipe. It's important to
2515  * do this as early as possible, so that if postmaster dies, others won't
2516  * think that it's still running because we're holding the pipe open.
2517  */
2519  ereport(FATAL,
2521  errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
2523  /* Notify fd.c that we released one pipe FD. */
2525 #endif
2526 
2527  /*
2528  * Close the postmaster's listen sockets. These aren't tracked by fd.c,
2529  * so we don't call ReleaseExternalFD() here.
2530  *
2531  * The listen sockets are marked as FD_CLOEXEC, so this isn't needed in
2532  * EXEC_BACKEND mode.
2533  */
2534 #ifndef EXEC_BACKEND
2535  if (ListenSockets)
2536  {
2537  for (int i = 0; i < NumListenSockets; i++)
2540  }
2541  NumListenSockets = 0;
2542  ListenSockets = NULL;
2543 #endif
2544 
2545  /*
2546  * If using syslogger, close the read side of the pipe. We don't bother
2547  * tracking this in fd.c, either.
2548  */
2549  if (!am_syslogger)
2550  {
2551 #ifndef WIN32
2552  if (syslogPipe[0] >= 0)
2553  close(syslogPipe[0]);
2554  syslogPipe[0] = -1;
2555 #else
2556  if (syslogPipe[0])
2557  CloseHandle(syslogPipe[0]);
2558  syslogPipe[0] = 0;
2559 #endif
2560  }
2561 
2562 #ifdef USE_BONJOUR
2563  /* If using Bonjour, close the connection to the mDNS daemon */
2564  if (bonjour_sdref)
2565  close(DNSServiceRefSockFD(bonjour_sdref));
2566 #endif
2567 }
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1162
int errcode_for_file_access(void)
Definition: elog.c:883
#define FATAL
Definition: elog.h:41
#define ereport(elevel,...)
Definition: elog.h:149
void ReleaseExternalFD(void)
Definition: fd.c:1239
#define close(a)
Definition: win32.h:12
int i
Definition: isn.c:73
void FreeWaitEventSetAfterFork(WaitEventSet *set)
Definition: latch.c:918
void pfree(void *pointer)
Definition: mcxt.c:1431
static pgsocket * ListenSockets
Definition: postmaster.c:231
static int NumListenSockets
Definition: postmaster.c:230
int postmaster_alive_fds[2]
Definition: postmaster.c:577
static WaitEventSet * pm_wait_set
Definition: postmaster.c:386
#define POSTMASTER_FD_OWN
Definition: postmaster.h:47
void StreamClose(pgsocket sock)
Definition: pqcomm.c:831
int syslogPipe[2]
Definition: syslogger.c:117

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

Referenced by BackendStartup(), do_start_bgworker(), StartAutoVacWorker(), StartChildProcess(), StartSlotSyncWorker(), and SysLogger_Start().

◆ InitProcessGlobals()

void InitProcessGlobals ( void  )

Definition at line 2576 of file postmaster.c.

2577 {
2578  MyProcPid = getpid();
2581 
2582  /*
2583  * Set a different global seed in every process. We want something
2584  * unpredictable, so if possible, use high-quality random bits for the
2585  * seed. Otherwise, fall back to a seed based on timestamp and PID.
2586  */
2588  {
2589  uint64 rseed;
2590 
2591  /*
2592  * Since PIDs and timestamps tend to change more frequently in their
2593  * least significant bits, shift the timestamp left to allow a larger
2594  * total number of seeds in a given time period. Since that would
2595  * leave only 20 bits of the timestamp that cycle every ~1 second,
2596  * also mix in some higher bits.
2597  */
2598  rseed = ((uint64) MyProcPid) ^
2599  ((uint64) MyStartTimestamp << 12) ^
2600  ((uint64) MyStartTimestamp >> 20);
2601 
2603  }
2604 
2605  /*
2606  * Also make sure that we've set a good seed for random(3). Use of that
2607  * is deprecated in core Postgres, but extensions might use it.
2608  */
2609 #ifndef WIN32
2611 #endif
2612 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1655
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition: timestamp.c:1834
#define unlikely(x)
Definition: c.h:300
int MyProcPid
Definition: globals.c:45
TimestampTz MyStartTimestamp
Definition: globals.c:47
pg_time_t MyStartTime
Definition: globals.c:46
uint32 pg_prng_uint32(pg_prng_state *state)
Definition: pg_prng.c:191
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 GetCurrentTimestamp(), MyProcPid, MyStartTime, MyStartTimestamp, pg_global_prng_state, 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  )

Definition at line 5612 of file postmaster.c.

5613 {
5614  return 2 * (MaxConnections + autovacuum_max_workers + 1 +
5616 }
int autovacuum_max_workers
Definition: autovacuum.c:118
int MaxConnections
Definition: globals.c:140
int max_worker_processes
Definition: globals.c:141
int max_wal_senders
Definition: walsender.c:124

References autovacuum_max_workers, max_wal_senders, max_worker_processes, and MaxConnections.

Referenced by canAcceptConnections(), PMSignalShmemInit(), PMSignalShmemSize(), and processCancelRequest().

◆ PostmasterMain()

void PostmasterMain ( int  argc,
char *  argv[] 
)

Definition at line 587 of file postmaster.c.

588 {
589  int opt;
590  int status;
591  char *userDoption = NULL;
592  bool listen_addr_saved = false;
593  char *output_config_variable = NULL;
594 
596 
598 
600 
601  /*
602  * Start our win32 signal implementation
603  */
604 #ifdef WIN32
606 #endif
607 
608  /*
609  * We should not be creating any files or directories before we check the
610  * data directory (see checkDataDir()), but just in case set the umask to
611  * the most restrictive (owner-only) permissions.
612  *
613  * checkDataDir() will reset the umask based on the data directory
614  * permissions.
615  */
616  umask(PG_MODE_MASK_OWNER);
617 
618  /*
619  * By default, palloc() requests in the postmaster will be allocated in
620  * the PostmasterContext, which is space that can be recycled by backends.
621  * Allocated data that needs to be available to backends should be
622  * allocated in TopMemoryContext.
623  */
625  "Postmaster",
628 
629  /* Initialize paths to installation files */
630  getInstallationPaths(argv[0]);
631 
632  /*
633  * Set up signal handlers for the postmaster process.
634  *
635  * CAUTION: when changing this list, check for side-effects on the signal
636  * handling setup of child processes. See tcop/postgres.c,
637  * bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
638  * postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/syslogger.c,
639  * postmaster/bgworker.c and postmaster/checkpointer.c.
640  */
641  pqinitmask();
642  sigprocmask(SIG_SETMASK, &BlockSig, NULL);
643 
648  pqsignal(SIGALRM, SIG_IGN); /* ignored */
649  pqsignal(SIGPIPE, SIG_IGN); /* ignored */
651  pqsignal(SIGUSR2, dummy_handler); /* unused, reserve for children */
653 
654  /* This may configure SIGURG, depending on platform. */
657 
658  /*
659  * No other place in Postgres should touch SIGTTIN/SIGTTOU handling. We
660  * ignore those signals in a postmaster environment, so that there is no
661  * risk of a child process freezing up due to writing to stderr. But for
662  * a standalone backend, their default handling is reasonable. Hence, all
663  * child processes should just allow the inherited settings to stand.
664  */
665 #ifdef SIGTTIN
666  pqsignal(SIGTTIN, SIG_IGN); /* ignored */
667 #endif
668 #ifdef SIGTTOU
669  pqsignal(SIGTTOU, SIG_IGN); /* ignored */
670 #endif
671 
672  /* ignore SIGXFSZ, so that ulimit violations work like disk full */
673 #ifdef SIGXFSZ
674  pqsignal(SIGXFSZ, SIG_IGN); /* ignored */
675 #endif
676 
677  /* Begin accepting signals. */
678  sigprocmask(SIG_SETMASK, &UnBlockSig, NULL);
679 
680  /*
681  * Options setup
682  */
684 
685  opterr = 1;
686 
687  /*
688  * Parse command-line options. CAUTION: keep this in sync with
689  * tcop/postgres.c (the option sets should not conflict) and with the
690  * common help() function in main/main.c.
691  */
692  while ((opt = getopt(argc, argv, "B:bC:c:D:d:EeFf:h:ijk:lN:OPp:r:S:sTt:W:-:")) != -1)
693  {
694  switch (opt)
695  {
696  case 'B':
697  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
698  break;
699 
700  case 'b':
701  /* Undocumented flag used for binary upgrades */
702  IsBinaryUpgrade = true;
703  break;
704 
705  case 'C':
706  output_config_variable = strdup(optarg);
707  break;
708 
709  case 'c':
710  case '-':
711  {
712  char *name,
713  *value;
714 
716  if (!value)
717  {
718  if (opt == '-')
719  ereport(ERROR,
720  (errcode(ERRCODE_SYNTAX_ERROR),
721  errmsg("--%s requires a value",
722  optarg)));
723  else
724  ereport(ERROR,
725  (errcode(ERRCODE_SYNTAX_ERROR),
726  errmsg("-c %s requires a value",
727  optarg)));
728  }
729 
731  pfree(name);
732  pfree(value);
733  break;
734  }
735 
736  case 'D':
737  userDoption = strdup(optarg);
738  break;
739 
740  case 'd':
742  break;
743 
744  case 'E':
745  SetConfigOption("log_statement", "all", PGC_POSTMASTER, PGC_S_ARGV);
746  break;
747 
748  case 'e':
749  SetConfigOption("datestyle", "euro", PGC_POSTMASTER, PGC_S_ARGV);
750  break;
751 
752  case 'F':
753  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
754  break;
755 
756  case 'f':
758  {
759  write_stderr("%s: invalid argument for option -f: \"%s\"\n",
760  progname, optarg);
761  ExitPostmaster(1);
762  }
763  break;
764 
765  case 'h':
766  SetConfigOption("listen_addresses", optarg, PGC_POSTMASTER, PGC_S_ARGV);
767  break;
768 
769  case 'i':
770  SetConfigOption("listen_addresses", "*", PGC_POSTMASTER, PGC_S_ARGV);
771  break;
772 
773  case 'j':
774  /* only used by interactive backend */
775  break;
776 
777  case 'k':
778  SetConfigOption("unix_socket_directories", optarg, PGC_POSTMASTER, PGC_S_ARGV);
779  break;
780 
781  case 'l':
782  SetConfigOption("ssl", "true", PGC_POSTMASTER, PGC_S_ARGV);
783  break;
784 
785  case 'N':
786  SetConfigOption("max_connections", optarg, PGC_POSTMASTER, PGC_S_ARGV);
787  break;
788 
789  case 'O':
790  SetConfigOption("allow_system_table_mods", "true", PGC_POSTMASTER, PGC_S_ARGV);
791  break;
792 
793  case 'P':
794  SetConfigOption("ignore_system_indexes", "true", PGC_POSTMASTER, PGC_S_ARGV);
795  break;
796 
797  case 'p':
799  break;
800 
801  case 'r':
802  /* only used by single-user backend */
803  break;
804 
805  case 'S':
807  break;
808 
809  case 's':
810  SetConfigOption("log_statement_stats", "true", PGC_POSTMASTER, PGC_S_ARGV);
811  break;
812 
813  case 'T':
814 
815  /*
816  * This option used to be defined as sending SIGSTOP after a
817  * backend crash, but sending SIGABRT seems more useful.
818  */
819  SetConfigOption("send_abort_for_crash", "true", PGC_POSTMASTER, PGC_S_ARGV);
820  break;
821 
822  case 't':
823  {
824  const char *tmp = get_stats_option_name(optarg);
825 
826  if (tmp)
827  {
829  }
830  else
831  {
832  write_stderr("%s: invalid argument for option -t: \"%s\"\n",
833  progname, optarg);
834  ExitPostmaster(1);
835  }
836  break;
837  }
838 
839  case 'W':
840  SetConfigOption("post_auth_delay", optarg, PGC_POSTMASTER, PGC_S_ARGV);
841  break;
842 
843  default:
844  write_stderr("Try \"%s --help\" for more information.\n",
845  progname);
846  ExitPostmaster(1);
847  }
848  }
849 
850  /*
851  * Postmaster accepts no non-option switch arguments.
852  */
853  if (optind < argc)
854  {
855  write_stderr("%s: invalid argument: \"%s\"\n",
856  progname, argv[optind]);
857  write_stderr("Try \"%s --help\" for more information.\n",
858  progname);
859  ExitPostmaster(1);
860  }
861 
862  /*
863  * Locate the proper configuration files and data directory, and read
864  * postgresql.conf for the first time.
865  */
867  ExitPostmaster(2);
868 
869  if (output_config_variable != NULL)
870  {
871  /*
872  * If this is a runtime-computed GUC, it hasn't yet been initialized,
873  * and the present value is not useful. However, this is a convenient
874  * place to print the value for most GUCs because it is safe to run
875  * postmaster startup to this point even if the server is already
876  * running. For the handful of runtime-computed GUCs that we cannot
877  * provide meaningful values for yet, we wait until later in
878  * postmaster startup to print the value. We won't be able to use -C
879  * on running servers for those GUCs, but using this option now would
880  * lead to incorrect results for them.
881  */
882  int flags = GetConfigOptionFlags(output_config_variable, true);
883 
884  if ((flags & GUC_RUNTIME_COMPUTED) == 0)
885  {
886  /*
887  * "-C guc" was specified, so print GUC's value and exit. No
888  * extra permission check is needed because the user is reading
889  * inside the data dir.
890  */
891  const char *config_val = GetConfigOption(output_config_variable,
892  false, false);
893 
894  puts(config_val ? config_val : "");
895  ExitPostmaster(0);
896  }
897 
898  /*
899  * A runtime-computed GUC will be printed later on. As we initialize
900  * a server startup sequence, silence any log messages that may show
901  * up in the output generated. FATAL and more severe messages are
902  * useful to show, even if one would only expect at least PANIC. LOG
903  * entries are hidden.
904  */
905  SetConfigOption("log_min_messages", "FATAL", PGC_SUSET,
907  }
908 
909  /* Verify that DataDir looks reasonable */
910  checkDataDir();
911 
912  /* Check that pg_control exists */
914 
915  /* And switch working directory into it */
916  ChangeToDataDir();
917 
918  /*
919  * Check for invalid combinations of GUC settings.
920  */
922  {
923  write_stderr("%s: superuser_reserved_connections (%d) plus reserved_connections (%d) must be less than max_connections (%d)\n",
924  progname,
927  ExitPostmaster(1);
928  }
930  ereport(ERROR,
931  (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
933  ereport(ERROR,
934  (errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
936  ereport(ERROR,
937  (errmsg("WAL cannot be summarized when wal_level is \"minimal\"")));
938 
939  /*
940  * Other one-time internal sanity checks can go here, if they are fast.
941  * (Put any slow processing further down, after postmaster.pid creation.)
942  */
943  if (!CheckDateTokenTables())
944  {
945  write_stderr("%s: invalid datetoken tables, please fix\n", progname);
946  ExitPostmaster(1);
947  }
948 
949  /*
950  * Now that we are done processing the postmaster arguments, reset
951  * getopt(3) library so that it will work correctly in subprocesses.
952  */
953  optind = 1;
954 #ifdef HAVE_INT_OPTRESET
955  optreset = 1; /* some systems need this too */
956 #endif
957 
958  /* For debugging: display postmaster environment */
959  {
960  extern char **environ;
961  char **p;
962 
963  ereport(DEBUG3,
964  (errmsg_internal("%s: PostmasterMain: initial environment dump:",
965  progname)));
966  ereport(DEBUG3,
967  (errmsg_internal("-----------------------------------------")));
968  for (p = environ; *p; ++p)
969  ereport(DEBUG3,
970  (errmsg_internal("\t%s", *p)));
971  ereport(DEBUG3,
972  (errmsg_internal("-----------------------------------------")));
973  }
974 
975  /*
976  * Create lockfile for data directory.
977  *
978  * We want to do this before we try to grab the input sockets, because the
979  * data directory interlock is more reliable than the socket-file
980  * interlock (thanks to whoever decided to put socket files in /tmp :-().
981  * For the same reason, it's best to grab the TCP socket(s) before the
982  * Unix socket(s).
983  *
984  * Also note that this internally sets up the on_proc_exit function that
985  * is responsible for removing both data directory and socket lockfiles;
986  * so it must happen before opening sockets so that at exit, the socket
987  * lockfiles go away after CloseServerPorts runs.
988  */
989  CreateDataDirLockFile(true);
990 
991  /*
992  * Read the control file (for error checking and config info).
993  *
994  * Since we verify the control file's CRC, this has a useful side effect
995  * on machines where we need a run-time test for CRC support instructions.
996  * The postmaster will do the test once at startup, and then its child
997  * processes will inherit the correct function pointer and not need to
998  * repeat the test.
999  */
1000  LocalProcessControlFile(false);
1001 
1002  /*
1003  * Register the apply launcher. It's probably a good idea to call this
1004  * before any modules had a chance to take the background worker slots.
1005  */
1007 
1008  /*
1009  * process any libraries that should be preloaded at postmaster start
1010  */
1012 
1013  /*
1014  * Initialize SSL library, if specified.
1015  */
1016 #ifdef USE_SSL
1017  if (EnableSSL)
1018  {
1019  (void) secure_initialize(true);
1020  LoadedSSL = true;
1021  }
1022 #endif
1023 
1024  /*
1025  * Now that loadable modules have had their chance to alter any GUCs,
1026  * calculate MaxBackends.
1027  */
1029 
1030  /*
1031  * Give preloaded libraries a chance to request additional shared memory.
1032  */
1034 
1035  /*
1036  * Now that loadable modules have had their chance to request additional
1037  * shared memory, determine the value of any runtime-computed GUCs that
1038  * depend on the amount of shared memory required.
1039  */
1041 
1042  /*
1043  * Now that modules have been loaded, we can process any custom resource
1044  * managers specified in the wal_consistency_checking GUC.
1045  */
1047 
1048  /*
1049  * If -C was specified with a runtime-computed GUC, we held off printing
1050  * the value earlier, as the GUC was not yet initialized. We handle -C
1051  * for most GUCs before we lock the data directory so that the option may
1052  * be used on a running server. However, a handful of GUCs are runtime-
1053  * computed and do not have meaningful values until after locking the data
1054  * directory, and we cannot safely calculate their values earlier on a
1055  * running server. At this point, such GUCs should be properly
1056  * initialized, and we haven't yet set up shared memory, so this is a good
1057  * time to handle the -C option for these special GUCs.
1058  */
1059  if (output_config_variable != NULL)
1060  {
1061  const char *config_val = GetConfigOption(output_config_variable,
1062  false, false);
1063 
1064  puts(config_val ? config_val : "");
1065  ExitPostmaster(0);
1066  }
1067 
1068  /*
1069  * Set up shared memory and semaphores.
1070  *
1071  * Note: if using SysV shmem and/or semas, each postmaster startup will
1072  * normally choose the same IPC keys. This helps ensure that we will
1073  * clean up dead IPC objects if the postmaster crashes and is restarted.
1074  */
1076 
1077  /*
1078  * Estimate number of openable files. This must happen after setting up
1079  * semaphores, because on some platforms semaphores count as open files.
1080  */
1081  set_max_safe_fds();
1082 
1083  /*
1084  * Set reference point for stack-depth checking.
1085  */
1086  (void) set_stack_base();
1087 
1088  /*
1089  * Initialize pipe (or process handle on Windows) that allows children to
1090  * wake up from sleep on postmaster death.
1091  */
1093 
1094 #ifdef WIN32
1095 
1096  /*
1097  * Initialize I/O completion port used to deliver list of dead children.
1098  */
1099  win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
1100  if (win32ChildQueue == NULL)
1101  ereport(FATAL,
1102  (errmsg("could not create I/O completion port for child queue")));
1103 #endif
1104 
1105 #ifdef EXEC_BACKEND
1106  /* Write out nondefault GUC settings for child processes to use */
1107  write_nondefault_variables(PGC_POSTMASTER);
1108 
1109  /*
1110  * Clean out the temp directory used to transmit parameters to child
1111  * processes (see internal_forkexec, below). We must do this before
1112  * launching any child processes, else we have a race condition: we could
1113  * remove a parameter file before the child can read it. It should be
1114  * safe to do so now, because we verified earlier that there are no
1115  * conflicting Postgres processes in this data directory.
1116  */
1118 #endif
1119 
1120  /*
1121  * Forcibly remove the files signaling a standby promotion request.
1122  * Otherwise, the existence of those files triggers a promotion too early,
1123  * whether a user wants that or not.
1124  *
1125  * This removal of files is usually unnecessary because they can exist
1126  * only during a few moments during a standby promotion. However there is
1127  * a race condition: if pg_ctl promote is executed and creates the files
1128  * during a promotion, the files can stay around even after the server is
1129  * brought up to be the primary. Then, if a new standby starts by using
1130  * the backup taken from the new primary, the files can exist at server
1131  * startup and must be removed in order to avoid an unexpected promotion.
1132  *
1133  * Note that promotion signal files need to be removed before the startup
1134  * process is invoked. Because, after that, they can be used by
1135  * postmaster's SIGUSR1 signal handler.
1136  */
1138 
1139  /* Do the same for logrotate signal file */
1141 
1142  /* Remove any outdated file holding the current log filenames. */
1143  if (unlink(LOG_METAINFO_DATAFILE) < 0 && errno != ENOENT)
1144  ereport(LOG,
1146  errmsg("could not remove file \"%s\": %m",
1148 
1149  /*
1150  * If enabled, start up syslogger collection subprocess
1151  */
1153 
1154  /*
1155  * Reset whereToSendOutput from DestDebug (its starting state) to
1156  * DestNone. This stops ereport from sending log messages to stderr unless
1157  * Log_destination permits. We don't do this until the postmaster is
1158  * fully launched, since startup failures may as well be reported to
1159  * stderr.
1160  *
1161  * If we are in fact disabling logging to stderr, first emit a log message
1162  * saying so, to provide a breadcrumb trail for users who may not remember
1163  * that their logging is configured to go somewhere else.
1164  */
1166  ereport(LOG,
1167  (errmsg("ending log output to stderr"),
1168  errhint("Future log output will go to log destination \"%s\".",
1170 
1172 
1173  /*
1174  * Report server startup in log. While we could emit this much earlier,
1175  * it seems best to do so after starting the log collector, if we intend
1176  * to use one.
1177  */
1178  ereport(LOG,
1179  (errmsg("starting %s", PG_VERSION_STR)));
1180 
1181  /*
1182  * Establish input sockets.
1183  *
1184  * First set up an on_proc_exit function that's charged with closing the
1185  * sockets again at postmaster shutdown.
1186  */
1187  ListenSockets = palloc(MAXLISTEN * sizeof(pgsocket));
1189 
1190  if (ListenAddresses)
1191  {
1192  char *rawstring;
1193  List *elemlist;
1194  ListCell *l;
1195  int success = 0;
1196 
1197  /* Need a modifiable copy of ListenAddresses */
1198  rawstring = pstrdup(ListenAddresses);
1199 
1200  /* Parse string into list of hostnames */
1201  if (!SplitGUCList(rawstring, ',', &elemlist))
1202  {
1203  /* syntax error in list */
1204  ereport(FATAL,
1205  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1206  errmsg("invalid list syntax in parameter \"%s\"",
1207  "listen_addresses")));
1208  }
1209 
1210  foreach(l, elemlist)
1211  {
1212  char *curhost = (char *) lfirst(l);
1213 
1214  if (strcmp(curhost, "*") == 0)
1215  status = StreamServerPort(AF_UNSPEC, NULL,
1216  (unsigned short) PostPortNumber,
1217  NULL,
1218  ListenSockets,
1220  MAXLISTEN);
1221  else
1222  status = StreamServerPort(AF_UNSPEC, curhost,
1223  (unsigned short) PostPortNumber,
1224  NULL,
1225  ListenSockets,
1227  MAXLISTEN);
1228 
1229  if (status == STATUS_OK)
1230  {
1231  success++;
1232  /* record the first successful host addr in lockfile */
1233  if (!listen_addr_saved)
1234  {
1236  listen_addr_saved = true;
1237  }
1238  }
1239  else
1240  ereport(WARNING,
1241  (errmsg("could not create listen socket for \"%s\"",
1242  curhost)));
1243  }
1244 
1245  if (!success && elemlist != NIL)
1246  ereport(FATAL,
1247  (errmsg("could not create any TCP/IP sockets")));
1248 
1249  list_free(elemlist);
1250  pfree(rawstring);
1251  }
1252 
1253 #ifdef USE_BONJOUR
1254  /* Register for Bonjour only if we opened TCP socket(s) */
1255  if (enable_bonjour && NumListenSockets > 0)
1256  {
1257  DNSServiceErrorType err;
1258 
1259  /*
1260  * We pass 0 for interface_index, which will result in registering on
1261  * all "applicable" interfaces. It's not entirely clear from the
1262  * DNS-SD docs whether this would be appropriate if we have bound to
1263  * just a subset of the available network interfaces.
1264  */
1265  err = DNSServiceRegister(&bonjour_sdref,
1266  0,
1267  0,
1268  bonjour_name,
1269  "_postgresql._tcp.",
1270  NULL,
1271  NULL,
1273  0,
1274  NULL,
1275  NULL,
1276  NULL);
1277  if (err != kDNSServiceErr_NoError)
1278  ereport(LOG,
1279  (errmsg("DNSServiceRegister() failed: error code %ld",
1280  (long) err)));
1281 
1282  /*
1283  * We don't bother to read the mDNS daemon's reply, and we expect that
1284  * it will automatically terminate our registration when the socket is
1285  * closed at postmaster termination. So there's nothing more to be
1286  * done here. However, the bonjour_sdref is kept around so that
1287  * forked children can close their copies of the socket.
1288  */
1289  }
1290 #endif
1291 
1293  {
1294  char *rawstring;
1295  List *elemlist;
1296  ListCell *l;
1297  int success = 0;
1298 
1299  /* Need a modifiable copy of Unix_socket_directories */
1300  rawstring = pstrdup(Unix_socket_directories);
1301 
1302  /* Parse string into list of directories */
1303  if (!SplitDirectoriesString(rawstring, ',', &elemlist))
1304  {
1305  /* syntax error in list */
1306  ereport(FATAL,
1307  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1308  errmsg("invalid list syntax in parameter \"%s\"",
1309  "unix_socket_directories")));
1310  }
1311 
1312  foreach(l, elemlist)
1313  {
1314  char *socketdir = (char *) lfirst(l);
1315 
1316  status = StreamServerPort(AF_UNIX, NULL,
1317  (unsigned short) PostPortNumber,
1318  socketdir,
1319  ListenSockets,
1321  MAXLISTEN);
1322 
1323  if (status == STATUS_OK)
1324  {
1325  success++;
1326  /* record the first successful Unix socket in lockfile */
1327  if (success == 1)
1329  }
1330  else
1331  ereport(WARNING,
1332  (errmsg("could not create Unix-domain socket in directory \"%s\"",
1333  socketdir)));
1334  }
1335 
1336  if (!success && elemlist != NIL)
1337  ereport(FATAL,
1338  (errmsg("could not create any Unix-domain sockets")));
1339 
1340  list_free_deep(elemlist);
1341  pfree(rawstring);
1342  }
1343 
1344  /*
1345  * check that we have some socket to listen on
1346  */
1347  if (NumListenSockets == 0)
1348  ereport(FATAL,
1349  (errmsg("no socket created for listening")));
1350 
1351  /*
1352  * If no valid TCP ports, write an empty line for listen address,
1353  * indicating the Unix socket must be used. Note that this line is not
1354  * added to the lock file until there is a socket backing it.
1355  */
1356  if (!listen_addr_saved)
1358 
1359  /*
1360  * Record postmaster options. We delay this till now to avoid recording
1361  * bogus options (eg, unusable port number).
1362  */
1363  if (!CreateOptsFile(argc, argv, my_exec_path))
1364  ExitPostmaster(1);
1365 
1366  /*
1367  * Write the external PID file if requested
1368  */
1369  if (external_pid_file)
1370  {
1371  FILE *fpidfile = fopen(external_pid_file, "w");
1372 
1373  if (fpidfile)
1374  {
1375  fprintf(fpidfile, "%d\n", MyProcPid);
1376  fclose(fpidfile);
1377 
1378  /* Make PID file world readable */
1379  if (chmod(external_pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0)
1380  write_stderr("%s: could not change permissions of external PID file \"%s\": %s\n",
1382  }
1383  else
1384  write_stderr("%s: could not write external PID file \"%s\": %s\n",
1386 
1388  }
1389 
1390  /*
1391  * Remove old temporary files. At this point there can be no other
1392  * Postgres processes running in this directory, so this should be safe.
1393  */
1395 
1396  /*
1397  * Initialize the autovacuum subsystem (again, no process start yet)
1398  */
1399  autovac_init();
1400 
1401  /*
1402  * Load configuration files for client authentication.
1403  */
1404  if (!load_hba())
1405  {
1406  /*
1407  * It makes no sense to continue if we fail to load the HBA file,
1408  * since there is no way to connect to the database in this case.
1409  */
1410  ereport(FATAL,
1411  /* translator: %s is a configuration file */
1412  (errmsg("could not load %s", HbaFileName)));
1413  }
1414  if (!load_ident())
1415  {
1416  /*
1417  * We can start up without the IDENT file, although it means that you
1418  * cannot log in using any of the authentication methods that need a
1419  * user name mapping. load_ident() already logged the details of error
1420  * to the log.
1421  */
1422  }
1423 
1424 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1425 
1426  /*
1427  * On macOS, libintl replaces setlocale() with a version that calls
1428  * CFLocaleCopyCurrent() when its second argument is "" and every relevant
1429  * environment variable is unset or empty. CFLocaleCopyCurrent() makes
1430  * the process multithreaded. The postmaster calls sigprocmask() and
1431  * calls fork() without an immediate exec(), both of which have undefined
1432  * behavior in a multithreaded program. A multithreaded postmaster is the
1433  * normal case on Windows, which offers neither fork() nor sigprocmask().
1434  */
1435  if (pthread_is_threaded_np() != 0)
1436  ereport(FATAL,
1437  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1438  errmsg("postmaster became multithreaded during startup"),
1439  errhint("Set the LC_ALL environment variable to a valid locale.")));
1440 #endif
1441 
1442  /*
1443  * Remember postmaster startup time
1444  */
1446 
1447  /*
1448  * Report postmaster status in the postmaster.pid file, to allow pg_ctl to
1449  * see what's happening.
1450  */
1452 
1453  /* Start bgwriter and checkpointer so they can help with recovery */
1454  if (CheckpointerPID == 0)
1456  if (BgWriterPID == 0)
1458 
1459  /*
1460  * We're ready to rock and roll...
1461  */
1463  Assert(StartupPID != 0);
1465  pmState = PM_STARTUP;
1466 
1467  /* Some workers may be scheduled to start now */
1469 
1470  status = ServerLoop();
1471 
1472  /*
1473  * ServerLoop probably shouldn't ever return, but if it does, close down.
1474  */
1475  ExitPostmaster(status != STATUS_OK);
1476 
1477  abort(); /* not reached */
1478 }
void autovac_init(void)
Definition: autovacuum.c:3347
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:4802
TimestampTz PgStartTime
Definition: timestamp.c:53
int secure_initialize(bool isServerStart)
Definition: be-secure.c:76
#define write_stderr(str)
Definition: parallel.c:184
#define STATUS_OK
Definition: c.h:1158
@ DestNone
Definition: dest.h:87
int Log_destination
Definition: elog.c:113
int errhint(const char *fmt,...)
Definition: elog.c:1322
char * Log_destination_string
Definition: elog.c:114
int errcode(int sqlerrcode)
Definition: elog.c:860
int errmsg(const char *fmt,...)
Definition: elog.c:1075
#define LOG
Definition: elog.h:31
#define DEBUG3
Definition: elog.h:28
#define WARNING
Definition: elog.h:36
#define ERROR
Definition: elog.h:39
#define LOG_DESTINATION_STDERR
Definition: elog.h:492
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:3333
void RemovePgTempFiles(void)
Definition: fd.c:3274
void set_max_safe_fds(void)
Definition: fd.c:1044
#define PG_MODE_MASK_OWNER
Definition: file_perm.h:24
#define PG_TEMP_FILES_DIR
Definition: file_utils.h:62
bool IsBinaryUpgrade
Definition: globals.c:117
pid_t PostmasterPid
Definition: globals.c:102
bool IsPostmasterEnvironment
Definition: globals.c:115
char my_exec_path[MAXPGPATH]
Definition: globals.c:77
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4256
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1779
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6287
void InitializeGUCOptions(void)
Definition: guc.c:1525
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition: guc.c:4279
int GetConfigOptionFlags(const char *name, bool missing_ok)
Definition: guc.c:4376
#define GUC_RUNTIME_COMPUTED
Definition: guc.h:225
@ PGC_S_OVERRIDE
Definition: guc.h:119
@ PGC_S_ARGV
Definition: guc.h:113
@ PGC_SUSET
Definition: guc.h:74
@ PGC_POSTMASTER
Definition: guc.h:70
char * HbaFileName
Definition: guc_tables.c:539
char * external_pid_file
Definition: guc_tables.c:541
bool load_ident(void)
Definition: hba.c:2964
bool load_hba(void)
Definition: hba.c:2588
static struct @148 value
static bool success
Definition: initdb.c:184
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:309
void InitializeShmemGUCs(void)
Definition: ipci.c:372
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:202
void InitializeLatchSupport(void)
Definition: latch.c:233
void ApplyLauncherRegister(void)
Definition: launcher.c:924
Assert(fmt[strlen(fmt) - 1] !='\n')
void list_free(List *list)
Definition: list.c:1546
void list_free_deep(List *list)
Definition: list.c:1560
const char * progname
Definition: main.c:45
char * pstrdup(const char *in)
Definition: mcxt.c:1619
MemoryContext TopMemoryContext
Definition: mcxt.c:141
MemoryContext PostmasterContext
Definition: mcxt.c:143
void * palloc(Size size)
Definition: mcxt.c:1201
#define AllocSetContextCreate
Definition: memutils.h:128
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:152
@ BgWriterProcess
Definition: miscadmin.h:443
@ StartupProcess
Definition: miscadmin.h:442
@ CheckpointerProcess
Definition: miscadmin.h:445
void ChangeToDataDir(void)
Definition: miscinit.c:455
void process_shmem_requests(void)
Definition: miscinit.c:1872
void AddToDataDirLockFile(int target_line, const char *str)
Definition: miscinit.c:1512
void InitProcessLocalLatch(void)
Definition: miscinit.c:242
void process_shared_preload_libraries(void)
Definition: miscinit.c:1844
void checkDataDir(void)
Definition: miscinit.c:342
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1456
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:124
#define pg_hton16(x)
Definition: pg_bswap.h:120
PGDLLIMPORT int optind
Definition: getopt.c:50
PGDLLIMPORT int opterr
Definition: getopt.c:49
int getopt(int nargc, char *const *nargv, const char *ostr)
Definition: getopt.c:71
PGDLLIMPORT char * optarg
Definition: getopt.c:52
#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
pqsigfunc pqsignal(int signo, pqsigfunc func)
int pgsocket
Definition: port.h:29
#define strerror
Definition: port.h:251
#define fprintf
Definition: port.h:242
void set_debug_options(int debug_flag, GucContext context, GucSource source)
Definition: postgres.c:3671
CommandDest whereToSendOutput
Definition: postgres.c:89
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition: postgres.c:3700
static const char * userDoption
Definition: postgres.c:160
const char * get_stats_option_name(const char *arg)
Definition: postgres.c:3742
pg_stack_base_t set_stack_base(void)
Definition: postgres.c:3473
void InitializeMaxBackends(void)
Definition: postinit.c:561
static void ExitPostmaster(int status) pg_attribute_noreturn()
Definition: postmaster.c:5030
static void handle_pm_shutdown_request_signal(SIGNAL_ARGS)
Definition: postmaster.c:2712
static void maybe_start_bgworkers(void)
Definition: postmaster.c:5927
static void CloseServerPorts(int status, Datum arg)
Definition: postmaster.c:1485
@ PM_STARTUP
Definition: postmaster.c:326
static void InitPostmasterDeathWatchHandle(void)
Definition: postmaster.c:6561
void InitProcessGlobals(void)
Definition: postmaster.c:2576
static void handle_pm_reload_request_signal(SIGNAL_ARGS)
Definition: postmaster.c:2629
static int ServerLoop(void)
Definition: postmaster.c:1719
int PostPortNumber
Definition: postmaster.c:199
static void checkControlFile(void)
Definition: postmaster.c:1582
bool enable_bonjour
Definition: postmaster.c:242
int ReservedConnections
Definition: postmaster.c:226
static void handle_pm_pmsignal_signal(SIGNAL_ARGS)
Definition: postmaster.c:2619
static pid_t CheckpointerPID
Definition: postmaster.c:252
static pid_t BgWriterPID
Definition: postmaster.c:251
static pid_t StartChildProcess(AuxProcType type)
Definition: postmaster.c:5316
char * Unix_socket_directories
Definition: postmaster.c:202
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname)
Definition: postmaster.c:5568
static void handle_pm_child_exit_signal(SIGNAL_ARGS)
Definition: postmaster.c:2887
static void getInstallationPaths(const char *argv0)
Definition: postmaster.c:1528
@ STARTUP_RUNNING
Definition: postmaster.c:265
static void unlink_external_pid_file(int status, Datum arg)
Definition: postmaster.c:1516
static StartupStatusEnum StartupStatus
Definition: postmaster.c:270
#define MAXLISTEN
Definition: postmaster.c:229
static void dummy_handler(SIGNAL_ARGS)
Definition: postmaster.c:5241
static pid_t StartupPID
Definition: postmaster.c:250
bool EnableSSL
Definition: postmaster.c:234
static PMState pmState
Definition: postmaster.c:340
char * ListenAddresses
Definition: postmaster.c:205
int SuperuserReservedConnections
Definition: postmaster.c:225
char * bonjour_name
Definition: postmaster.c:243
static pid_t SysLoggerPID
Definition: postmaster.c:258
int StreamServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSockets[], int *NumListenSockets, int MaxListen)
Definition: pqcomm.c:322
char ** environ
void pgwin32_signal_initialize(void)
Definition: signal.c:79
Definition: pg_list.h:54
void RemoveLogrotateSignalFiles(void)
Definition: syslogger.c:1636
int SysLogger_Start(void)
Definition: syslogger.c:567
#define LOG_METAINFO_DATAFILE
Definition: syslogger.h:100
bool SplitDirectoriesString(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3583
bool SplitGUCList(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3704
const char * name
bool summarize_wal
#define S_IROTH
Definition: win32_port.h:313
#define SIGCHLD
Definition: win32_port.h:178
#define SIGHUP
Definition: win32_port.h:168
#define S_IRGRP
Definition: win32_port.h:301
#define SIGPIPE
Definition: win32_port.h:173
#define SIGQUIT
Definition: win32_port.h:169
#define S_IRUSR
Definition: win32_port.h:289
#define SIGUSR1
Definition: win32_port.h:180
#define SIGALRM
Definition: win32_port.h:174
#define SIGUSR2
Definition: win32_port.h:181
#define SIG_IGN
Definition: win32_port.h:165
#define S_IWUSR
Definition: win32_port.h:292
int XLogArchiveMode
Definition: xlog.c:123
int wal_level
Definition: xlog.c:135
void InitializeWalConsistencyChecking(void)
Definition: xlog.c:4686
void LocalProcessControlFile(bool reset)
Definition: xlog.c:4748
@ ARCHIVE_MODE_OFF
Definition: xlog.h:63
@ WAL_LEVEL_MINIMAL
Definition: xlog.h:72
void RemovePromoteSignalFiles(void)

References AddToDataDirLockFile(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ApplyLauncherRegister(), ARCHIVE_MODE_OFF, Assert(), autovac_init(), BgWriterPID, BgWriterProcess, BlockSig, bonjour_name, ChangeToDataDir(), checkControlFile(), checkDataDir(), CheckDateTokenTables(), CheckpointerPID, CheckpointerProcess, CloseServerPorts(), CreateDataDirLockFile(), CreateOptsFile(), CreateSharedMemoryAndSemaphores(), DEBUG3, DestNone, dummy_handler(), enable_bonjour, EnableSSL, environ, ereport, err(), errcode(), errcode_for_file_access(), errhint(), errmsg(), errmsg_internal(), ERROR, ExitPostmaster(), external_pid_file, FATAL, fprintf, get_stats_option_name(), GetConfigOption(), GetConfigOptionFlags(), GetCurrentTimestamp(), getInstallationPaths(), getopt(), GUC_RUNTIME_COMPUTED, handle_pm_child_exit_signal(), handle_pm_pmsignal_signal(), handle_pm_reload_request_signal(), handle_pm_shutdown_request_signal(), HbaFileName, InitializeGUCOptions(), InitializeLatchSupport(), InitializeMaxBackends(), InitializeShmemGUCs(), InitializeWalConsistencyChecking(), InitPostmasterDeathWatchHandle(), InitProcessGlobals(), InitProcessLocalLatch(), IsBinaryUpgrade, IsPostmasterEnvironment, lfirst, list_free(), list_free_deep(), ListenAddresses, ListenSockets, load_hba(), load_ident(), 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, max_wal_senders, MaxConnections, MAXLISTEN, maybe_start_bgworkers(), MemoryContextSwitchTo(), my_exec_path, MyProcPid, name, NIL, NumListenSockets, on_proc_exit(), optarg, opterr, optind, palloc(), ParseLongOption(), pfree(), 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, pmState, PostmasterContext, PostmasterPid, PostPortNumber, pqinitmask(), pqsignal(), process_shared_preload_libraries(), process_shmem_requests(), progname, pstrdup(), 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(), set_stack_base(), SetConfigOption(), SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SIGPIPE, SIGQUIT, SIGUSR1, SIGUSR2, SplitDirectoriesString(), SplitGUCList(), StartChildProcess(), STARTUP_RUNNING, StartupPID, StartupProcess, StartupStatus, STATUS_OK, StreamServerPort(), strerror, success, summarize_wal, SuperuserReservedConnections, SysLogger_Start(), SysLoggerPID, TopMemoryContext, UnBlockSig, Unix_socket_directories, unlink_external_pid_file(), userDoption, value, wal_level, WAL_LEVEL_MINIMAL, WARNING, whereToSendOutput, write_stderr, and XLogArchiveMode.

Referenced by main().

◆ PostmasterMarkPIDForWorkerNotify()

bool PostmasterMarkPIDForWorkerNotify ( int  pid)

Definition at line 6046 of file postmaster.c.

6047 {
6048  dlist_iter iter;
6049  Backend *bp;
6050 
6051  dlist_foreach(iter, &BackendList)
6052  {
6053  bp = dlist_container(Backend, elem, iter.cur);
6054  if (bp->pid == pid)
6055  {
6056  bp->bgworker_notify = true;
6057  return true;
6058  }
6059  }
6060  return false;
6061 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:623
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
static dlist_head BackendList
Definition: postmaster.c:188
bool bgworker_notify
Definition: postmaster.c:184
pid_t pid
Definition: postmaster.c:179
dlist_node * cur
Definition: ilist.h:179

References BackendList, bkend::bgworker_notify, dlist_iter::cur, dlist_container, dlist_foreach, and bkend::pid.

Referenced by BackgroundWorkerStateChange().

Variable Documentation

◆ AuthenticationTimeout

PGDLLIMPORT int AuthenticationTimeout
extern

Definition at line 237 of file postmaster.c.

Referenced by BackendInitialize(), and PerformAuthentication().

◆ bonjour_name

PGDLLIMPORT char* bonjour_name
extern

Definition at line 243 of file postmaster.c.

Referenced by PostmasterMain().

◆ ClientAuthInProgress

◆ enable_bonjour

PGDLLIMPORT bool enable_bonjour
extern

Definition at line 242 of file postmaster.c.

Referenced by PostmasterMain().

◆ EnableSSL

PGDLLIMPORT bool EnableSSL
extern

Definition at line 234 of file postmaster.c.

Referenced by parse_hba_line(), PostmasterMain(), and process_pm_reload_request().

◆ ListenAddresses

PGDLLIMPORT char* ListenAddresses
extern

Definition at line 205 of file postmaster.c.

Referenced by PostmasterMain().

◆ Log_connections

PGDLLIMPORT bool Log_connections
extern

◆ log_hostname

PGDLLIMPORT bool log_hostname
extern

Definition at line 239 of file postmaster.c.

Referenced by BackendInitialize().

◆ postmaster_alive_fds

◆ PostPortNumber

PGDLLIMPORT int PostPortNumber
extern

Definition at line 199 of file postmaster.c.

Referenced by CreateLockFile(), and PostmasterMain().

◆ PreAuthDelay

PGDLLIMPORT int PreAuthDelay
extern

Definition at line 236 of file postmaster.c.

Referenced by BackendInitialize().

◆ progname

◆ remove_temp_files_after_crash

PGDLLIMPORT bool remove_temp_files_after_crash
extern

Definition at line 245 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ ReservedConnections

PGDLLIMPORT int ReservedConnections
extern

Definition at line 226 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ restart_after_crash

PGDLLIMPORT bool restart_after_crash
extern

Definition at line 244 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ send_abort_for_crash

PGDLLIMPORT bool send_abort_for_crash
extern

Definition at line 246 of file postmaster.c.

Referenced by sigquit_child().

◆ send_abort_for_kill

PGDLLIMPORT bool send_abort_for_kill
extern

Definition at line 247 of file postmaster.c.

Referenced by ServerLoop().

◆ SuperuserReservedConnections

PGDLLIMPORT int SuperuserReservedConnections
extern

Definition at line 225 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ Unix_socket_directories

PGDLLIMPORT char* Unix_socket_directories
extern

Definition at line 202 of file postmaster.c.

Referenced by PostmasterMain().

◆ Unix_socket_group

PGDLLIMPORT char* Unix_socket_group
extern

Definition at line 107 of file pqcomm.c.

Referenced by Setup_AF_UNIX().

◆ Unix_socket_permissions

PGDLLIMPORT int Unix_socket_permissions
extern

Definition at line 106 of file pqcomm.c.

Referenced by Setup_AF_UNIX(), and show_unix_socket_permissions().