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

bool EnableSSL
 
int ReservedBackends
 
PGDLLIMPORT int PostPortNumber
 
int Unix_socket_permissions
 
char * Unix_socket_group
 
char * Unix_socket_directories
 
char * ListenAddresses
 
bool ClientAuthInProgress
 
int PreAuthDelay
 
int AuthenticationTimeout
 
bool Log_connections
 
bool log_hostname
 
bool enable_bonjour
 
char * bonjour_name
 
bool restart_after_crash
 
bool remove_temp_files_after_crash
 
int postmaster_alive_fds [2]
 
PGDLLIMPORT const char * progname
 

Macro Definition Documentation

◆ MAX_BACKENDS

◆ POSTMASTER_FD_OWN

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

Definition at line 45 of file postmaster.h.

Referenced by ClosePostmasterPorts().

◆ 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.

Referenced by AddWaitEventToSet(), InitPostmasterDeathWatchHandle(), and PostmasterIsAliveInternal().

Function Documentation

◆ ClosePostmasterPorts()

void ClosePostmasterPorts ( bool  am_syslogger)

Definition at line 2612 of file postmaster.c.

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 BackendRun(), BackendStartup(), do_start_bgworker(), pgstat_start(), StartAutoVacWorker(), StartChildProcess(), and SysLogger_Start().

2613 {
2614  int i;
2615 
2616 #ifndef WIN32
2617 
2618  /*
2619  * Close the write end of postmaster death watch pipe. It's important to
2620  * do this as early as possible, so that if postmaster dies, others won't
2621  * think that it's still running because we're holding the pipe open.
2622  */
2624  ereport(FATAL,
2626  errmsg_internal("could not close postmaster death monitoring pipe in child process: %m")));
2628  /* Notify fd.c that we released one pipe FD. */
2630 #endif
2631 
2632  /*
2633  * Close the postmaster's listen sockets. These aren't tracked by fd.c,
2634  * so we don't call ReleaseExternalFD() here.
2635  */
2636  for (i = 0; i < MAXLISTEN; i++)
2637  {
2638  if (ListenSocket[i] != PGINVALID_SOCKET)
2639  {
2642  }
2643  }
2644 
2645  /*
2646  * If using syslogger, close the read side of the pipe. We don't bother
2647  * tracking this in fd.c, either.
2648  */
2649  if (!am_syslogger)
2650  {
2651 #ifndef WIN32
2652  if (syslogPipe[0] >= 0)
2653  close(syslogPipe[0]);
2654  syslogPipe[0] = -1;
2655 #else
2656  if (syslogPipe[0])
2657  CloseHandle(syslogPipe[0]);
2658  syslogPipe[0] = 0;
2659 #endif
2660  }
2661 
2662 #ifdef USE_BONJOUR
2663  /* If using Bonjour, close the connection to the mDNS daemon */
2664  if (bonjour_sdref)
2665  close(DNSServiceRefSockFD(bonjour_sdref));
2666 #endif
2667 }
void StreamClose(pgsocket sock)
Definition: pqcomm.c:850
#define FATAL
Definition: elog.h:49
#define POSTMASTER_FD_OWN
Definition: postmaster.h:45
int errcode_for_file_access(void)
Definition: elog.c:721
int postmaster_alive_fds[2]
Definition: postmaster.c:571
static pgsocket ListenSocket[MAXLISTEN]
Definition: postmaster.c:221
#define PGINVALID_SOCKET
Definition: port.h:33
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg_internal(const char *fmt,...)
Definition: elog.c:996
void ReleaseExternalFD(void)
Definition: fd.c:1228
int i
#define close(a)
Definition: win32.h:12
#define MAXLISTEN
Definition: postmaster.c:220
int syslogPipe[2]
Definition: syslogger.c:115

◆ InitProcessGlobals()

void InitProcessGlobals ( void  )

Definition at line 2676 of file postmaster.c.

References GetCurrentTimestamp(), MyProcPid, MyStartTime, MyStartTimestamp, pg_strong_random(), srandom(), and timestamptz_to_time_t().

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

2677 {
2678  unsigned int rseed;
2679 
2680  MyProcPid = getpid();
2683 
2684  /*
2685  * Set a different seed for random() in every process. We want something
2686  * unpredictable, so if possible, use high-quality random bits for the
2687  * seed. Otherwise, fall back to a seed based on timestamp and PID.
2688  */
2689  if (!pg_strong_random(&rseed, sizeof(rseed)))
2690  {
2691  /*
2692  * Since PIDs and timestamps tend to change more frequently in their
2693  * least significant bits, shift the timestamp left to allow a larger
2694  * total number of seeds in a given time period. Since that would
2695  * leave only 20 bits of the timestamp that cycle every ~1 second,
2696  * also mix in some higher bits.
2697  */
2698  rseed = ((uint64) MyProcPid) ^
2699  ((uint64) MyStartTimestamp << 12) ^
2700  ((uint64) MyStartTimestamp >> 20);
2701  }
2702  srandom(rseed);
2703 }
int MyProcPid
Definition: globals.c:43
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1580
pg_time_t MyStartTime
Definition: globals.c:44
pg_time_t timestamptz_to_time_t(TimestampTz t)
Definition: timestamp.c:1754
TimestampTz MyStartTimestamp
Definition: globals.c:45
bool pg_strong_random(void *buf, size_t len)
void srandom(unsigned int seed)
Definition: srandom.c:22

◆ MaxLivePostmasterChildren()

int MaxLivePostmasterChildren ( void  )

Definition at line 5719 of file postmaster.c.

References autovacuum_max_workers, max_wal_senders, max_worker_processes, and MaxConnections.

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

5720 {
5721  return 2 * (MaxConnections + autovacuum_max_workers + 1 +
5723 }
int max_wal_senders
Definition: walsender.c:121
int MaxConnections
Definition: globals.c:136
int autovacuum_max_workers
Definition: autovacuum.c:115
int max_worker_processes
Definition: globals.c:137

◆ PostmasterMain()

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

Definition at line 581 of file postmaster.c.

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(), 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, PGINVALID_SOCKET, PgStartTime, pgstat_init(), pgwin32_signal_initialize(), PM_STARTUP, PM_STATUS_STARTING, pmdie(), pmState, PostmasterContext, PostmasterPid, PostPortNumber, pqinitmask(), pqsignal_pm(), process_shared_preload_libraries(), 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().

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

◆ PostmasterMarkPIDForWorkerNotify()

bool PostmasterMarkPIDForWorkerNotify ( int  )

Definition at line 6135 of file postmaster.c.

References AllocateFile(), Assert, AuxiliaryProcs, bkend::bgworker_notify, bkend::child_slot, closesocket, dlist_iter::cur, DataDir, generate_unaccent_rules::dest, dlist_container, dlist_foreach, bkend::elem, ereport, errmsg(), errmsg_internal(), first_syslogger_file_time, free, FreeFile(), i, IsBinaryUpgrade, sort-test::key, ListenSocket, LOG, MainLWLockArray, max_safe_fds, MaxBackends, MaxLivePostmasterChildren(), MAXPGPATH, mul_size(), my_exec_path, MyCancelKey, MyPMChildSlot, NamedLWLockTrancheArray, NamedLWLockTrancheRequests, PG_BINARY_R, pg_queue_signal(), PGINVALID_SOCKET, PgReloadTime, PgStartTime, pgStatSock, pgwin32_create_signal_listener(), pgwin32_initial_signal_pipe, bkend::pid, pkglib_path, PMSignalState, postmaster_alive_fds, PostmasterPid, PreparedXactProcs, ProcGlobal, ProcStructLock, query_id_enabled, redirection_done, ReserveExternalFD(), SetDataDir(), ShmemAlloc(), ShmemLock, ShmemProtectiveRegion, ShmemVariableCache, SIGCHLD, Port::sock, SpinlockSemaArray, strerror, strlcpy(), syslogPipe, UsedShmemSegAddr, UsedShmemSegID, and write_stderr.

Referenced by BackgroundWorkerStateChange().

6136 {
6137  dlist_iter iter;
6138  Backend *bp;
6139 
6140  dlist_foreach(iter, &BackendList)
6141  {
6142  bp = dlist_container(Backend, elem, iter.cur);
6143  if (bp->pid == pid)
6144  {
6145  bp->bgworker_notify = true;
6146  return true;
6147  }
6148  }
6149  return false;
6150 }
#define dlist_foreach(iter, lhead)
Definition: ilist.h:526
bool bgworker_notify
Definition: postmaster.c:185
#define dlist_container(type, membername, ptr)
Definition: ilist.h:496
static dlist_head BackendList
Definition: postmaster.c:189
dlist_node * cur
Definition: ilist.h:161
pid_t pid
Definition: postmaster.c:180

Variable Documentation

◆ AuthenticationTimeout

int AuthenticationTimeout

Definition at line 237 of file postmaster.c.

Referenced by BackendInitialize(), and PerformAuthentication().

◆ bonjour_name

char* bonjour_name

Definition at line 244 of file postmaster.c.

Referenced by PostmasterMain().

◆ ClientAuthInProgress

◆ enable_bonjour

bool enable_bonjour

Definition at line 243 of file postmaster.c.

Referenced by PostmasterMain().

◆ EnableSSL

bool EnableSSL

Definition at line 234 of file postmaster.c.

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

◆ ListenAddresses

char* ListenAddresses

Definition at line 206 of file postmaster.c.

Referenced by PostmasterMain().

◆ Log_connections

bool Log_connections

Definition at line 240 of file postmaster.c.

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

◆ log_hostname

bool log_hostname

Definition at line 239 of file postmaster.c.

Referenced by BackendInitialize().

◆ postmaster_alive_fds

◆ PostPortNumber

PGDLLIMPORT int PostPortNumber

Definition at line 200 of file postmaster.c.

Referenced by CreateLockFile(), and PostmasterMain().

◆ PreAuthDelay

int PreAuthDelay

Definition at line 236 of file postmaster.c.

Referenced by BackendInitialize().

◆ progname

◆ remove_temp_files_after_crash

bool remove_temp_files_after_crash

Definition at line 246 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ ReservedBackends

int ReservedBackends

Definition at line 217 of file postmaster.c.

Referenced by InitPostgres(), and PostmasterMain().

◆ restart_after_crash

bool restart_after_crash

Definition at line 245 of file postmaster.c.

Referenced by PostmasterStateMachine().

◆ Unix_socket_directories

char* Unix_socket_directories

Definition at line 203 of file postmaster.c.

Referenced by PostmasterMain().

◆ Unix_socket_group

char* Unix_socket_group

Definition at line 109 of file pqcomm.c.

Referenced by StreamServerPort().

◆ Unix_socket_permissions

int Unix_socket_permissions

Definition at line 108 of file pqcomm.c.

Referenced by show_unix_socket_permissions(), and StreamServerPort().