80 #ifdef HAVE_SYS_SELECT_H 81 #include <sys/select.h> 89 #include <systemd/sd-daemon.h> 92 #ifdef HAVE_PTHREAD_IS_THREADED_NP 145 #define BACKEND_TYPE_NORMAL 0x0001 146 #define BACKEND_TYPE_AUTOVAC 0x0002 147 #define BACKEND_TYPE_WALSND 0x0004 148 #define BACKEND_TYPE_BGWORKER 0x0008 149 #define BACKEND_TYPE_ALL 0x000F 191 static Backend *ShmemBackendArray;
270 #define SmartShutdown 1 271 #define FastShutdown 2 272 #define ImmediateShutdown 3 358 #define SIGKILL_CHILDREN_AFTER_SECS 5 382 static bool LoadedSSL =
false;
386 static DNSServiceRef bonjour_sdref = NULL;
410 int pid,
int exitstatus);
428 #define SignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL) 433 static bool CreateOptsFile(
int argc,
char *argv[],
char *fullprogname);
445 #define PgArchStartupAllowed() \ 446 ((XLogArchivingActive() && pmState == PM_RUN) || \ 447 (XLogArchivingAlways() && \ 448 (pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY))) 455 static pid_t waitpid(pid_t
pid,
int *exitstatus,
int options);
456 static void WINAPI pgwin32_deadchild_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
458 static HANDLE win32ChildQueue;
465 } win32_deadchild_waitinfo;
468 static pid_t backend_forkexec(
Port *
port);
469 static pid_t internal_forkexec(
int argc,
char *argv[],
Port *
port);
477 WSAPROTOCOL_INFO wsainfo;
480 typedef int InheritableSocket;
489 InheritableSocket portsocket;
504 #ifndef HAVE_SPINLOCKS 525 HANDLE PostmasterHandle;
526 HANDLE initial_signal_pipe;
536 static void read_backend_variables(
char *
id,
Port *
port);
537 static void restore_backend_variables(BackendParameters *param,
Port *
port);
540 static bool save_backend_variables(BackendParameters *param,
Port *
port);
542 static bool save_backend_variables(BackendParameters *param,
Port *
port,
543 HANDLE childProcess, pid_t childPid);
546 static void ShmemBackendArrayAdd(
Backend *bn);
547 static void ShmemBackendArrayRemove(
Backend *bn);
550 #define StartupDataBase() StartChildProcess(StartupProcess) 551 #define StartBackgroundWriter() StartChildProcess(BgWriterProcess) 552 #define StartCheckpointer() StartChildProcess(CheckpointerProcess) 553 #define StartWalWriter() StartChildProcess(WalWriterProcess) 554 #define StartWalReceiver() StartChildProcess(WalReceiverProcess) 557 #define EXIT_STATUS_0(st) ((st) == 0) 558 #define EXIT_STATUS_1(st) (WIFEXITED(st) && WEXITSTATUS(st) == 1) 559 #define EXIT_STATUS_3(st) (WIFEXITED(st) && WEXITSTATUS(st) == 3) 569 HANDLE PostmasterHandle;
581 bool listen_addr_saved =
false;
583 char *output_config_variable = NULL;
690 while ((opt =
getopt(argc, argv,
"B:bc:C:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:W:-:")) != -1)
704 output_config_variable = strdup(
optarg);
708 userDoption = strdup(
optarg);
730 write_stderr(
"%s: invalid argument for option -f: \"%s\"\n",
809 write_stderr(
"%s: invalid argument for option -t: \"%s\"\n",
831 (
errcode(ERRCODE_SYNTAX_ERROR),
832 errmsg(
"--%s requires a value",
836 (
errcode(ERRCODE_SYNTAX_ERROR),
837 errmsg(
"-c %s requires a value",
849 write_stderr(
"Try \"%s --help\" for more information.\n",
862 write_stderr(
"Try \"%s --help\" for more information.\n",
874 if (output_config_variable != NULL)
884 puts(config_val ? config_val :
"");
902 write_stderr(
"%s: superuser_reserved_connections (%d) must be less than max_connections (%d)\n",
909 (
errmsg(
"WAL archival cannot be enabled when wal_level is \"minimal\"")));
912 (
errmsg(
"WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
929 #ifdef HAVE_INT_OPTRESET 943 for (p = environ; *p; ++p)
1034 win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
1035 if (win32ChildQueue == NULL)
1037 (
errmsg(
"could not create I/O completion port for child queue")));
1081 errmsg(
"could not remove file \"%s\": %m",
1102 (
errmsg(
"ending log output to stderr"),
1103 errhint(
"Future log output will go to log destination \"%s\".",
1114 (
errmsg(
"starting %s", PG_VERSION_STR)));
1142 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1143 errmsg(
"invalid list syntax in parameter \"%s\"",
1144 "listen_addresses")));
1147 foreach(l, elemlist)
1149 char *curhost = (
char *)
lfirst(l);
1151 if (strcmp(curhost,
"*") == 0)
1160 ListenSocket, MAXLISTEN);
1166 if (!listen_addr_saved)
1169 listen_addr_saved =
true;
1174 (
errmsg(
"could not create listen socket for \"%s\"",
1178 if (!success && elemlist !=
NIL)
1180 (
errmsg(
"could not create any TCP/IP sockets")));
1190 DNSServiceErrorType err;
1198 err = DNSServiceRegister(&bonjour_sdref,
1202 "_postgresql._tcp.",
1210 if (err != kDNSServiceErr_NoError)
1212 (
errmsg(
"DNSServiceRegister() failed: error code %ld",
1225 #ifdef HAVE_UNIX_SOCKETS 1241 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1242 errmsg(
"invalid list syntax in parameter \"%s\"",
1243 "unix_socket_directories")));
1246 foreach(l, elemlist)
1248 char *socketdir = (
char *)
lfirst(l);
1264 (
errmsg(
"could not create Unix-domain socket in directory \"%s\"",
1268 if (!success && elemlist !=
NIL)
1270 (
errmsg(
"could not create any Unix-domain sockets")));
1282 (
errmsg(
"no socket created for listening")));
1289 if (!listen_addr_saved)
1313 write_stderr(
"%s: could not change permissions of external PID file \"%s\": %s\n",
1317 write_stderr(
"%s: could not write external PID file \"%s\": %s\n",
1350 (
errmsg(
"could not load pg_hba.conf")));
1362 #ifdef HAVE_PTHREAD_IS_THREADED_NP 1373 if (pthread_is_threaded_np() != 0)
1375 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1376 errmsg(
"postmaster became multithreaded during startup"),
1377 errhint(
"Set the LC_ALL environment variable to a valid locale.")));
1472 (
errmsg(
"%s: could not locate my own executable path", argv0)));
1477 postgres_exec_path) < 0)
1479 (
errmsg(
"%s: could not locate matching postgres executable",
1500 errmsg(
"could not open directory \"%s\": %m",
1502 errhint(
"This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
1529 write_stderr(
"%s: could not find the database system\n" 1530 "Expected to find it in the directory \"%s\",\n" 1531 "but could not open file \"%s\": %s\n",
1564 timeout->tv_sec =
Max(timeout->tv_sec, 0);
1565 timeout->tv_usec = 0;
1569 timeout->tv_sec = 60;
1570 timeout->tv_usec = 0;
1577 timeout->tv_sec = 0;
1578 timeout->tv_usec = 0;
1611 if (next_wakeup == 0 || this_wakeup < next_wakeup)
1612 next_wakeup = this_wakeup;
1616 if (next_wakeup != 0)
1623 timeout->tv_sec = secs;
1624 timeout->tv_usec = microsecs;
1627 if (timeout->tv_sec > 60)
1629 timeout->tv_sec = 60;
1630 timeout->tv_usec = 0;
1635 timeout->tv_sec = 60;
1636 timeout->tv_usec = 0;
1650 time_t last_lockfile_recheck_time,
1653 last_lockfile_recheck_time = last_touch_time = time(NULL);
1673 memcpy((
char *) &rmask, (
char *) &readmask,
sizeof(fd_set));
1687 struct timeval timeout;
1694 selres =
select(nSockets, &rmask, NULL, NULL, &timeout);
1706 errmsg(
"select() failed in postmaster: %m")));
1809 #ifdef HAVE_PTHREAD_IS_THREADED_NP 1815 Assert(pthread_is_threaded_np() == 0);
1842 (
errmsg(
"issuing SIGKILL to recalcitrant children")));
1863 (
errmsg(
"performing immediate shutdown because data directory lock file is invalid")));
1866 last_lockfile_recheck_time =
now;
1878 last_touch_time =
now;
1963 if (!ssl_done && !gss_done)
1965 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
1966 errmsg(
"incomplete startup packet")));
1977 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
1978 errmsg(
"invalid length of startup packet")));
1996 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
1997 errmsg(
"incomplete startup packet")));
2030 if (
send(port->
sock, &SSLok, 1, 0) != 1)
2036 errmsg(
"failed to send SSL negotiation response: %m")));
2062 while (
send(port->
sock, &GSSok, 1, 0) != 1)
2068 errmsg(
"failed to send GSSAPI negotiation response: %m")));
2097 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2098 errmsg(
"unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
2117 List *unrecognized_protocol_options =
NIL;
2126 while (offset < len)
2128 char *nameptr = ((
char *) buf) + offset;
2132 if (*nameptr ==
'\0')
2134 valoffset = offset + strlen(nameptr) + 1;
2135 if (valoffset >= len)
2137 valptr = ((
char *) buf) + valoffset;
2139 if (strcmp(nameptr,
"database") == 0)
2141 else if (strcmp(nameptr,
"user") == 0)
2143 else if (strcmp(nameptr,
"options") == 0)
2145 else if (strcmp(nameptr,
"replication") == 0)
2154 if (strcmp(valptr,
"database") == 0)
2161 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2162 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
2165 errhint(
"Valid values are: \"false\", 0, \"true\", 1, \"database\".")));
2167 else if (strncmp(nameptr,
"_pq_.", 5) == 0)
2174 unrecognized_protocol_options =
2191 if (strcmp(nameptr,
"application_name") == 0)
2193 char *tmp_app_name =
pstrdup(valptr);
2200 offset = valoffset + strlen(valptr) + 1;
2207 if (offset != len - 1)
2209 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2210 errmsg(
"invalid startup packet layout: expected terminator as last byte")));
2219 unrecognized_protocol_options !=
NIL)
2247 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
2248 errmsg(
"no PostgreSQL user name specified in startup packet")));
2312 errmsg(
"the database system is starting up")));
2317 errmsg(
"the database system is shutting down")));
2322 errmsg(
"the database system is in recovery mode")));
2326 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
2327 errmsg(
"sorry, too many clients already")));
2361 foreach(lc, unrecognized_protocol_options)
2378 int32 cancelAuthCode;
2381 #ifndef EXEC_BACKEND 2395 #ifndef EXEC_BACKEND 2402 bp = (
Backend *) &ShmemBackendArray[i];
2404 if (bp->
pid == backendPID)
2410 (
errmsg_internal(
"processing cancel request: sending SIGINT to process %d",
2417 (
errmsg(
"wrong key in cancel request for process %d",
2421 #ifndef EXEC_BACKEND 2429 (
errmsg(
"PID %d in cancel request did not match any process",
2511 (
errcode(ERRCODE_OUT_OF_MEMORY),
2512 errmsg(
"out of memory")));
2566 errmsg_internal(
"could not close postmaster death monitoring pipe in child process: %m")));
2605 close(DNSServiceRefSockFD(bonjour_sdref));
2669 int save_errno = errno;
2682 (
errmsg(
"received SIGHUP, reloading configuration files")));
2708 (
errmsg(
"%s was not reloaded",
"pg_hba.conf")));
2712 (
errmsg(
"%s was not reloaded",
"pg_ident.conf")));
2722 (
errmsg(
"SSL configuration was not reloaded")));
2751 int save_errno = errno;
2763 postgres_signal_arg)));
2765 switch (postgres_signal_arg)
2778 (
errmsg(
"received smart shutdown request")));
2783 sd_notify(0,
"STOPPING=1");
2824 (
errmsg(
"received fast shutdown request")));
2829 sd_notify(0,
"STOPPING=1");
2842 (
errmsg(
"aborting any active transactions")));
2866 (
errmsg(
"received immediate shutdown request")));
2871 sd_notify(0,
"STOPPING=1");
2903 int save_errno = errno;
2918 while ((pid = waitpid(-1, &exitstatus, WNOHANG)) > 0)
2943 (
errmsg(
"shutdown at recovery target")));
2964 (
errmsg(
"aborting startup due to startup process failure")));
2997 _(
"startup process"));
3039 (
errmsg(
"database system is ready to accept connections")));
3044 sd_notify(0,
"READY=1");
3060 _(
"background writer process"));
3114 _(
"checkpointer process"));
3130 _(
"WAL writer process"));
3145 _(
"WAL receiver process"));
3160 _(
"autovacuum launcher process"));
3265 if (exitstatus == ERROR_WAIT_NO_CHILDREN)
3332 namebuf, pid, exitstatus);
3371 if (exitstatus == ERROR_WAIT_NO_CHILDREN)
3402 ShmemBackendArrayRemove(bp);
3452 (
errmsg(
"terminating any other active server processes")));
3497 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3518 ShmemBackendArrayRemove(bp);
3549 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3566 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3579 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3591 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3603 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3615 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3627 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3694 char activity_buffer[1024];
3695 const char *activity = NULL;
3700 sizeof(activity_buffer));
3708 (
errmsg(
"%s (PID %d) exited with exit code %d",
3710 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3719 (
errmsg(
"%s (PID %d) was terminated by exception 0x%X",
3720 procname, pid,
WTERMSIG(exitstatus)),
3721 errhint(
"See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
3722 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3729 (
errmsg(
"%s (PID %d) was terminated by signal %d: %s",
3730 procname, pid,
WTERMSIG(exitstatus),
3732 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3741 (
errmsg(
"%s (PID %d) exited with unrecognized status %d",
3742 procname, pid, exitstatus),
3743 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3996 (
errmsg(
"all server processes terminated; reinitializing")));
4037 if (
kill(pid, signal) < 0)
4038 elog(
DEBUG3,
"kill(%ld,%d) failed: %m", (
long) pid, signal);
4047 if (
kill(-pid, signal) < 0)
4048 elog(
DEBUG3,
"kill(%ld,%d) failed: %m", (
long) (-pid), signal);
4093 signal, (
int) bp->
pid)));
4151 (
errcode(ERRCODE_OUT_OF_MEMORY),
4152 errmsg(
"out of memory")));
4165 (
errcode(ERRCODE_INTERNAL_ERROR),
4166 errmsg(
"could not generate random cancel key")));
4189 pid = backend_forkexec(port);
4213 int save_errno = errno;
4220 (
errmsg(
"could not fork new process for connection: %m")));
4228 (
int) pid, (
int) port->
sock)));
4240 ShmemBackendArrayAdd(bn);
4261 snprintf(buffer,
sizeof(buffer),
"E%s%s\n",
4262 _(
"could not fork new process for connection: "),
4272 rc =
send(port->
sock, buffer, strlen(buffer) + 1, 0);
4273 }
while (rc < 0 && errno ==
EINTR);
4346 remote_host[0] =
'\0';
4347 remote_port[0] =
'\0';
4349 remote_host,
sizeof(remote_host),
4350 remote_port,
sizeof(remote_port),
4368 (
errmsg(
"connection received: host=%s port=%s",
4373 (
errmsg(
"connection received: host=%s",
4390 strspn(remote_host,
"0123456789.") < strlen(remote_host) &&
4391 strspn(remote_host,
"0123456789ABCDEFabcdef:") < strlen(remote_host))
4503 postmaster_forkexec(
int argc,
char *argv[])
4508 memset(&port, 0,
sizeof(port));
4509 return internal_forkexec(argc, argv, &port);
4527 av[ac++] =
"postgres";
4528 av[ac++] =
"--forkbackend";
4534 return internal_forkexec(ac, av, port);
4546 internal_forkexec(
int argc,
char *argv[],
Port *port)
4548 static unsigned long tmpBackendFileNum = 0;
4551 BackendParameters param;
4554 if (!save_backend_variables(¶m, port))
4577 errmsg(
"could not create file \"%s\": %m",
4583 if (fwrite(¶m,
sizeof(param), 1, fp) != 1)
4587 errmsg(
"could not write to file \"%s\": %m", tmpfilename)));
4597 errmsg(
"could not write to file \"%s\": %m", tmpfilename)));
4603 Assert(argv[argc] == NULL);
4604 Assert(strncmp(argv[1],
"--fork", 6) == 0);
4608 argv[2] = tmpfilename;
4613 if (execv(postgres_exec_path, argv) < 0)
4616 (
errmsg(
"could not execute server process \"%s\": %m",
4617 postgres_exec_path)));
4638 internal_forkexec(
int argc,
char *argv[],
Port *port)
4640 int retry_count = 0;
4642 PROCESS_INFORMATION pi;
4647 BackendParameters *param;
4648 SECURITY_ATTRIBUTES
sa;
4649 char paramHandleStr[32];
4650 win32_deadchild_waitinfo *childinfo;
4654 Assert(argv[argc] == NULL);
4655 Assert(strncmp(argv[1],
"--fork", 6) == 0);
4662 ZeroMemory(&sa,
sizeof(sa));
4663 sa.nLength =
sizeof(sa);
4664 sa.bInheritHandle = TRUE;
4665 paramHandle = CreateFileMapping(INVALID_HANDLE_VALUE,
4669 sizeof(BackendParameters),
4671 if (paramHandle == INVALID_HANDLE_VALUE)
4674 (
errmsg(
"could not create backend parameter file mapping: error code %lu",
4679 param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0,
sizeof(BackendParameters));
4683 (
errmsg(
"could not map backend parameter memory: error code %lu",
4685 CloseHandle(paramHandle);
4691 sprintf(paramHandleStr,
"%llu", (LONG_PTR) paramHandle);
4693 sprintf(paramHandleStr,
"%lu", (DWORD) paramHandle);
4695 argv[2] = paramHandleStr;
4698 cmdLine[
sizeof(cmdLine) - 1] =
'\0';
4699 cmdLine[
sizeof(cmdLine) - 2] =
'\0';
4700 snprintf(cmdLine,
sizeof(cmdLine) - 1,
"\"%s\"", postgres_exec_path);
4702 while (argv[++i] != NULL)
4704 j = strlen(cmdLine);
4705 snprintf(cmdLine + j,
sizeof(cmdLine) - 1 - j,
" \"%s\"", argv[i]);
4707 if (cmdLine[
sizeof(cmdLine) - 2] !=
'\0')
4710 (
errmsg(
"subprocess command line too long")));
4711 UnmapViewOfFile(param);
4712 CloseHandle(paramHandle);
4716 memset(&pi, 0,
sizeof(pi));
4717 memset(&si, 0,
sizeof(si));
4724 if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
4725 NULL, NULL, &si, &pi))
4728 (
errmsg(
"CreateProcess() call failed: %m (error code %lu)",
4730 UnmapViewOfFile(param);
4731 CloseHandle(paramHandle);
4735 if (!save_backend_variables(param, port, pi.hProcess, pi.dwProcessId))
4741 if (!TerminateProcess(pi.hProcess, 255))
4743 (
errmsg_internal(
"could not terminate unstarted process: error code %lu",
4745 CloseHandle(pi.hProcess);
4746 CloseHandle(pi.hThread);
4747 UnmapViewOfFile(param);
4748 CloseHandle(paramHandle);
4753 if (!UnmapViewOfFile(param))
4755 (
errmsg(
"could not unmap view of backend parameter file: error code %lu",
4757 if (!CloseHandle(paramHandle))
4759 (
errmsg(
"could not close handle to backend parameter file: error code %lu",
4772 if (!TerminateProcess(pi.hProcess, 255))
4774 (
errmsg_internal(
"could not terminate process that failed to reserve memory: error code %lu",
4776 CloseHandle(pi.hProcess);
4777 CloseHandle(pi.hThread);
4778 if (++retry_count < 100)
4781 (
errmsg(
"giving up after too many tries to reserve shared memory"),
4782 errhint(
"This might be caused by ASLR or antivirus software.")));
4791 if (ResumeThread(pi.hThread) == -1)
4793 if (!TerminateProcess(pi.hProcess, 255))
4796 (
errmsg_internal(
"could not terminate unstartable process: error code %lu",
4798 CloseHandle(pi.hProcess);
4799 CloseHandle(pi.hThread);
4802 CloseHandle(pi.hProcess);
4803 CloseHandle(pi.hThread);
4805 (
errmsg_internal(
"could not resume thread of unstarted process: error code %lu",
4818 childinfo =
malloc(
sizeof(win32_deadchild_waitinfo));
4821 (
errcode(ERRCODE_OUT_OF_MEMORY),
4822 errmsg(
"out of memory")));
4824 childinfo->procHandle = pi.hProcess;
4825 childinfo->procId = pi.dwProcessId;
4827 if (!RegisterWaitForSingleObject(&childinfo->waitHandle,
4829 pgwin32_deadchild_callback,
4832 WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD))
4834 (
errmsg_internal(
"could not register process for wait: error code %lu",
4839 CloseHandle(pi.hThread);
4841 return pi.dwProcessId;
4858 SubPostmasterMain(
int argc,
char *argv[])
4871 elog(
FATAL,
"invalid subpostmaster invocation");
4874 memset(&port, 0,
sizeof(
Port));
4875 read_backend_variables(argv[2], &port);
4908 if (strcmp(argv[1],
"--forkbackend") == 0 ||
4909 strcmp(argv[1],
"--forkavlauncher") == 0 ||
4910 strcmp(argv[1],
"--forkavworker") == 0 ||
4911 strcmp(argv[1],
"--forkboot") == 0 ||
4912 strncmp(argv[1],
"--forkbgworker=", 15) == 0)
4918 if (strcmp(argv[1],
"--forkavlauncher") == 0)
4919 AutovacuumLauncherIAm();
4920 if (strcmp(argv[1],
"--forkavworker") == 0)
4921 AutovacuumWorkerIAm();
4924 read_nondefault_variables();
4949 if (strcmp(argv[1],
"--forkbackend") == 0)
4972 (
errmsg(
"SSL configuration could not be loaded in child process")));
4999 if (strcmp(argv[1],
"--forkboot") == 0)
5012 if (strcmp(argv[1],
"--forkavlauncher") == 0)
5025 if (strcmp(argv[1],
"--forkavworker") == 0)
5038 if (strncmp(argv[1],
"--forkbgworker=", 15) == 0)
5055 shmem_slot = atoi(argv[1] + 15);
5056 MyBgworkerEntry = BackgroundWorkerEntry(shmem_slot);
5060 if (strcmp(argv[1],
"--forkarch") == 0)
5066 if (strcmp(argv[1],
"--forkcol") == 0)
5072 if (strcmp(argv[1],
"--forklog") == 0)
5092 #ifdef HAVE_PTHREAD_IS_THREADED_NP 5100 if (pthread_is_threaded_np() != 0)
5102 (
errcode(ERRCODE_INTERNAL_ERROR),
5104 errdetail(
"Please report this to <%s>.", PACKAGE_BUGREPORT)));
5125 int save_errno = errno;
5174 sd_notify(0,
"READY=1");
5191 (
errmsg(
"database system is ready to accept read only connections")));
5196 sd_notify(0,
"READY=1");
5421 av[ac++] =
"postgres";
5424 av[ac++] =
"--forkboot";
5428 snprintf(typebuf,
sizeof(typebuf),
"-x%d", type);
5435 pid = postmaster_forkexec(ac, av);
5459 int save_errno = errno;
5466 (
errmsg(
"could not fork startup process: %m")));
5470 (
errmsg(
"could not fork background writer process: %m")));
5474 (
errmsg(
"could not fork checkpointer process: %m")));
5478 (
errmsg(
"could not fork WAL writer process: %m")));
5482 (
errmsg(
"could not fork WAL receiver process: %m")));
5486 (
errmsg(
"could not fork process: %m")));
5537 (
errcode(ERRCODE_INTERNAL_ERROR),
5538 errmsg(
"could not generate random cancel key")));
5558 ShmemBackendArrayAdd(bn);
5573 (
errcode(ERRCODE_OUT_OF_MEMORY),
5574 errmsg(
"out of memory")));
5630 #define OPTS_FILE "postmaster.opts" 5632 if ((fp = fopen(
OPTS_FILE,
"w")) == NULL)
5640 fprintf(fp,
"%s", fullprogname);
5641 for (i = 1; i < argc; i++)
5642 fprintf(fp,
" \"%s\"", argv[i]);
5686 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5687 errmsg(
"database connection requirement not indicated during registration")));
5694 (
errmsg(
"invalid processing mode in background worker")));
5709 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5710 errmsg(
"database connection requirement not indicated during registration")));
5717 (
errmsg(
"invalid processing mode in background worker")));
5738 bgworker_forkexec(
int shmem_slot)
5746 av[ac++] =
"postgres";
5753 return postmaster_forkexec(ac, av);
5790 (
errmsg(
"starting background worker process \"%s\"",
5794 switch ((worker_pid = bgworker_forkexec(rw->
rw_shmem_slot)))
5802 (
errmsg(
"could not fork worker process: %m")));
5812 #ifndef EXEC_BACKEND