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 ReservedBackends
 
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 int postmaster_alive_fds [2]
 
PGDLLIMPORT const char * progname
 

Macro Definition Documentation

◆ MAX_BACKENDS

#define MAX_BACKENDS   0x3FFFF

Definition at line 75 of file postmaster.h.

◆ POSTMASTER_FD_OWN

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

Definition at line 44 of file postmaster.h.

◆ POSTMASTER_FD_WATCH

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

Definition at line 43 of file postmaster.h.

Function Documentation

◆ ClosePostmasterPorts()

void ClosePostmasterPorts ( bool  am_syslogger)

Definition at line 2624 of file postmaster.c.

2625 {
2626  int i;
2627 
2628 #ifndef WIN32
2629 
2630  /*
2631  * Close the write end of postmaster death watch pipe. It's important to
2632  * do this as early as possible, so that if postmaster dies, others won't
2633  * think that it's still running because we're holding the pipe open.
2634  */
2636  ereport(FATAL,
2638  errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
2640  /* Notify fd.c that we released one pipe FD. */
2642 #endif
2643 
2644  /*
2645  * Close the postmaster's listen sockets. These aren't tracked by fd.c,
2646  * so we don't call ReleaseExternalFD() here.
2647  */
2648  for (i = 0; i < MAXLISTEN; i++)
2649  {
2651  {
2654  }
2655  }
2656 
2657  /*
2658  * If using syslogger, close the read side of the pipe. We don't bother
2659  * tracking this in fd.c, either.
2660  */
2661  if (!am_syslogger)
2662  {
2663 #ifndef WIN32
2664  if (syslogPipe[0] >= 0)
2665  close(syslogPipe[0]);
2666  syslogPipe[0] = -1;
2667 #else
2668  if (syslogPipe[0])
2669  CloseHandle(syslogPipe[0]);
2670  syslogPipe[0] = 0;
2671 #endif
2672  }
2673 
2674 #ifdef USE_BONJOUR
2675  /* If using Bonjour, close the connection to the mDNS daemon */
2676  if (bonjour_sdref)
2677  close(DNSServiceRefSockFD(bonjour_sdref));
2678 #endif
2679 }
int errmsg_internal(const char *fmt,...)
Definition: elog.c:991
int errcode_for_file_access(void)
Definition: elog.c:716
#define FATAL
Definition: elog.h:35
#define ereport(elevel,...)
Definition: elog.h:143
void ReleaseExternalFD(void)
Definition: fd.c:1230
#define close(a)
Definition: win32.h:12
int i
Definition: isn.c:73
#define PGINVALID_SOCKET
Definition: port.h:31
int postmaster_alive_fds[2]
Definition: postmaster.c:564
#define MAXLISTEN
Definition: postmaster.c:222
static pgsocket ListenSocket[MAXLISTEN]
Definition: postmaster.c:223
#define POSTMASTER_FD_OWN
Definition: postmaster.h:44
void StreamClose(pgsocket sock)
Definition: pqcomm.c:850
int syslogPipe[2]
Definition: syslogger.c:117

References close, ereport, errcode_for_file_access(), errmsg_internal(), FATAL, i, ListenSocket, MAXLISTEN, PGINVALID_SOCKET, postmaster_alive_fds, POSTMASTER_FD_OWN, ReleaseExternalFD(), StreamClose(), and syslogPipe.

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

◆ InitProcessGlobals()

void InitProcessGlobals ( void  )

Definition at line 2688 of file postmaster.c.

2689 {
2690  MyProcPid = getpid();
2693 
2694  /*
2695  * Set a different global seed in every process. We want something
2696  * unpredictable, so if possible, use high-quality random bits for the
2697  * seed. Otherwise, fall back to a seed based on timestamp and PID.
2698  */
2700  {
2701  uint64 rseed;
2702 
2703  /*
2704  * Since PIDs and timestamps tend to change more frequently in their
2705  * least significant bits, shift the timestamp left to allow a larger
2706  * total number of seeds in a given time period. Since that would
2707  * leave only 20 bits of the timestamp that cycle every ~1 second,
2708  * also mix in some higher bits.
2709  */
2710  rseed = ((uint64) MyProcPid) ^
2711  ((uint64) MyStartTimestamp << 12) ^
2712  ((uint64) MyStartTimestamp >> 20);
2713 
2715  }
2716 
2717  /*
2718  * Also make sure that we've set a good seed for random(3). Use of that
2719  * is deprecated in core Postgres, but extensions might use it.
2720  */
2721 #ifndef WIN32
2723 #endif
2724 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1574
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition: timestamp.c:1748
#define unlikely(x)
Definition: c.h:273
int MyProcPid
Definition: globals.c:44
TimestampTz MyStartTimestamp
Definition: globals.c:46
pg_time_t MyStartTime
Definition: globals.c:45
uint32 pg_prng_uint32(pg_prng_state *state)
Definition: pg_prng.c:185
void pg_prng_seed(pg_prng_state *state, uint64 seed)
Definition: pg_prng.c:83
pg_prng_state pg_global_prng_state
Definition: pg_prng.c:28
#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 5651 of file postmaster.c.

5652 {
5653  return 2 * (MaxConnections + autovacuum_max_workers + 1 +
5655 }
int autovacuum_max_workers
Definition: autovacuum.c:116
int MaxConnections
Definition: globals.c:137
int max_worker_processes
Definition: globals.c:138
int max_wal_senders
Definition: walsender.c:122

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

575 {
576  int opt;
577  int status;
578  char *userDoption = NULL;
579  bool listen_addr_saved = false;
580  int i;
581  char *output_config_variable = NULL;
582 
584 
586 
588 
589  /*
590  * Start our win32 signal implementation
591  */
592 #ifdef WIN32
594 #endif
595 
596  /*
597  * We should not be creating any files or directories before we check the
598  * data directory (see checkDataDir()), but just in case set the umask to
599  * the most restrictive (owner-only) permissions.
600  *
601  * checkDataDir() will reset the umask based on the data directory
602  * permissions.
603  */
604  umask(PG_MODE_MASK_OWNER);
605 
606  /*
607  * By default, palloc() requests in the postmaster will be allocated in
608  * the PostmasterContext, which is space that can be recycled by backends.
609  * Allocated data that needs to be available to backends should be
610  * allocated in TopMemoryContext.
611  */
613  "Postmaster",
616 
617  /* Initialize paths to installation files */
618  getInstallationPaths(argv[0]);
619 
620  /*
621  * Set up signal handlers for the postmaster process.
622  *
623  * In the postmaster, we use pqsignal_pm() rather than pqsignal() (which
624  * is used by all child processes and client processes). That has a
625  * couple of special behaviors:
626  *
627  * 1. Except on Windows, we tell sigaction() to block all signals for the
628  * duration of the signal handler. This is faster than our old approach
629  * of blocking/unblocking explicitly in the signal handler, and it should
630  * also prevent excessive stack consumption if signals arrive quickly.
631  *
632  * 2. We do not set the SA_RESTART flag. This is because signals will be
633  * blocked at all times except when ServerLoop is waiting for something to
634  * happen, and during that window, we want signals to exit the select(2)
635  * wait so that ServerLoop can respond if anything interesting happened.
636  * On some platforms, signals marked SA_RESTART would not cause the
637  * select() wait to end.
638  *
639  * Child processes will generally want SA_RESTART, so pqsignal() sets that
640  * flag. We expect children to set up their own handlers before
641  * unblocking signals.
642  *
643  * CAUTION: when changing this list, check for side-effects on the signal
644  * handling setup of child processes. See tcop/postgres.c,
645  * bootstrap/bootstrap.c, postmaster/bgwriter.c, postmaster/walwriter.c,
646  * postmaster/autovacuum.c, postmaster/pgarch.c, postmaster/syslogger.c,
647  * postmaster/bgworker.c and postmaster/checkpointer.c.
648  */
649  pqinitmask();
651 
652  pqsignal_pm(SIGHUP, SIGHUP_handler); /* reread config file and have
653  * children do same */
654  pqsignal_pm(SIGINT, pmdie); /* send SIGTERM and shut down */
655  pqsignal_pm(SIGQUIT, pmdie); /* send SIGQUIT and die */
656  pqsignal_pm(SIGTERM, pmdie); /* wait for children and shut down */
657  pqsignal_pm(SIGALRM, SIG_IGN); /* ignored */
658  pqsignal_pm(SIGPIPE, SIG_IGN); /* ignored */
659  pqsignal_pm(SIGUSR1, sigusr1_handler); /* message from child process */
660  pqsignal_pm(SIGUSR2, dummy_handler); /* unused, reserve for children */
661  pqsignal_pm(SIGCHLD, reaper); /* handle child termination */
662 
663 #ifdef SIGURG
664 
665  /*
666  * Ignore SIGURG for now. Child processes may change this (see
667  * InitializeLatchSupport), but they will not receive any such signals
668  * until they wait on a latch.
669  */
670  pqsignal_pm(SIGURG, SIG_IGN); /* ignored */
671 #endif
672 
673  /*
674  * No other place in Postgres should touch SIGTTIN/SIGTTOU handling. We
675  * ignore those signals in a postmaster environment, so that there is no
676  * risk of a child process freezing up due to writing to stderr. But for
677  * a standalone backend, their default handling is reasonable. Hence, all
678  * child processes should just allow the inherited settings to stand.
679  */
680 #ifdef SIGTTIN
681  pqsignal_pm(SIGTTIN, SIG_IGN); /* ignored */
682 #endif
683 #ifdef SIGTTOU
684  pqsignal_pm(SIGTTOU, SIG_IGN); /* ignored */
685 #endif
686 
687  /* ignore SIGXFSZ, so that ulimit violations work like disk full */
688 #ifdef SIGXFSZ
689  pqsignal_pm(SIGXFSZ, SIG_IGN); /* ignored */
690 #endif
691 
692  /*
693  * Options setup
694  */
696 
697  opterr = 1;
698 
699  /*
700  * Parse command-line options. CAUTION: keep this in sync with
701  * tcop/postgres.c (the option sets should not conflict) and with the
702  * common help() function in main/main.c.
703  */
704  while ((opt = getopt(argc, argv, "B:bc:C:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:W:-:")) != -1)
705  {
706  switch (opt)
707  {
708  case 'B':
709  SetConfigOption("shared_buffers", optarg, PGC_POSTMASTER, PGC_S_ARGV);
710  break;
711 
712  case 'b':
713  /* Undocumented flag used for binary upgrades */
714  IsBinaryUpgrade = true;
715  break;
716 
717  case 'C':
718  output_config_variable = strdup(optarg);
719  break;
720 
721  case 'D':
722  userDoption = strdup(optarg);
723  break;
724 
725  case 'd':
727  break;
728 
729  case 'E':
730  SetConfigOption("log_statement", "all", PGC_POSTMASTER, PGC_S_ARGV);
731  break;
732 
733  case 'e':
734  SetConfigOption("datestyle", "euro", PGC_POSTMASTER, PGC_S_ARGV);
735  break;
736 
737  case 'F':
738  SetConfigOption("fsync", "false", PGC_POSTMASTER, PGC_S_ARGV);
739  break;
740 
741  case 'f':
743  {
744  write_stderr("%s: invalid argument for option -f: \"%s\"\n",
745  progname, optarg);
746  ExitPostmaster(1);
747  }
748  break;
749 
750  case 'h':
751  SetConfigOption("listen_addresses", optarg, PGC_POSTMASTER, PGC_S_ARGV);
752  break;
753 
754  case 'i':
755  SetConfigOption("listen_addresses", "*", PGC_POSTMASTER, PGC_S_ARGV);
756  break;
757 
758  case 'j':
759  /* only used by interactive backend */
760  break;
761 
762  case 'k':
763  SetConfigOption("unix_socket_directories", optarg, PGC_POSTMASTER, PGC_S_ARGV);
764  break;
765 
766  case 'l':
767  SetConfigOption("ssl", "true", PGC_POSTMASTER, PGC_S_ARGV);
768  break;
769 
770  case 'N':
771  SetConfigOption("max_connections", optarg, PGC_POSTMASTER, PGC_S_ARGV);
772  break;
773 
774  case 'n':
775  /* Don't reinit shared mem after abnormal exit */
776  Reinit = false;
777  break;
778 
779  case 'O':
780  SetConfigOption("allow_system_table_mods", "true", PGC_POSTMASTER, PGC_S_ARGV);
781  break;
782 
783  case 'P':
784  SetConfigOption("ignore_system_indexes", "true", PGC_POSTMASTER, PGC_S_ARGV);
785  break;
786 
787  case 'p':
789  break;
790 
791  case 'r':
792  /* only used by single-user backend */
793  break;
794 
795  case 'S':
797  break;
798 
799  case 's':
800  SetConfigOption("log_statement_stats", "true", PGC_POSTMASTER, PGC_S_ARGV);
801  break;
802 
803  case 'T':
804 
805  /*
806  * In the event that some backend dumps core, send SIGSTOP,
807  * rather than SIGQUIT, to all its peers. This lets the wily
808  * post_hacker collect core dumps from everyone.
809  */
810  SendStop = true;
811  break;
812 
813  case 't':
814  {
815  const char *tmp = get_stats_option_name(optarg);
816 
817  if (tmp)
818  {
820  }
821  else
822  {
823  write_stderr("%s: invalid argument for option -t: \"%s\"\n",
824  progname, optarg);
825  ExitPostmaster(1);
826  }
827  break;
828  }
829 
830  case 'W':
831  SetConfigOption("post_auth_delay", optarg, PGC_POSTMASTER, PGC_S_ARGV);
832  break;
833 
834  case 'c':
835  case '-':
836  {
837  char *name,
838  *value;
839 
841  if (!value)
842  {
843  if (opt == '-')
844  ereport(ERROR,
845  (errcode(ERRCODE_SYNTAX_ERROR),
846  errmsg("--%s requires a value",
847  optarg)));
848  else
849  ereport(ERROR,
850  (errcode(ERRCODE_SYNTAX_ERROR),
851  errmsg("-c %s requires a value",
852  optarg)));
853  }
854 
856  free(name);
857  if (value)
858  free(value);
859  break;
860  }
861 
862  default:
863  write_stderr("Try \"%s --help\" for more information.\n",
864  progname);
865  ExitPostmaster(1);
866  }
867  }
868 
869  /*
870  * Postmaster accepts no non-option switch arguments.
871  */
872  if (optind < argc)
873  {
874  write_stderr("%s: invalid argument: \"%s\"\n",
875  progname, argv[optind]);
876  write_stderr("Try \"%s --help\" for more information.\n",
877  progname);
878  ExitPostmaster(1);
879  }
880 
881  /*
882  * Locate the proper configuration files and data directory, and read
883  * postgresql.conf for the first time.
884  */
886  ExitPostmaster(2);
887 
888  if (output_config_variable != NULL)
889  {
890  /*
891  * If this is a runtime-computed GUC, it hasn't yet been initialized,
892  * and the present value is not useful. However, this is a convenient
893  * place to print the value for most GUCs because it is safe to run
894  * postmaster startup to this point even if the server is already
895  * running. For the handful of runtime-computed GUCs that we cannot
896  * provide meaningful values for yet, we wait until later in
897  * postmaster startup to print the value. We won't be able to use -C
898  * on running servers for those GUCs, but using this option now would
899  * lead to incorrect results for them.
900  */
901  int flags = GetConfigOptionFlags(output_config_variable, true);
902 
903  if ((flags & GUC_RUNTIME_COMPUTED) == 0)
904  {
905  /*
906  * "-C guc" was specified, so print GUC's value and exit. No
907  * extra permission check is needed because the user is reading
908  * inside the data dir.
909  */
910  const char *config_val = GetConfigOption(output_config_variable,
911  false, false);
912 
913  puts(config_val ? config_val : "");
914  ExitPostmaster(0);
915  }
916 
917  /*
918  * A runtime-computed GUC will be printed later on. As we initialize
919  * a server startup sequence, silence any log messages that may show
920  * up in the output generated. FATAL and more severe messages are
921  * useful to show, even if one would only expect at least PANIC. LOG
922  * entries are hidden.
923  */
924  SetConfigOption("log_min_messages", "FATAL", PGC_SUSET,
926  }
927 
928  /* Verify that DataDir looks reasonable */
929  checkDataDir();
930 
931  /* Check that pg_control exists */
933 
934  /* And switch working directory into it */
935  ChangeToDataDir();
936 
937  /*
938  * Check for invalid combinations of GUC settings.
939  */
941  {
942  write_stderr("%s: superuser_reserved_connections (%d) must be less than max_connections (%d)\n",
943  progname,
945  ExitPostmaster(1);
946  }
948  ereport(ERROR,
949  (errmsg("WAL archival cannot be enabled when wal_level is \"minimal\"")));
951  ereport(ERROR,
952  (errmsg("WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
953 
954  /*
955  * Other one-time internal sanity checks can go here, if they are fast.
956  * (Put any slow processing further down, after postmaster.pid creation.)
957  */
958  if (!CheckDateTokenTables())
959  {
960  write_stderr("%s: invalid datetoken tables, please fix\n", progname);
961  ExitPostmaster(1);
962  }
963 
964  /*
965  * Now that we are done processing the postmaster arguments, reset
966  * getopt(3) library so that it will work correctly in subprocesses.
967  */
968  optind = 1;
969 #ifdef HAVE_INT_OPTRESET
970  optreset = 1; /* some systems need this too */
971 #endif
972 
973  /* For debugging: display postmaster environment */
974  {
975  extern char **environ;
976  char **p;
977 
978  ereport(DEBUG3,
979  (errmsg_internal("%s: PostmasterMain: initial environment dump:",
980  progname)));
981  ereport(DEBUG3,
982  (errmsg_internal("-----------------------------------------")));
983  for (p = environ; *p; ++p)
984  ereport(DEBUG3,
985  (errmsg_internal("\t%s", *p)));
986  ereport(DEBUG3,
987  (errmsg_internal("-----------------------------------------")));
988  }
989 
990  /*
991  * Create lockfile for data directory.
992  *
993  * We want to do this before we try to grab the input sockets, because the
994  * data directory interlock is more reliable than the socket-file
995  * interlock (thanks to whoever decided to put socket files in /tmp :-().
996  * For the same reason, it's best to grab the TCP socket(s) before the
997  * Unix socket(s).
998  *
999  * Also note that this internally sets up the on_proc_exit function that
1000  * is responsible for removing both data directory and socket lockfiles;
1001  * so it must happen before opening sockets so that at exit, the socket
1002  * lockfiles go away after CloseServerPorts runs.
1003  */
1004  CreateDataDirLockFile(true);
1005 
1006  /*
1007  * Read the control file (for error checking and config info).
1008  *
1009  * Since we verify the control file's CRC, this has a useful side effect
1010  * on machines where we need a run-time test for CRC support instructions.
1011  * The postmaster will do the test once at startup, and then its child
1012  * processes will inherit the correct function pointer and not need to
1013  * repeat the test.
1014  */
1015  LocalProcessControlFile(false);
1016 
1017  /*
1018  * Register the apply launcher. It's probably a good idea to call this
1019  * before any modules had a chance to take the background worker slots.
1020  */
1022 
1023  /*
1024  * process any libraries that should be preloaded at postmaster start
1025  */
1027 
1028  /*
1029  * Initialize SSL library, if specified.
1030  */
1031 #ifdef USE_SSL
1032  if (EnableSSL)
1033  {
1034  (void) secure_initialize(true);
1035  LoadedSSL = true;
1036  }
1037 #endif
1038 
1039  /*
1040  * Now that loadable modules have had their chance to alter any GUCs,
1041  * calculate MaxBackends.
1042  */
1044 
1045  /*
1046  * Give preloaded libraries a chance to request additional shared memory.
1047  */
1049 
1050  /*
1051  * Now that loadable modules have had their chance to request additional
1052  * shared memory, determine the value of any runtime-computed GUCs that
1053  * depend on the amount of shared memory required.
1054  */
1056 
1057  /*
1058  * Now that modules have been loaded, we can process any custom resource
1059  * managers specified in the wal_consistency_checking GUC.
1060  */
1062 
1063  /*
1064  * If -C was specified with a runtime-computed GUC, we held off printing
1065  * the value earlier, as the GUC was not yet initialized. We handle -C
1066  * for most GUCs before we lock the data directory so that the option may
1067  * be used on a running server. However, a handful of GUCs are runtime-
1068  * computed and do not have meaningful values until after locking the data
1069  * directory, and we cannot safely calculate their values earlier on a
1070  * running server. At this point, such GUCs should be properly
1071  * initialized, and we haven't yet set up shared memory, so this is a good
1072  * time to handle the -C option for these special GUCs.
1073  */
1074  if (output_config_variable != NULL)
1075  {
1076  const char *config_val = GetConfigOption(output_config_variable,
1077  false, false);
1078 
1079  puts(config_val ? config_val : "");
1080  ExitPostmaster(0);
1081  }
1082 
1083  /*
1084  * Set up shared memory and semaphores.
1085  */
1086  reset_shared();
1087 
1088  /*
1089  * Estimate number of openable files. This must happen after setting up
1090  * semaphores, because on some platforms semaphores count as open files.
1091  */
1092  set_max_safe_fds();
1093 
1094  /*
1095  * Set reference point for stack-depth checking.
1096  */
1097  (void) set_stack_base();
1098 
1099  /*
1100  * Initialize pipe (or process handle on Windows) that allows children to
1101  * wake up from sleep on postmaster death.
1102  */
1104 
1105 #ifdef WIN32
1106 
1107  /*
1108  * Initialize I/O completion port used to deliver list of dead children.
1109  */
1110  win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
1111  if (win32ChildQueue == NULL)
1112  ereport(FATAL,
1113  (errmsg("could not create I/O completion port for child queue")));
1114 #endif
1115 
1116 #ifdef EXEC_BACKEND
1117  /* Write out nondefault GUC settings for child processes to use */
1118  write_nondefault_variables(PGC_POSTMASTER);
1119 
1120  /*
1121  * Clean out the temp directory used to transmit parameters to child
1122  * processes (see internal_forkexec, below). We must do this before
1123  * launching any child processes, else we have a race condition: we could
1124  * remove a parameter file before the child can read it. It should be
1125  * safe to do so now, because we verified earlier that there are no
1126  * conflicting Postgres processes in this data directory.
1127  */
1129 #endif
1130 
1131  /*
1132  * Forcibly remove the files signaling a standby promotion request.
1133  * Otherwise, the existence of those files triggers a promotion too early,
1134  * whether a user wants that or not.
1135  *
1136  * This removal of files is usually unnecessary because they can exist
1137  * only during a few moments during a standby promotion. However there is
1138  * a race condition: if pg_ctl promote is executed and creates the files
1139  * during a promotion, the files can stay around even after the server is
1140  * brought up to be the primary. Then, if a new standby starts by using
1141  * the backup taken from the new primary, the files can exist at server
1142  * startup and must be removed in order to avoid an unexpected promotion.
1143  *
1144  * Note that promotion signal files need to be removed before the startup
1145  * process is invoked. Because, after that, they can be used by
1146  * postmaster's SIGUSR1 signal handler.
1147  */
1149 
1150  /* Do the same for logrotate signal file */
1152 
1153  /* Remove any outdated file holding the current log filenames. */
1154  if (unlink(LOG_METAINFO_DATAFILE) < 0 && errno != ENOENT)
1155  ereport(LOG,
1157  errmsg("could not remove file \"%s\": %m",
1159 
1160  /*
1161  * If enabled, start up syslogger collection subprocess
1162  */
1164 
1165  /*
1166  * Reset whereToSendOutput from DestDebug (its starting state) to
1167  * DestNone. This stops ereport from sending log messages to stderr unless
1168  * Log_destination permits. We don't do this until the postmaster is
1169  * fully launched, since startup failures may as well be reported to
1170  * stderr.
1171  *
1172  * If we are in fact disabling logging to stderr, first emit a log message
1173  * saying so, to provide a breadcrumb trail for users who may not remember
1174  * that their logging is configured to go somewhere else.
1175  */
1177  ereport(LOG,
1178  (errmsg("ending log output to stderr"),
1179  errhint("Future log output will go to log destination \"%s\".",
1181 
1183 
1184  /*
1185  * Report server startup in log. While we could emit this much earlier,
1186  * it seems best to do so after starting the log collector, if we intend
1187  * to use one.
1188  */
1189  ereport(LOG,
1190  (errmsg("starting %s", PG_VERSION_STR)));
1191 
1192  /*
1193  * Establish input sockets.
1194  *
1195  * First, mark them all closed, and set up an on_proc_exit function that's
1196  * charged with closing the sockets again at postmaster shutdown.
1197  */
1198  for (i = 0; i < MAXLISTEN; i++)
1200 
1202 
1203  if (ListenAddresses)
1204  {
1205  char *rawstring;
1206  List *elemlist;
1207  ListCell *l;
1208  int success = 0;
1209 
1210  /* Need a modifiable copy of ListenAddresses */
1211  rawstring = pstrdup(ListenAddresses);
1212 
1213  /* Parse string into list of hostnames */
1214  if (!SplitGUCList(rawstring, ',', &elemlist))
1215  {
1216  /* syntax error in list */
1217  ereport(FATAL,
1218  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1219  errmsg("invalid list syntax in parameter \"%s\"",
1220  "listen_addresses")));
1221  }
1222 
1223  foreach(l, elemlist)
1224  {
1225  char *curhost = (char *) lfirst(l);
1226 
1227  if (strcmp(curhost, "*") == 0)
1228  status = StreamServerPort(AF_UNSPEC, NULL,
1229  (unsigned short) PostPortNumber,
1230  NULL,
1232  else
1233  status = StreamServerPort(AF_UNSPEC, curhost,
1234  (unsigned short) PostPortNumber,
1235  NULL,
1237 
1238  if (status == STATUS_OK)
1239  {
1240  success++;
1241  /* record the first successful host addr in lockfile */
1242  if (!listen_addr_saved)
1243  {
1245  listen_addr_saved = true;
1246  }
1247  }
1248  else
1249  ereport(WARNING,
1250  (errmsg("could not create listen socket for \"%s\"",
1251  curhost)));
1252  }
1253 
1254  if (!success && elemlist != NIL)
1255  ereport(FATAL,
1256  (errmsg("could not create any TCP/IP sockets")));
1257 
1258  list_free(elemlist);
1259  pfree(rawstring);
1260  }
1261 
1262 #ifdef USE_BONJOUR
1263  /* Register for Bonjour only if we opened TCP socket(s) */
1265  {
1266  DNSServiceErrorType err;
1267 
1268  /*
1269  * We pass 0 for interface_index, which will result in registering on
1270  * all "applicable" interfaces. It's not entirely clear from the
1271  * DNS-SD docs whether this would be appropriate if we have bound to
1272  * just a subset of the available network interfaces.
1273  */
1274  err = DNSServiceRegister(&bonjour_sdref,
1275  0,
1276  0,
1277  bonjour_name,
1278  "_postgresql._tcp.",
1279  NULL,
1280  NULL,
1282  0,
1283  NULL,
1284  NULL,
1285  NULL);
1286  if (err != kDNSServiceErr_NoError)
1287  ereport(LOG,
1288  (errmsg("DNSServiceRegister() failed: error code %ld",
1289  (long) err)));
1290 
1291  /*
1292  * We don't bother to read the mDNS daemon's reply, and we expect that
1293  * it will automatically terminate our registration when the socket is
1294  * closed at postmaster termination. So there's nothing more to be
1295  * done here. However, the bonjour_sdref is kept around so that
1296  * forked children can close their copies of the socket.
1297  */
1298  }
1299 #endif
1300 
1301 #ifdef HAVE_UNIX_SOCKETS
1303  {
1304  char *rawstring;
1305  List *elemlist;
1306  ListCell *l;
1307  int success = 0;
1308 
1309  /* Need a modifiable copy of Unix_socket_directories */
1310  rawstring = pstrdup(Unix_socket_directories);
1311 
1312  /* Parse string into list of directories */
1313  if (!SplitDirectoriesString(rawstring, ',', &elemlist))
1314  {
1315  /* syntax error in list */
1316  ereport(FATAL,
1317  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1318  errmsg("invalid list syntax in parameter \"%s\"",
1319  "unix_socket_directories")));
1320  }
1321 
1322  foreach(l, elemlist)
1323  {
1324  char *socketdir = (char *) lfirst(l);
1325 
1326  status = StreamServerPort(AF_UNIX, NULL,
1327  (unsigned short) PostPortNumber,
1328  socketdir,
1330 
1331  if (status == STATUS_OK)
1332  {
1333  success++;
1334  /* record the first successful Unix socket in lockfile */
1335  if (success == 1)
1337  }
1338  else
1339  ereport(WARNING,
1340  (errmsg("could not create Unix-domain socket in directory \"%s\"",
1341  socketdir)));
1342  }
1343 
1344  if (!success && elemlist != NIL)
1345  ereport(FATAL,
1346  (errmsg("could not create any Unix-domain sockets")));
1347 
1348  list_free_deep(elemlist);
1349  pfree(rawstring);
1350  }
1351 #endif
1352 
1353  /*
1354  * check that we have some socket to listen on
1355  */
1356  if (ListenSocket[0] == PGINVALID_SOCKET)
1357  ereport(FATAL,
1358  (errmsg("no socket created for listening")));
1359 
1360  /*
1361  * If no valid TCP ports, write an empty line for listen address,
1362  * indicating the Unix socket must be used. Note that this line is not
1363  * added to the lock file until there is a socket backing it.
1364  */
1365  if (!listen_addr_saved)
1367 
1368  /*
1369  * Record postmaster options. We delay this till now to avoid recording
1370  * bogus options (eg, unusable port number).
1371  */
1372  if (!CreateOptsFile(argc, argv, my_exec_path))
1373  ExitPostmaster(1);
1374 
1375  /*
1376  * Write the external PID file if requested
1377  */
1378  if (external_pid_file)
1379  {
1380  FILE *fpidfile = fopen(external_pid_file, "w");
1381 
1382  if (fpidfile)
1383  {
1384  fprintf(fpidfile, "%d\n", MyProcPid);
1385  fclose(fpidfile);
1386 
1387  /* Make PID file world readable */
1388  if (chmod(external_pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0)
1389  write_stderr("%s: could not change permissions of external PID file \"%s\": %s\n",
1391  }
1392  else
1393  write_stderr("%s: could not write external PID file \"%s\": %s\n",
1395 
1397  }
1398 
1399  /*
1400  * Remove old temporary files. At this point there can be no other
1401  * Postgres processes running in this directory, so this should be safe.
1402  */
1404 
1405  /*
1406  * Initialize the autovacuum subsystem (again, no process start yet)
1407  */
1408  autovac_init();
1409 
1410  /*
1411  * Load configuration files for client authentication.
1412  */
1413  if (!load_hba())
1414  {
1415  /*
1416  * It makes no sense to continue if we fail to load the HBA file,
1417  * since there is no way to connect to the database in this case.
1418  */
1419  ereport(FATAL,
1420  (errmsg("could not load pg_hba.conf")));
1421  }
1422  if (!load_ident())
1423  {
1424  /*
1425  * We can start up without the IDENT file, although it means that you
1426  * cannot log in using any of the authentication methods that need a
1427  * user name mapping. load_ident() already logged the details of error
1428  * to the log.
1429  */
1430  }
1431 
1432 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1433 
1434  /*
1435  * On macOS, libintl replaces setlocale() with a version that calls
1436  * CFLocaleCopyCurrent() when its second argument is "" and every relevant
1437  * environment variable is unset or empty. CFLocaleCopyCurrent() makes
1438  * the process multithreaded. The postmaster calls sigprocmask() and
1439  * calls fork() without an immediate exec(), both of which have undefined
1440  * behavior in a multithreaded program. A multithreaded postmaster is the
1441  * normal case on Windows, which offers neither fork() nor sigprocmask().
1442  */
1443  if (pthread_is_threaded_np() != 0)
1444  ereport(FATAL,
1445  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1446  errmsg("postmaster became multithreaded during startup"),
1447  errhint("Set the LC_ALL environment variable to a valid locale.")));
1448 #endif
1449 
1450  /*
1451  * Remember postmaster startup time
1452  */
1454 
1455  /*
1456  * Report postmaster status in the postmaster.pid file, to allow pg_ctl to
1457  * see what's happening.
1458  */
1460 
1461  /* Start bgwriter and checkpointer so they can help with recovery */
1462  if (CheckpointerPID == 0)
1464  if (BgWriterPID == 0)
1466 
1467  /*
1468  * We're ready to rock and roll...
1469  */
1471  Assert(StartupPID != 0);
1473  pmState = PM_STARTUP;
1474 
1475  /* Some workers may be scheduled to start now */
1477 
1478  status = ServerLoop();
1479 
1480  /*
1481  * ServerLoop probably shouldn't ever return, but if it does, close down.
1482  */
1484 
1485  abort(); /* not reached */
1486 }
void autovac_init(void)
Definition: autovacuum.c:3289
void pqinitmask(void)
Definition: pqsignal.c:41
pqsigfunc pqsignal_pm(int signo, pqsigfunc func)
Definition: pqsignal.c:120
sigset_t BlockSig
Definition: pqsignal.c:23
bool CheckDateTokenTables(void)
Definition: datetime.c:4727
TimestampTz PgStartTime
Definition: timestamp.c:53
int secure_initialize(bool isServerStart)
Definition: be-secure.c:78
#define write_stderr(str)
Definition: parallel.c:186
#define STATUS_OK
Definition: c.h:1167
@ DestNone
Definition: dest.h:89
int Log_destination
Definition: elog.c:111
int errhint(const char *fmt,...)
Definition: elog.c:1151
char * Log_destination_string
Definition: elog.c:112
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define LOG
Definition: elog.h:25
#define DEBUG3
Definition: elog.h:22
#define WARNING
Definition: elog.h:30
#define ERROR
Definition: elog.h:33
#define LOG_DESTINATION_STDERR
Definition: elog.h:421
const char * name
Definition: encode.c:561
void RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok, bool unlink_all)
Definition: fd.c:3212
void RemovePgTempFiles(void)
Definition: fd.c:3153
void set_max_safe_fds(void)
Definition: fd.c:1028
#define PG_MODE_MASK_OWNER
Definition: file_perm.h:24
bool IsBinaryUpgrade
Definition: globals.c:114
pid_t PostmasterPid
Definition: globals.c:99
bool IsPostmasterEnvironment
Definition: globals.c:112
char my_exec_path[MAXPGPATH]
Definition: globals.c:76
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:8376
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:6097
void InitializeWalConsistencyChecking(void)
Definition: guc.c:5889
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:11341
void InitializeGUCOptions(void)
Definition: guc.c:5836
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition: guc.c:8400
int GetConfigOptionFlags(const char *name, bool missing_ok)
Definition: guc.c:8495
char * external_pid_file
Definition: guc.c:657
#define GUC_RUNTIME_COMPUTED
Definition: guc.h:239
@ PGC_S_OVERRIDE
Definition: guc.h:120
@ PGC_S_ARGV
Definition: guc.h:114
@ PGC_SUSET
Definition: guc.h:75
@ PGC_POSTMASTER
Definition: guc.h:71
bool load_ident(void)
Definition: hba.c:2586
bool load_hba(void)
Definition: hba.c:2207
#define free(a)
Definition: header.h:65
static struct @151 value
static bool success
Definition: initdb.c:169
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:305
void InitializeShmemGUCs(void)
Definition: ipci.c:324
void ApplyLauncherRegister(void)
Definition: launcher.c:706
Assert(fmt[strlen(fmt) - 1] !='\n')
void list_free(List *list)
Definition: list.c:1505
void list_free_deep(List *list)
Definition: list.c:1519
const char * progname
Definition: main.c:50
char * pstrdup(const char *in)
Definition: mcxt.c:1305
void pfree(void *pointer)
Definition: mcxt.c:1175
MemoryContext TopMemoryContext
Definition: mcxt.c:48
MemoryContext PostmasterContext
Definition: mcxt.c:50
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
void ChangeToDataDir(void)
Definition: miscinit.c:432
void process_shmem_requests(void)
Definition: miscinit.c:1711
void AddToDataDirLockFile(int target_line, const char *str)
Definition: miscinit.c:1351
void process_shared_preload_libraries(void)
Definition: miscinit.c:1683
void checkDataDir(void)
Definition: miscinit.c:318
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1295
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define pg_hton16(x)
Definition: pg_bswap.h:120
#define PG_TEMP_FILES_DIR
Definition: pg_checksums.c:62
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:169
#define NIL
Definition: pg_list.h:65
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:229
#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
#define strerror
Definition: port.h:238
#define fprintf
Definition: port.h:229
void set_debug_options(int debug_flag, GucContext context, GucSource source)
Definition: postgres.c:3595
CommandDest whereToSendOutput
Definition: postgres.c:92
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition: postgres.c:3624
static const char * userDoption
Definition: postgres.c:170
const char * get_stats_option_name(const char *arg)
Definition: postgres.c:3666
pg_stack_base_t set_stack_base(void)
Definition: postgres.c:3437
void InitializeMaxBackends(void)
Definition: postinit.c:551
static void ExitPostmaster(int status) pg_attribute_noreturn()
Definition: postmaster.c:5094
static void maybe_start_bgworkers(void)
Definition: postmaster.c:5947
static void CloseServerPorts(int status, Datum arg)
Definition: postmaster.c:1493
@ PM_STARTUP
Definition: postmaster.c:325
static void InitPostmasterDeathWatchHandle(void)
Definition: postmaster.c:6542
static void pmdie(SIGNAL_ARGS)
Definition: postmaster.c:2828
void InitProcessGlobals(void)
Definition: postmaster.c:2688
static void reset_shared(void)
Definition: postmaster.c:2731
static int ServerLoop(void)
Definition: postmaster.c:1722
int PostPortNumber
Definition: postmaster.c:202
static void checkControlFile(void)
Definition: postmaster.c:1595
#define StartupDataBase()
Definition: postmaster.c:547
bool enable_bonjour
Definition: postmaster.c:245
static int SendStop
Definition: postmaster.c:233
static pid_t CheckpointerPID
Definition: postmaster.c:253
static pid_t BgWriterPID
Definition: postmaster.c:252
char * Unix_socket_directories
Definition: postmaster.c:205
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname)
Definition: postmaster.c:5607
static void sigusr1_handler(SIGNAL_ARGS)
Definition: postmaster.c:5127
static void getInstallationPaths(const char *argv0)
Definition: postmaster.c:1541
static bool Reinit
Definition: postmaster.c:232
#define StartCheckpointer()
Definition: postmaster.c:550
@ STARTUP_RUNNING
Definition: postmaster.c:264
static void unlink_external_pid_file(int status, Datum arg)
Definition: postmaster.c:1529
#define StartBackgroundWriter()
Definition: postmaster.c:549
static StartupStatusEnum StartupStatus
Definition: postmaster.c:269
static void reaper(SIGNAL_ARGS)
Definition: postmaster.c:2975
static void dummy_handler(SIGNAL_ARGS)
Definition: postmaster.c:5315
static pid_t StartupPID
Definition: postmaster.c:251
bool EnableSSL
Definition: postmaster.c:236
static PMState pmState
Definition: postmaster.c:339
char * ListenAddresses
Definition: postmaster.c:208
char * bonjour_name
Definition: postmaster.c:246
static void SIGHUP_handler(SIGNAL_ARGS)
Definition: postmaster.c:2748
int ReservedBackends
Definition: postmaster.c:219
static pid_t SysLoggerPID
Definition: postmaster.c:258
int StreamServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSocket[], int MaxListen)
Definition: pqcomm.c:318
#define PG_SETMASK(mask)
Definition: pqsignal.h:19
char ** environ
void pgwin32_signal_initialize(void)
Definition: signal.c:79
Definition: pg_list.h:51
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:3842
bool SplitGUCList(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3963
#define S_IROTH
Definition: win32_port.h:312
#define SIGCHLD
Definition: win32_port.h:177
#define SIGHUP
Definition: win32_port.h:167
#define S_IRGRP
Definition: win32_port.h:300
#define SIGPIPE
Definition: win32_port.h:172
#define SIGQUIT
Definition: win32_port.h:168
#define S_IRUSR
Definition: win32_port.h:288
#define SIGUSR1
Definition: win32_port.h:179
#define SIGALRM
Definition: win32_port.h:173
#define SIGUSR2
Definition: win32_port.h:180
#define SIG_IGN
Definition: win32_port.h:164
#define S_IWUSR
Definition: win32_port.h:291
int XLogArchiveMode
Definition: xlog.c:120
int wal_level
Definition: xlog.c:132
void LocalProcessControlFile(bool reset)
Definition: xlog.c:4326
@ ARCHIVE_MODE_OFF
Definition: xlog.h:60
@ WAL_LEVEL_MINIMAL
Definition: xlog.h:69
void RemovePromoteSignalFiles(void)

References AddToDataDirLockFile(), ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, ApplyLauncherRegister(), ARCHIVE_MODE_OFF, Assert(), autovac_init(), BgWriterPID, BlockSig, bonjour_name, ChangeToDataDir(), checkControlFile(), checkDataDir(), CheckDateTokenTables(), CheckpointerPID, CloseServerPorts(), CreateDataDirLockFile(), CreateOptsFile(), DEBUG3, DestNone, dummy_handler(), enable_bonjour, EnableSSL, environ, ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), errmsg_internal(), ERROR, ExitPostmaster(), external_pid_file, FATAL, fprintf, free, get_stats_option_name(), GetConfigOption(), GetConfigOptionFlags(), GetCurrentTimestamp(), getInstallationPaths(), getopt(), GUC_RUNTIME_COMPUTED, i, InitializeGUCOptions(), InitializeMaxBackends(), InitializeShmemGUCs(), InitializeWalConsistencyChecking(), InitPostmasterDeathWatchHandle(), InitProcessGlobals(), IsBinaryUpgrade, IsPostmasterEnvironment, lfirst, list_free(), list_free_deep(), ListenAddresses, ListenSocket, 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, on_proc_exit(), optarg, opterr, optind, ParseLongOption(), pfree(), pg_hton16, PG_MODE_MASK_OWNER, PG_SETMASK, PG_TEMP_FILES_DIR, PGC_POSTMASTER, PGC_S_ARGV, PGC_S_OVERRIDE, PGC_SUSET, PGINVALID_SOCKET, PgStartTime, pgwin32_signal_initialize(), PM_STARTUP, PM_STATUS_STARTING, pmdie(), pmState, PostmasterContext, PostmasterPid, PostPortNumber, pqinitmask(), pqsignal_pm(), process_shared_preload_libraries(), process_shmem_requests(), progname, pstrdup(), reaper(), Reinit, RemoveLogrotateSignalFiles(), RemovePgTempFiles(), RemovePgTempFilesInDir(), RemovePromoteSignalFiles(), ReservedBackends, reset_shared(), S_IRGRP, S_IROTH, S_IRUSR, S_IWUSR, secure_initialize(), SelectConfigFiles(), SendStop, ServerLoop(), set_debug_options(), set_max_safe_fds(), set_plan_disabling_options(), set_stack_base(), SetConfigOption(), SIG_IGN, SIGALRM, SIGCHLD, SIGHUP, SIGHUP_handler(), SIGPIPE, SIGQUIT, SIGUSR1, sigusr1_handler(), SIGUSR2, SplitDirectoriesString(), SplitGUCList(), StartBackgroundWriter, StartCheckpointer, STARTUP_RUNNING, StartupDataBase, StartupPID, StartupStatus, status(), STATUS_OK, StreamServerPort(), strerror, success, SysLogger_Start(), SysLoggerPID, TopMemoryContext, 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 6066 of file postmaster.c.

6067 {
6068  dlist_iter iter;
6069  Backend *bp;
6070 
6071  dlist_foreach(iter, &BackendList)
6072  {
6073  bp = dlist_container(Backend, elem, iter.cur);
6074  if (bp->pid == pid)
6075  {
6076  bp->bgworker_notify = true;
6077  return true;
6078  }
6079  }
6080  return false;
6081 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:526
#define dlist_container(type, membername, ptr)
Definition: ilist.h:496
static dlist_head BackendList
Definition: postmaster.c:191
bool bgworker_notify
Definition: postmaster.c:187
pid_t pid
Definition: postmaster.c:182
dlist_node * cur
Definition: ilist.h:161

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

Referenced by BackendInitialize(), and PerformAuthentication().

◆ bonjour_name

PGDLLIMPORT char* bonjour_name
extern

Definition at line 246 of file postmaster.c.

Referenced by PostmasterMain().

◆ ClientAuthInProgress

◆ enable_bonjour

PGDLLIMPORT bool enable_bonjour
extern

Definition at line 245 of file postmaster.c.

Referenced by PostmasterMain().

◆ EnableSSL

PGDLLIMPORT bool EnableSSL
extern

Definition at line 236 of file postmaster.c.

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

◆ ListenAddresses

PGDLLIMPORT char* ListenAddresses
extern

Definition at line 208 of file postmaster.c.

Referenced by PostmasterMain().

◆ Log_connections

PGDLLIMPORT bool Log_connections
extern

Definition at line 242 of file postmaster.c.

Referenced by BackendInitialize(), PerformAuthentication(), and set_authn_id().

◆ log_hostname

PGDLLIMPORT bool log_hostname
extern

Definition at line 241 of file postmaster.c.

Referenced by BackendInitialize().

◆ postmaster_alive_fds

PGDLLIMPORT int postmaster_alive_fds[2]
extern

◆ PostPortNumber

PGDLLIMPORT int PostPortNumber
extern

Definition at line 202 of file postmaster.c.

Referenced by CreateLockFile(), and PostmasterMain().

◆ PreAuthDelay

PGDLLIMPORT int PreAuthDelay
extern

Definition at line 238 of file postmaster.c.

Referenced by BackendInitialize().

◆ progname

◆ remove_temp_files_after_crash

PGDLLIMPORT bool remove_temp_files_after_crash
extern

Definition at line 248 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ ReservedBackends

PGDLLIMPORT int ReservedBackends
extern

Definition at line 219 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ restart_after_crash

PGDLLIMPORT bool restart_after_crash
extern

Definition at line 247 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ Unix_socket_directories

PGDLLIMPORT char* Unix_socket_directories
extern

Definition at line 205 of file postmaster.c.

Referenced by PostmasterMain().

◆ Unix_socket_group

PGDLLIMPORT char* Unix_socket_group
extern

Definition at line 109 of file pqcomm.c.

◆ Unix_socket_permissions

PGDLLIMPORT int Unix_socket_permissions
extern

Definition at line 108 of file pqcomm.c.

Referenced by show_unix_socket_permissions().