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

2575 {
2576  int i;
2577 
2578  /* Release resources held by the postmaster's WaitEventSet. */
2579  if (pm_wait_set)
2580  {
2582  pm_wait_set = NULL;
2583  }
2584 
2585 #ifndef WIN32
2586 
2587  /*
2588  * Close the write end of postmaster death watch pipe. It's important to
2589  * do this as early as possible, so that if postmaster dies, others won't
2590  * think that it's still running because we're holding the pipe open.
2591  */
2593  ereport(FATAL,
2595  errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
2597  /* Notify fd.c that we released one pipe FD. */
2599 #endif
2600 
2601  /*
2602  * Close the postmaster's listen sockets. These aren't tracked by fd.c,
2603  * so we don't call ReleaseExternalFD() here.
2604  */
2605  for (i = 0; i < MAXLISTEN; i++)
2606  {
2608  {
2611  }
2612  }
2613 
2614  /*
2615  * If using syslogger, close the read side of the pipe. We don't bother
2616  * tracking this in fd.c, either.
2617  */
2618  if (!am_syslogger)
2619  {
2620 #ifndef WIN32
2621  if (syslogPipe[0] >= 0)
2622  close(syslogPipe[0]);
2623  syslogPipe[0] = -1;
2624 #else
2625  if (syslogPipe[0])
2626  CloseHandle(syslogPipe[0]);
2627  syslogPipe[0] = 0;
2628 #endif
2629  }
2630 
2631 #ifdef USE_BONJOUR
2632  /* If using Bonjour, close the connection to the mDNS daemon */
2633  if (bonjour_sdref)
2634  close(DNSServiceRefSockFD(bonjour_sdref));
2635 #endif
2636 }
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1156
int errcode_for_file_access(void)
Definition: elog.c:881
#define FATAL
Definition: elog.h:41
#define ereport(elevel,...)
Definition: elog.h:149
void ReleaseExternalFD(void)
Definition: fd.c:1152
#define close(a)
Definition: win32.h:12
int i
Definition: isn.c:73
void FreeWaitEventSetAfterFork(WaitEventSet *set)
Definition: latch.c:876
#define PGINVALID_SOCKET
Definition: port.h:31
int postmaster_alive_fds[2]
Definition: postmaster.c:576
static WaitEventSet * pm_wait_set
Definition: postmaster.c:383
#define MAXLISTEN
Definition: postmaster.c:228
static pgsocket ListenSocket[MAXLISTEN]
Definition: postmaster.c:229
#define POSTMASTER_FD_OWN
Definition: postmaster.h:47
void StreamClose(pgsocket sock)
Definition: pqcomm.c:825
int syslogPipe[2]
Definition: syslogger.c:117

References close, ereport, errcode_for_file_access(), errmsg_internal(), FATAL, FreeWaitEventSetAfterFork(), i, ListenSocket, MAXLISTEN, PGINVALID_SOCKET, pm_wait_set, 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 2645 of file postmaster.c.

2646 {
2647  MyProcPid = getpid();
2650 
2651  /*
2652  * Set a different global seed in every process. We want something
2653  * unpredictable, so if possible, use high-quality random bits for the
2654  * seed. Otherwise, fall back to a seed based on timestamp and PID.
2655  */
2657  {
2658  uint64 rseed;
2659 
2660  /*
2661  * Since PIDs and timestamps tend to change more frequently in their
2662  * least significant bits, shift the timestamp left to allow a larger
2663  * total number of seeds in a given time period. Since that would
2664  * leave only 20 bits of the timestamp that cycle every ~1 second,
2665  * also mix in some higher bits.
2666  */
2667  rseed = ((uint64) MyProcPid) ^
2668  ((uint64) MyStartTimestamp << 12) ^
2669  ((uint64) MyStartTimestamp >> 20);
2670 
2672  }
2673 
2674  /*
2675  * Also make sure that we've set a good seed for random(3). Use of that
2676  * is deprecated in core Postgres, but extensions might use it.
2677  */
2678 #ifndef WIN32
2680 #endif
2681 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1585
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition: timestamp.c:1773
#define unlikely(x)
Definition: c.h:295
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: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 5598 of file postmaster.c.

5599 {
5600  return 2 * (MaxConnections + autovacuum_max_workers + 1 +
5602 }
int autovacuum_max_workers
Definition: autovacuum.c:117
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 586 of file postmaster.c.

587 {
588  int opt;
589  int status;
590  char *userDoption = NULL;
591  bool listen_addr_saved = false;
592  int i;
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\"")));
935 
936  /*
937  * Other one-time internal sanity checks can go here, if they are fast.
938  * (Put any slow processing further down, after postmaster.pid creation.)
939  */
940  if (!CheckDateTokenTables())
941  {
942  write_stderr("%s: invalid datetoken tables, please fix\n", progname);
943  ExitPostmaster(1);
944  }
945 
946  /*
947  * Now that we are done processing the postmaster arguments, reset
948  * getopt(3) library so that it will work correctly in subprocesses.
949  */
950  optind = 1;
951 #ifdef HAVE_INT_OPTRESET
952  optreset = 1; /* some systems need this too */
953 #endif
954 
955  /* For debugging: display postmaster environment */
956  {
957  extern char **environ;
958  char **p;
959 
960  ereport(DEBUG3,
961  (errmsg_internal("%s: PostmasterMain: initial environment dump:",
962  progname)));
963  ereport(DEBUG3,
964  (errmsg_internal("-----------------------------------------")));
965  for (p = environ; *p; ++p)
966  ereport(DEBUG3,
967  (errmsg_internal("\t%s", *p)));
968  ereport(DEBUG3,
969  (errmsg_internal("-----------------------------------------")));
970  }
971 
972  /*
973  * Create lockfile for data directory.
974  *
975  * We want to do this before we try to grab the input sockets, because the
976  * data directory interlock is more reliable than the socket-file
977  * interlock (thanks to whoever decided to put socket files in /tmp :-().
978  * For the same reason, it's best to grab the TCP socket(s) before the
979  * Unix socket(s).
980  *
981  * Also note that this internally sets up the on_proc_exit function that
982  * is responsible for removing both data directory and socket lockfiles;
983  * so it must happen before opening sockets so that at exit, the socket
984  * lockfiles go away after CloseServerPorts runs.
985  */
986  CreateDataDirLockFile(true);
987 
988  /*
989  * Read the control file (for error checking and config info).
990  *
991  * Since we verify the control file's CRC, this has a useful side effect
992  * on machines where we need a run-time test for CRC support instructions.
993  * The postmaster will do the test once at startup, and then its child
994  * processes will inherit the correct function pointer and not need to
995  * repeat the test.
996  */
998 
999  /*
1000  * Register the apply launcher. It's probably a good idea to call this
1001  * before any modules had a chance to take the background worker slots.
1002  */
1004 
1005  /*
1006  * process any libraries that should be preloaded at postmaster start
1007  */
1009 
1010  /*
1011  * Initialize SSL library, if specified.
1012  */
1013 #ifdef USE_SSL
1014  if (EnableSSL)
1015  {
1016  (void) secure_initialize(true);
1017  LoadedSSL = true;
1018  }
1019 #endif
1020 
1021  /*
1022  * Now that loadable modules have had their chance to alter any GUCs,
1023  * calculate MaxBackends.
1024  */
1026 
1027  /*
1028  * Give preloaded libraries a chance to request additional shared memory.
1029  */
1031 
1032  /*
1033  * Now that loadable modules have had their chance to request additional
1034  * shared memory, determine the value of any runtime-computed GUCs that
1035  * depend on the amount of shared memory required.
1036  */
1038 
1039  /*
1040  * Now that modules have been loaded, we can process any custom resource
1041  * managers specified in the wal_consistency_checking GUC.
1042  */
1044 
1045  /*
1046  * If -C was specified with a runtime-computed GUC, we held off printing
1047  * the value earlier, as the GUC was not yet initialized. We handle -C
1048  * for most GUCs before we lock the data directory so that the option may
1049  * be used on a running server. However, a handful of GUCs are runtime-
1050  * computed and do not have meaningful values until after locking the data
1051  * directory, and we cannot safely calculate their values earlier on a
1052  * running server. At this point, such GUCs should be properly
1053  * initialized, and we haven't yet set up shared memory, so this is a good
1054  * time to handle the -C option for these special GUCs.
1055  */
1056  if (output_config_variable != NULL)
1057  {
1058  const char *config_val = GetConfigOption(output_config_variable,
1059  false, false);
1060 
1061  puts(config_val ? config_val : "");
1062  ExitPostmaster(0);
1063  }
1064 
1065  /*
1066  * Set up shared memory and semaphores.
1067  *
1068  * Note: if using SysV shmem and/or semas, each postmaster startup will
1069  * normally choose the same IPC keys. This helps ensure that we will
1070  * clean up dead IPC objects if the postmaster crashes and is restarted.
1071  */
1073 
1074  /*
1075  * Estimate number of openable files. This must happen after setting up
1076  * semaphores, because on some platforms semaphores count as open files.
1077  */
1078  set_max_safe_fds();
1079 
1080  /*
1081  * Set reference point for stack-depth checking.
1082  */
1083  (void) set_stack_base();
1084 
1085  /*
1086  * Initialize pipe (or process handle on Windows) that allows children to
1087  * wake up from sleep on postmaster death.
1088  */
1090 
1091 #ifdef WIN32
1092 
1093  /*
1094  * Initialize I/O completion port used to deliver list of dead children.
1095  */
1096  win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
1097  if (win32ChildQueue == NULL)
1098  ereport(FATAL,
1099  (errmsg("could not create I/O completion port for child queue")));
1100 #endif
1101 
1102 #ifdef EXEC_BACKEND
1103  /* Write out nondefault GUC settings for child processes to use */
1104  write_nondefault_variables(PGC_POSTMASTER);
1105 
1106  /*
1107  * Clean out the temp directory used to transmit parameters to child
1108  * processes (see internal_forkexec, below). We must do this before
1109  * launching any child processes, else we have a race condition: we could
1110  * remove a parameter file before the child can read it. It should be
1111  * safe to do so now, because we verified earlier that there are no
1112  * conflicting Postgres processes in this data directory.
1113  */
1115 #endif
1116 
1117  /*
1118  * Forcibly remove the files signaling a standby promotion request.
1119  * Otherwise, the existence of those files triggers a promotion too early,
1120  * whether a user wants that or not.
1121  *
1122  * This removal of files is usually unnecessary because they can exist
1123  * only during a few moments during a standby promotion. However there is
1124  * a race condition: if pg_ctl promote is executed and creates the files
1125  * during a promotion, the files can stay around even after the server is
1126  * brought up to be the primary. Then, if a new standby starts by using
1127  * the backup taken from the new primary, the files can exist at server
1128  * startup and must be removed in order to avoid an unexpected promotion.
1129  *
1130  * Note that promotion signal files need to be removed before the startup
1131  * process is invoked. Because, after that, they can be used by
1132  * postmaster's SIGUSR1 signal handler.
1133  */
1135 
1136  /* Do the same for logrotate signal file */
1138 
1139  /* Remove any outdated file holding the current log filenames. */
1140  if (unlink(LOG_METAINFO_DATAFILE) < 0 && errno != ENOENT)
1141  ereport(LOG,
1143  errmsg("could not remove file \"%s\": %m",
1145 
1146  /*
1147  * If enabled, start up syslogger collection subprocess
1148  */
1150 
1151  /*
1152  * Reset whereToSendOutput from DestDebug (its starting state) to
1153  * DestNone. This stops ereport from sending log messages to stderr unless
1154  * Log_destination permits. We don't do this until the postmaster is
1155  * fully launched, since startup failures may as well be reported to
1156  * stderr.
1157  *
1158  * If we are in fact disabling logging to stderr, first emit a log message
1159  * saying so, to provide a breadcrumb trail for users who may not remember
1160  * that their logging is configured to go somewhere else.
1161  */
1163  ereport(LOG,
1164  (errmsg("ending log output to stderr"),
1165  errhint("Future log output will go to log destination \"%s\".",
1167 
1169 
1170  /*
1171  * Report server startup in log. While we could emit this much earlier,
1172  * it seems best to do so after starting the log collector, if we intend
1173  * to use one.
1174  */
1175  ereport(LOG,
1176  (errmsg("starting %s", PG_VERSION_STR)));
1177 
1178  /*
1179  * Establish input sockets.
1180  *
1181  * First, mark them all closed, and set up an on_proc_exit function that's
1182  * charged with closing the sockets again at postmaster shutdown.
1183  */
1184  for (i = 0; i < MAXLISTEN; i++)
1186 
1188 
1189  if (ListenAddresses)
1190  {
1191  char *rawstring;
1192  List *elemlist;
1193  ListCell *l;
1194  int success = 0;
1195 
1196  /* Need a modifiable copy of ListenAddresses */
1197  rawstring = pstrdup(ListenAddresses);
1198 
1199  /* Parse string into list of hostnames */
1200  if (!SplitGUCList(rawstring, ',', &elemlist))
1201  {
1202  /* syntax error in list */
1203  ereport(FATAL,
1204  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1205  errmsg("invalid list syntax in parameter \"%s\"",
1206  "listen_addresses")));
1207  }
1208 
1209  foreach(l, elemlist)
1210  {
1211  char *curhost = (char *) lfirst(l);
1212 
1213  if (strcmp(curhost, "*") == 0)
1214  status = StreamServerPort(AF_UNSPEC, NULL,
1215  (unsigned short) PostPortNumber,
1216  NULL,
1218  else
1219  status = StreamServerPort(AF_UNSPEC, curhost,
1220  (unsigned short) PostPortNumber,
1221  NULL,
1223 
1224  if (status == STATUS_OK)
1225  {
1226  success++;
1227  /* record the first successful host addr in lockfile */
1228  if (!listen_addr_saved)
1229  {
1231  listen_addr_saved = true;
1232  }
1233  }
1234  else
1235  ereport(WARNING,
1236  (errmsg("could not create listen socket for \"%s\"",
1237  curhost)));
1238  }
1239 
1240  if (!success && elemlist != NIL)
1241  ereport(FATAL,
1242  (errmsg("could not create any TCP/IP sockets")));
1243 
1244  list_free(elemlist);
1245  pfree(rawstring);
1246  }
1247 
1248 #ifdef USE_BONJOUR
1249  /* Register for Bonjour only if we opened TCP socket(s) */
1251  {
1252  DNSServiceErrorType err;
1253 
1254  /*
1255  * We pass 0 for interface_index, which will result in registering on
1256  * all "applicable" interfaces. It's not entirely clear from the
1257  * DNS-SD docs whether this would be appropriate if we have bound to
1258  * just a subset of the available network interfaces.
1259  */
1260  err = DNSServiceRegister(&bonjour_sdref,
1261  0,
1262  0,
1263  bonjour_name,
1264  "_postgresql._tcp.",
1265  NULL,
1266  NULL,
1268  0,
1269  NULL,
1270  NULL,
1271  NULL);
1272  if (err != kDNSServiceErr_NoError)
1273  ereport(LOG,
1274  (errmsg("DNSServiceRegister() failed: error code %ld",
1275  (long) err)));
1276 
1277  /*
1278  * We don't bother to read the mDNS daemon's reply, and we expect that
1279  * it will automatically terminate our registration when the socket is
1280  * closed at postmaster termination. So there's nothing more to be
1281  * done here. However, the bonjour_sdref is kept around so that
1282  * forked children can close their copies of the socket.
1283  */
1284  }
1285 #endif
1286 
1288  {
1289  char *rawstring;
1290  List *elemlist;
1291  ListCell *l;
1292  int success = 0;
1293 
1294  /* Need a modifiable copy of Unix_socket_directories */
1295  rawstring = pstrdup(Unix_socket_directories);
1296 
1297  /* Parse string into list of directories */
1298  if (!SplitDirectoriesString(rawstring, ',', &elemlist))
1299  {
1300  /* syntax error in list */
1301  ereport(FATAL,
1302  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1303  errmsg("invalid list syntax in parameter \"%s\"",
1304  "unix_socket_directories")));
1305  }
1306 
1307  foreach(l, elemlist)
1308  {
1309  char *socketdir = (char *) lfirst(l);
1310 
1311  status = StreamServerPort(AF_UNIX, NULL,
1312  (unsigned short) PostPortNumber,
1313  socketdir,
1315 
1316  if (status == STATUS_OK)
1317  {
1318  success++;
1319  /* record the first successful Unix socket in lockfile */
1320  if (success == 1)
1322  }
1323  else
1324  ereport(WARNING,
1325  (errmsg("could not create Unix-domain socket in directory \"%s\"",
1326  socketdir)));
1327  }
1328 
1329  if (!success && elemlist != NIL)
1330  ereport(FATAL,
1331  (errmsg("could not create any Unix-domain sockets")));
1332 
1333  list_free_deep(elemlist);
1334  pfree(rawstring);
1335  }
1336 
1337  /*
1338  * check that we have some socket to listen on
1339  */
1340  if (ListenSocket[0] == PGINVALID_SOCKET)
1341  ereport(FATAL,
1342  (errmsg("no socket created for listening")));
1343 
1344  /*
1345  * If no valid TCP ports, write an empty line for listen address,
1346  * indicating the Unix socket must be used. Note that this line is not
1347  * added to the lock file until there is a socket backing it.
1348  */
1349  if (!listen_addr_saved)
1351 
1352  /*
1353  * Record postmaster options. We delay this till now to avoid recording
1354  * bogus options (eg, unusable port number).
1355  */
1356  if (!CreateOptsFile(argc, argv, my_exec_path))
1357  ExitPostmaster(1);
1358 
1359  /*
1360  * Write the external PID file if requested
1361  */
1362  if (external_pid_file)
1363  {
1364  FILE *fpidfile = fopen(external_pid_file, "w");
1365 
1366  if (fpidfile)
1367  {
1368  fprintf(fpidfile, "%d\n", MyProcPid);
1369  fclose(fpidfile);
1370 
1371  /* Make PID file world readable */
1372  if (chmod(external_pid_file, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0)
1373  write_stderr("%s: could not change permissions of external PID file \"%s\": %s\n",
1375  }
1376  else
1377  write_stderr("%s: could not write external PID file \"%s\": %s\n",
1379 
1381  }
1382 
1383  /*
1384  * Remove old temporary files. At this point there can be no other
1385  * Postgres processes running in this directory, so this should be safe.
1386  */
1388 
1389  /*
1390  * Initialize the autovacuum subsystem (again, no process start yet)
1391  */
1392  autovac_init();
1393 
1394  /*
1395  * Load configuration files for client authentication.
1396  */
1397  if (!load_hba())
1398  {
1399  /*
1400  * It makes no sense to continue if we fail to load the HBA file,
1401  * since there is no way to connect to the database in this case.
1402  */
1403  ereport(FATAL,
1404  /* translator: %s is a configuration file */
1405  (errmsg("could not load %s", HbaFileName)));
1406  }
1407  if (!load_ident())
1408  {
1409  /*
1410  * We can start up without the IDENT file, although it means that you
1411  * cannot log in using any of the authentication methods that need a
1412  * user name mapping. load_ident() already logged the details of error
1413  * to the log.
1414  */
1415  }
1416 
1417 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1418 
1419  /*
1420  * On macOS, libintl replaces setlocale() with a version that calls
1421  * CFLocaleCopyCurrent() when its second argument is "" and every relevant
1422  * environment variable is unset or empty. CFLocaleCopyCurrent() makes
1423  * the process multithreaded. The postmaster calls sigprocmask() and
1424  * calls fork() without an immediate exec(), both of which have undefined
1425  * behavior in a multithreaded program. A multithreaded postmaster is the
1426  * normal case on Windows, which offers neither fork() nor sigprocmask().
1427  */
1428  if (pthread_is_threaded_np() != 0)
1429  ereport(FATAL,
1430  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1431  errmsg("postmaster became multithreaded during startup"),
1432  errhint("Set the LC_ALL environment variable to a valid locale.")));
1433 #endif
1434 
1435  /*
1436  * Remember postmaster startup time
1437  */
1439 
1440  /*
1441  * Report postmaster status in the postmaster.pid file, to allow pg_ctl to
1442  * see what's happening.
1443  */
1445 
1446  /* Start bgwriter and checkpointer so they can help with recovery */
1447  if (CheckpointerPID == 0)
1449  if (BgWriterPID == 0)
1451 
1452  /*
1453  * We're ready to rock and roll...
1454  */
1456  Assert(StartupPID != 0);
1458  pmState = PM_STARTUP;
1459 
1460  /* Some workers may be scheduled to start now */
1462 
1463  status = ServerLoop();
1464 
1465  /*
1466  * ServerLoop probably shouldn't ever return, but if it does, close down.
1467  */
1469 
1470  abort(); /* not reached */
1471 }
void autovac_init(void)
Definition: autovacuum.c:3299
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:4762
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:1159
@ DestNone
Definition: dest.h:87
int Log_destination
Definition: elog.c:113
int errhint(const char *fmt,...)
Definition: elog.c:1316
char * Log_destination_string
Definition: elog.c:114
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#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
const char * name
Definition: encode.c:571
void RemovePgTempFilesInDir(const char *tmpdirname, bool missing_ok, bool unlink_all)
Definition: fd.c:3133
void RemovePgTempFiles(void)
Definition: fd.c:3074
void set_max_safe_fds(void)
Definition: fd.c:950
#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:4175
bool SelectConfigFiles(const char *userDoption, const char *progname)
Definition: guc.c:1748
void ParseLongOption(const char *string, char **name, char **value)
Definition: guc.c:6182
void InitializeGUCOptions(void)
Definition: guc.c:1494
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition: guc.c:4199
int GetConfigOptionFlags(const char *name, bool missing_ok)
Definition: guc.c:4292
#define GUC_RUNTIME_COMPUTED
Definition: guc.h:223
@ 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:510
char * external_pid_file
Definition: guc_tables.c:512
bool load_ident(void)
Definition: hba.c:3043
bool load_hba(void)
Definition: hba.c:2651
static struct @143 value
static bool success
Definition: initdb.c:170
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:305
void InitializeShmemGUCs(void)
Definition: ipci.c:325
void CreateSharedMemoryAndSemaphores(void)
Definition: ipci.c:174
void InitializeLatchSupport(void)
Definition: latch.c:207
void ApplyLauncherRegister(void)
Definition: launcher.c:881
Assert(fmt[strlen(fmt) - 1] !='\n')
void list_free(List *list)
Definition: list.c:1545
void list_free_deep(List *list)
Definition: list.c:1559
const char * progname
Definition: main.c:45
char * pstrdup(const char *in)
Definition: mcxt.c:1624
void pfree(void *pointer)
Definition: mcxt.c:1436
MemoryContext TopMemoryContext
Definition: mcxt.c:141
MemoryContext PostmasterContext
Definition: mcxt.c:143
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
void ChangeToDataDir(void)
Definition: miscinit.c:441
void process_shmem_requests(void)
Definition: miscinit.c:1863
void AddToDataDirLockFile(int target_line, const char *str)
Definition: miscinit.c:1503
void InitProcessLocalLatch(void)
Definition: miscinit.c:234
void process_shared_preload_libraries(void)
Definition: miscinit.c:1835
void checkDataDir(void)
Definition: miscinit.c:328
void CreateDataDirLockFile(bool amPostmaster)
Definition: miscinit.c:1447
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
#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:172
#define NIL
Definition: pg_list.h:68
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:224
#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)
#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:3585
CommandDest whereToSendOutput
Definition: postgres.c:84
bool set_plan_disabling_options(const char *arg, GucContext context, GucSource source)
Definition: postgres.c:3614
static const char * userDoption
Definition: postgres.c:155
const char * get_stats_option_name(const char *arg)
Definition: postgres.c:3656
pg_stack_base_t set_stack_base(void)
Definition: postgres.c:3404
void InitializeMaxBackends(void)
Definition: postinit.c:553
static void ExitPostmaster(int status) pg_attribute_noreturn()
Definition: postmaster.c:5051
static void handle_pm_shutdown_request_signal(SIGNAL_ARGS)
Definition: postmaster.c:2785
static void maybe_start_bgworkers(void)
Definition: postmaster.c:5902
static void CloseServerPorts(int status, Datum arg)
Definition: postmaster.c:1478
@ PM_STARTUP
Definition: postmaster.c:323
static void InitPostmasterDeathWatchHandle(void)
Definition: postmaster.c:6497
void InitProcessGlobals(void)
Definition: postmaster.c:2645
static void handle_pm_reload_request_signal(SIGNAL_ARGS)
Definition: postmaster.c:2702
static int ServerLoop(void)
Definition: postmaster.c:1727
int PostPortNumber
Definition: postmaster.c:198
static void checkControlFile(void)
Definition: postmaster.c:1580
#define StartupDataBase()
Definition: postmaster.c:559
bool enable_bonjour
Definition: postmaster.c:241
int ReservedConnections
Definition: postmaster.c:225
static void handle_pm_pmsignal_signal(SIGNAL_ARGS)
Definition: postmaster.c:2688
static pid_t CheckpointerPID
Definition: postmaster.c:251
static pid_t BgWriterPID
Definition: postmaster.c:250
char * Unix_socket_directories
Definition: postmaster.c:201
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname)
Definition: postmaster.c:5554
static void handle_pm_child_exit_signal(SIGNAL_ARGS)
Definition: postmaster.c:2964
static void getInstallationPaths(const char *argv0)
Definition: postmaster.c:1526
#define StartCheckpointer()
Definition: postmaster.c:562
@ STARTUP_RUNNING
Definition: postmaster.c:262
static void unlink_external_pid_file(int status, Datum arg)
Definition: postmaster.c:1514
#define StartBackgroundWriter()
Definition: postmaster.c:561
static StartupStatusEnum StartupStatus
Definition: postmaster.c:267
static void dummy_handler(SIGNAL_ARGS)
Definition: postmaster.c:5262
static pid_t StartupPID
Definition: postmaster.c:249
bool EnableSSL
Definition: postmaster.c:232
static PMState pmState
Definition: postmaster.c:337
char * ListenAddresses
Definition: postmaster.c:204
int SuperuserReservedConnections
Definition: postmaster.c:224
char * bonjour_name
Definition: postmaster.c:242
static pid_t SysLoggerPID
Definition: postmaster.c:256
int StreamServerPort(int family, const char *hostName, unsigned short portNumber, const char *unixSocketDir, pgsocket ListenSocket[], int MaxListen)
Definition: pqcomm.c:314
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:3857
bool SplitGUCList(char *rawstring, char separator, List **namelist)
Definition: varlena.c:3978
#define S_IROTH
Definition: win32_port.h:315
#define SIGCHLD
Definition: win32_port.h:186
#define SIGHUP
Definition: win32_port.h:176
#define S_IRGRP
Definition: win32_port.h:303
#define SIGPIPE
Definition: win32_port.h:181
#define SIGQUIT
Definition: win32_port.h:177
#define S_IRUSR
Definition: win32_port.h:291
#define SIGUSR1
Definition: win32_port.h:188
#define SIGALRM
Definition: win32_port.h:182
#define SIGUSR2
Definition: win32_port.h:189
#define SIG_IGN
Definition: win32_port.h:173
#define S_IWUSR
Definition: win32_port.h:294
int XLogArchiveMode
Definition: xlog.c:122
int wal_level
Definition: xlog.c:134
void InitializeWalConsistencyChecking(void)
Definition: xlog.c:4397
void LocalProcessControlFile(bool reset)
Definition: xlog.c:4460
@ 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(), CreateSharedMemoryAndSemaphores(), 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, 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, i, InitializeGUCOptions(), InitializeLatchSupport(), InitializeMaxBackends(), InitializeShmemGUCs(), InitializeWalConsistencyChecking(), InitPostmasterDeathWatchHandle(), InitProcessGlobals(), InitProcessLocalLatch(), 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_TEMP_FILES_DIR, PGC_POSTMASTER, PGC_S_ARGV, PGC_S_OVERRIDE, PGC_SUSET, PGINVALID_SOCKET, 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(), StartBackgroundWriter, StartCheckpointer, STARTUP_RUNNING, StartupDataBase, StartupPID, StartupStatus, status(), STATUS_OK, StreamServerPort(), strerror, success, 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 6021 of file postmaster.c.

6022 {
6023  dlist_iter iter;
6024  Backend *bp;
6025 
6026  dlist_foreach(iter, &BackendList)
6027  {
6028  bp = dlist_container(Backend, elem, iter.cur);
6029  if (bp->pid == pid)
6030  {
6031  bp->bgworker_notify = true;
6032  return true;
6033  }
6034  }
6035  return false;
6036 }
#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:187
bool bgworker_notify
Definition: postmaster.c:183
pid_t pid
Definition: postmaster.c:178
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 235 of file postmaster.c.

Referenced by BackendInitialize(), and PerformAuthentication().

◆ bonjour_name

PGDLLIMPORT char* bonjour_name
extern

Definition at line 242 of file postmaster.c.

Referenced by PostmasterMain().

◆ ClientAuthInProgress

◆ enable_bonjour

PGDLLIMPORT bool enable_bonjour
extern

Definition at line 241 of file postmaster.c.

Referenced by PostmasterMain().

◆ EnableSSL

PGDLLIMPORT bool EnableSSL
extern

Definition at line 232 of file postmaster.c.

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

◆ ListenAddresses

PGDLLIMPORT char* ListenAddresses
extern

Definition at line 204 of file postmaster.c.

Referenced by PostmasterMain().

◆ Log_connections

PGDLLIMPORT bool Log_connections
extern

Definition at line 238 of file postmaster.c.

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

◆ log_hostname

PGDLLIMPORT bool log_hostname
extern

Definition at line 237 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 198 of file postmaster.c.

Referenced by CreateLockFile(), and PostmasterMain().

◆ PreAuthDelay

PGDLLIMPORT int PreAuthDelay
extern

Definition at line 234 of file postmaster.c.

Referenced by BackendInitialize().

◆ progname

◆ remove_temp_files_after_crash

PGDLLIMPORT bool remove_temp_files_after_crash
extern

Definition at line 244 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ ReservedConnections

PGDLLIMPORT int ReservedConnections
extern

Definition at line 225 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ restart_after_crash

PGDLLIMPORT bool restart_after_crash
extern

Definition at line 243 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ send_abort_for_crash

PGDLLIMPORT bool send_abort_for_crash
extern

Definition at line 245 of file postmaster.c.

Referenced by sigquit_child().

◆ send_abort_for_kill

PGDLLIMPORT bool send_abort_for_kill
extern

Definition at line 246 of file postmaster.c.

Referenced by ServerLoop().

◆ SuperuserReservedConnections

PGDLLIMPORT int SuperuserReservedConnections
extern

Definition at line 224 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ Unix_socket_directories

PGDLLIMPORT char* Unix_socket_directories
extern

Definition at line 201 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().