85 #include <systemd/sd-daemon.h>
88 #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;
271 #define SmartShutdown 1
272 #define FastShutdown 2
273 #define ImmediateShutdown 3
352 #define SIGKILL_CHILDREN_AFTER_SECS 5
387 static bool LoadedSSL =
false;
391 static DNSServiceRef bonjour_sdref = NULL;
416 static void HandleChildCrash(
int pid,
int exitstatus,
const char *procname);
418 int pid,
int exitstatus);
436 #define SignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL)
441 static bool CreateOptsFile(
int argc,
char *argv[],
char *fullprogname);
453 #define PgArchStartupAllowed() \
454 (((XLogArchivingActive() && pmState == PM_RUN) || \
455 (XLogArchivingAlways() && \
456 (pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY))) && \
464 static pid_t waitpid(pid_t pid,
int *exitstatus,
int options);
465 static void WINAPI pgwin32_deadchild_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
467 static HANDLE win32ChildQueue;
474 } win32_deadchild_waitinfo;
477 static pid_t backend_forkexec(
Port *
port);
478 static pid_t internal_forkexec(
int argc,
char *argv[],
Port *
port);
486 WSAPROTOCOL_INFO wsainfo;
489 typedef int InheritableSocket;
498 InheritableSocket portsocket;
512 #ifndef HAVE_SPINLOCKS
533 HANDLE PostmasterHandle;
534 HANDLE initial_signal_pipe;
544 static void read_backend_variables(
char *
id,
Port *
port);
545 static void restore_backend_variables(BackendParameters *param,
Port *
port);
548 static bool save_backend_variables(BackendParameters *param,
Port *
port);
550 static bool save_backend_variables(BackendParameters *param,
Port *
port,
551 HANDLE childProcess, pid_t childPid);
554 static void ShmemBackendArrayAdd(
Backend *bn);
555 static void ShmemBackendArrayRemove(
Backend *bn);
558 #define StartupDataBase() StartChildProcess(StartupProcess)
559 #define StartArchiver() StartChildProcess(ArchiverProcess)
560 #define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
561 #define StartCheckpointer() StartChildProcess(CheckpointerProcess)
562 #define StartWalWriter() StartChildProcess(WalWriterProcess)
563 #define StartWalReceiver() StartChildProcess(WalReceiverProcess)
566 #define EXIT_STATUS_0(st) ((st) == 0)
567 #define EXIT_STATUS_1(st) (WIFEXITED(st) && WEXITSTATUS(st) == 1)
568 #define EXIT_STATUS_3(st) (WIFEXITED(st) && WEXITSTATUS(st) == 3)
578 HANDLE PostmasterHandle;
590 bool listen_addr_saved =
false;
592 char *output_config_variable = NULL;
641 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
691 while ((opt =
getopt(argc, argv,
"B:bC:c:D:d:EeFf:h:ijk:lN:OPp:r:S:sTt:W:-:")) != -1)
705 output_config_variable = strdup(
optarg);
719 (
errcode(ERRCODE_SYNTAX_ERROR),
720 errmsg(
"--%s requires a value",
724 (
errcode(ERRCODE_SYNTAX_ERROR),
725 errmsg(
"-c %s requires a value",
758 write_stderr(
"%s: invalid argument for option -f: \"%s\"\n",
831 write_stderr(
"%s: invalid argument for option -t: \"%s\"\n",
843 write_stderr(
"Try \"%s --help\" for more information.\n",
856 write_stderr(
"Try \"%s --help\" for more information.\n",
868 if (output_config_variable != NULL)
893 puts(config_val ? config_val :
"");
922 write_stderr(
"%s: superuser_reserved_connections (%d) plus reserved_connections (%d) must be less than max_connections (%d)\n",
930 (
errmsg(
"WAL archival cannot be enabled when wal_level is \"minimal\"")));
933 (
errmsg(
"WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
950 #ifdef HAVE_INT_OPTRESET
1055 if (output_config_variable != NULL)
1060 puts(config_val ? config_val :
"");
1095 win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
1096 if (win32ChildQueue == NULL)
1098 (
errmsg(
"could not create I/O completion port for child queue")));
1142 errmsg(
"could not remove file \"%s\": %m",
1174 (
errmsg(
"ending log output to stderr"),
1175 errhint(
"Future log output will go to log destination \"%s\".",
1186 (
errmsg(
"starting %s", PG_VERSION_STR)));
1206 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1207 errmsg(
"invalid list syntax in parameter \"%s\"",
1208 "listen_addresses")));
1211 foreach(l, elemlist)
1213 char *curhost = (
char *)
lfirst(l);
1215 if (strcmp(curhost,
"*") == 0)
1230 if (!listen_addr_saved)
1233 listen_addr_saved =
true;
1238 (
errmsg(
"could not create listen socket for \"%s\"",
1244 (
errmsg(
"could not create any TCP/IP sockets")));
1254 DNSServiceErrorType
err;
1262 err = DNSServiceRegister(&bonjour_sdref,
1266 "_postgresql._tcp.",
1274 if (
err != kDNSServiceErr_NoError)
1276 (
errmsg(
"DNSServiceRegister() failed: error code %ld",
1304 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1305 errmsg(
"invalid list syntax in parameter \"%s\"",
1306 "unix_socket_directories")));
1309 foreach(l, elemlist)
1311 char *socketdir = (
char *)
lfirst(l);
1327 (
errmsg(
"could not create Unix-domain socket in directory \"%s\"",
1333 (
errmsg(
"could not create any Unix-domain sockets")));
1344 (
errmsg(
"no socket created for listening")));
1351 if (!listen_addr_saved)
1375 write_stderr(
"%s: could not change permissions of external PID file \"%s\": %s\n",
1379 write_stderr(
"%s: could not write external PID file \"%s\": %s\n",
1419 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1430 if (pthread_is_threaded_np() != 0)
1432 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1433 errmsg(
"postmaster became multithreaded during startup"),
1434 errhint(
"Set the LC_ALL environment variable to a valid locale.")));
1535 (
errmsg(
"%s: could not locate my own executable path",
argv0)));
1540 postgres_exec_path) < 0)
1542 (
errmsg(
"%s: could not locate matching postgres executable",
1563 errmsg(
"could not open directory \"%s\": %m",
1565 errhint(
"This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
1592 write_stderr(
"%s: could not find the database system\n"
1593 "Expected to find it in the directory \"%s\",\n"
1594 "but could not open file \"%s\": %s\n",
1630 return Max(seconds * 1000, 0);
1668 if (next_wakeup == 0 || this_wakeup < next_wakeup)
1669 next_wakeup = this_wakeup;
1673 if (next_wakeup != 0)
1680 return Min(60 * 1000, ms);
1706 if (accept_connections)
1717 if (accept_connections)
1719 for (
int i = 0;
i < nsockets;
i++)
1731 time_t last_lockfile_recheck_time,
1737 last_lockfile_recheck_time = last_touch_time = time(NULL);
1753 for (
int i = 0;
i < nevents;
i++)
1854 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1860 Assert(pthread_is_threaded_np() == 0);
1889 (
errmsg(
"issuing %s to recalcitrant children",
1911 (
errmsg(
"performing immediate shutdown because data directory lock file is invalid")));
1914 last_lockfile_recheck_time =
now;
1926 last_touch_time =
now;
1983 if (!ssl_done && !gss_done)
1985 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
1986 errmsg(
"incomplete startup packet")));
1997 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
1998 errmsg(
"invalid length of startup packet")));
2013 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2014 errmsg(
"incomplete startup packet")));
2030 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2031 errmsg(
"invalid length of startup packet")));
2045 if (!LoadedSSL ||
port->laddr.addr.ss_family == AF_UNIX)
2054 if (
send(
port->sock, &SSLok, 1, 0) != 1)
2060 errmsg(
"failed to send SSL negotiation response: %m")));
2077 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2078 errmsg(
"received unencrypted data after SSL request"),
2079 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
2094 if (
port->laddr.addr.ss_family != AF_UNIX)
2098 while (
send(
port->sock, &GSSok, 1, 0) != 1)
2104 errmsg(
"failed to send GSSAPI negotiation response: %m")));
2121 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2122 errmsg(
"received unencrypted data after GSSAPI encryption request"),
2123 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
2145 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2146 errmsg(
"unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
2165 List *unrecognized_protocol_options =
NIL;
2174 while (offset <
len)
2176 char *nameptr =
buf + offset;
2180 if (*nameptr ==
'\0')
2182 valoffset = offset + strlen(nameptr) + 1;
2183 if (valoffset >=
len)
2185 valptr =
buf + valoffset;
2187 if (strcmp(nameptr,
"database") == 0)
2189 else if (strcmp(nameptr,
"user") == 0)
2191 else if (strcmp(nameptr,
"options") == 0)
2193 else if (strcmp(nameptr,
"replication") == 0)
2202 if (strcmp(valptr,
"database") == 0)
2209 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2210 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
2213 errhint(
"Valid values are: \"false\", 0, \"true\", 1, \"database\".")));
2215 else if (strncmp(nameptr,
"_pq_.", 5) == 0)
2222 unrecognized_protocol_options =
2239 if (strcmp(nameptr,
"application_name") == 0)
2244 offset = valoffset + strlen(valptr) + 1;
2251 if (offset !=
len - 1)
2253 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2254 errmsg(
"invalid startup packet layout: expected terminator as last byte")));
2263 unrecognized_protocol_options !=
NIL)
2268 if (
port->user_name == NULL ||
port->user_name[0] ==
'\0')
2270 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
2271 errmsg(
"no PostgreSQL user name specified in startup packet")));
2274 if (
port->database_name == NULL ||
port->database_name[0] ==
'\0')
2291 port->database_name[0] =
'\0';
2303 switch (
port->canAcceptConnections)
2308 errmsg(
"the database system is starting up")));
2314 errmsg(
"the database system is not yet accepting connections"),
2315 errdetail(
"Consistent recovery state has not been yet reached.")));
2319 errmsg(
"the database system is not accepting connections"),
2320 errdetail(
"Hot standby mode is disabled.")));
2325 errmsg(
"the database system is shutting down")));
2330 errmsg(
"the database system is in recovery mode")));
2334 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
2335 errmsg(
"sorry, too many clients already")));
2366 foreach(lc, unrecognized_protocol_options)
2383 int32 cancelAuthCode;
2386 #ifndef EXEC_BACKEND
2400 #ifndef EXEC_BACKEND
2407 bp = (
Backend *) &ShmemBackendArray[
i];
2409 if (bp->
pid == backendPID)
2415 (
errmsg_internal(
"processing cancel request: sending SIGINT to process %d",
2422 (
errmsg(
"wrong key in cancel request for process %d",
2426 #ifndef EXEC_BACKEND
2434 (
errmsg(
"PID %d in cancel request did not match any process",
2508 (
errcode(ERRCODE_OUT_OF_MEMORY),
2509 errmsg(
"out of memory")));
2568 errmsg_internal(
"could not close postmaster death monitoring pipe in child process: %m")));
2581 #ifndef EXEC_BACKEND
2612 close(DNSServiceRefSockFD(bonjour_sdref));
2668 int save_errno = errno;
2682 int save_errno = errno;
2704 (
errmsg(
"received SIGHUP, reloading configuration files")));
2742 (
errmsg(
"SSL configuration was not reloaded")));
2765 int save_errno = errno;
2767 switch (postgres_signal_arg)
2832 (
errmsg(
"received smart shutdown request")));
2837 sd_notify(0,
"STOPPING=1");
2873 (
errmsg(
"received fast shutdown request")));
2878 sd_notify(0,
"STOPPING=1");
2891 (
errmsg(
"aborting any active transactions")));
2915 (
errmsg(
"received immediate shutdown request")));
2920 sd_notify(0,
"STOPPING=1");
2944 int save_errno = errno;
2966 while ((pid = waitpid(-1, &exitstatus, WNOHANG)) > 0)
2991 (
errmsg(
"shutdown at recovery target")));
3012 (
errmsg(
"aborting startup due to startup process failure")));
3045 _(
"startup process"));
3085 (
errmsg(
"database system is ready to accept connections")));
3090 sd_notify(0,
"READY=1");
3106 _(
"background writer process"));
3153 _(
"checkpointer process"));
3169 _(
"WAL writer process"));
3184 _(
"WAL receiver process"));
3199 _(
"autovacuum launcher process"));
3217 _(
"archiver process"));
3283 if (exitstatus == ERROR_WAIT_NO_CHILDREN)
3345 namebuf, pid, exitstatus);
3384 if (exitstatus == ERROR_WAIT_NO_CHILDREN)
3415 ShmemBackendArrayRemove(bp);
3465 (
errmsg(
"terminating any other active server processes")));
3520 ShmemBackendArrayRemove(bp);
3626 char activity_buffer[1024];
3627 const char *activity = NULL;
3632 sizeof(activity_buffer));
3640 (
errmsg(
"%s (PID %d) exited with exit code %d",
3642 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3651 (
errmsg(
"%s (PID %d) was terminated by exception 0x%X",
3652 procname, pid,
WTERMSIG(exitstatus)),
3653 errhint(
"See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
3654 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3661 (
errmsg(
"%s (PID %d) was terminated by signal %d: %s",
3662 procname, pid,
WTERMSIG(exitstatus),
3664 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3673 (
errmsg(
"%s (PID %d) exited with unrecognized status %d",
3674 procname, pid, exitstatus),
3675 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3907 (
errmsg(
"shutting down due to startup process failure")));
3913 (
errmsg(
"shutting down because restart_after_crash is off")));
3925 (
errmsg(
"all server processes terminated; reinitializing")));
3974 if (
kill(pid, signal) < 0)
3975 elog(
DEBUG3,
"kill(%ld,%d) failed: %m", (
long) pid, signal);
3984 if (
kill(-pid, signal) < 0)
3985 elog(
DEBUG3,
"kill(%ld,%d) failed: %m", (
long) (-pid), signal);
4019 bool signaled =
false;
4048 signal, (
int) bp->
pid)));
4104 (
errcode(ERRCODE_OUT_OF_MEMORY),
4105 errmsg(
"out of memory")));
4118 (
errcode(ERRCODE_INTERNAL_ERROR),
4119 errmsg(
"could not generate random cancel key")));
4141 pid = backend_forkexec(
port);
4174 int save_errno = errno;
4181 (
errmsg(
"could not fork new process for connection: %m")));
4189 (
int) pid, (
int)
port->sock)));
4201 ShmemBackendArrayAdd(bn);
4222 snprintf(buffer,
sizeof(buffer),
"E%s%s\n",
4223 _(
"could not fork new process for connection: "),
4233 rc =
send(
port->sock, buffer, strlen(buffer) + 1, 0);
4234 }
while (rc < 0 && errno ==
EINTR);
4255 char remote_host[NI_MAXHOST];
4256 char remote_port[NI_MAXSERV];
4279 port->remote_host =
"";
4280 port->remote_port =
"";
4307 remote_host[0] =
'\0';
4308 remote_port[0] =
'\0';
4310 remote_host,
sizeof(remote_host),
4311 remote_port,
sizeof(remote_port),
4312 (
log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV)) != 0)
4315 gai_strerror(ret))));
4321 port->remote_host = strdup(remote_host);
4322 port->remote_port = strdup(remote_port);
4329 (
errmsg(
"connection received: host=%s port=%s",
4334 (
errmsg(
"connection received: host=%s",
4351 strspn(remote_host,
"0123456789.") < strlen(remote_host) &&
4352 strspn(remote_host,
"0123456789ABCDEFabcdef:") < strlen(remote_host))
4353 port->remote_hostname = strdup(remote_host);
4383 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
4411 if (
port->database_name[0] !=
'\0')
4414 if (
port->remote_port[0] !=
'\0')
4458 postmaster_forkexec(
int argc,
char *argv[])
4464 return internal_forkexec(argc, argv, &
port);
4482 av[ac++] =
"postgres";
4483 av[ac++] =
"--forkbackend";
4489 return internal_forkexec(ac,
av,
port);
4501 internal_forkexec(
int argc,
char *argv[],
Port *
port)
4503 static unsigned long tmpBackendFileNum = 0;
4506 BackendParameters param;
4509 if (!save_backend_variables(¶m,
port))
4532 errmsg(
"could not create file \"%s\": %m",
4538 if (fwrite(¶m,
sizeof(param), 1, fp) != 1)
4542 errmsg(
"could not write to file \"%s\": %m", tmpfilename)));
4552 errmsg(
"could not write to file \"%s\": %m", tmpfilename)));
4558 Assert(argv[argc] == NULL);
4559 Assert(strncmp(argv[1],
"--fork", 6) == 0);
4563 argv[2] = tmpfilename;
4568 if (execv(postgres_exec_path, argv) < 0)
4571 (
errmsg(
"could not execute server process \"%s\": %m",
4572 postgres_exec_path)));
4593 internal_forkexec(
int argc,
char *argv[],
Port *
port)
4595 int retry_count = 0;
4597 PROCESS_INFORMATION pi;
4602 BackendParameters *param;
4603 SECURITY_ATTRIBUTES
sa;
4604 char paramHandleStr[32];
4605 win32_deadchild_waitinfo *childinfo;
4609 Assert(argv[argc] == NULL);
4610 Assert(strncmp(argv[1],
"--fork", 6) == 0);
4617 ZeroMemory(&
sa,
sizeof(
sa));
4618 sa.nLength =
sizeof(
sa);
4619 sa.bInheritHandle = TRUE;
4620 paramHandle = CreateFileMapping(INVALID_HANDLE_VALUE,
4624 sizeof(BackendParameters),
4626 if (paramHandle == INVALID_HANDLE_VALUE)
4629 (
errmsg(
"could not create backend parameter file mapping: error code %lu",
4634 param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0,
sizeof(BackendParameters));
4638 (
errmsg(
"could not map backend parameter memory: error code %lu",
4640 CloseHandle(paramHandle);
4646 sprintf(paramHandleStr,
"%llu", (LONG_PTR) paramHandle);
4648 sprintf(paramHandleStr,
"%lu", (DWORD) paramHandle);
4650 argv[2] = paramHandleStr;
4653 cmdLine[
sizeof(cmdLine) - 1] =
'\0';
4654 cmdLine[
sizeof(cmdLine) - 2] =
'\0';
4655 snprintf(cmdLine,
sizeof(cmdLine) - 1,
"\"%s\"", postgres_exec_path);
4657 while (argv[++
i] != NULL)
4659 j = strlen(cmdLine);
4660 snprintf(cmdLine +
j,
sizeof(cmdLine) - 1 -
j,
" \"%s\"", argv[
i]);
4662 if (cmdLine[
sizeof(cmdLine) - 2] !=
'\0')
4665 (
errmsg(
"subprocess command line too long")));
4666 UnmapViewOfFile(param);
4667 CloseHandle(paramHandle);
4671 memset(&pi, 0,
sizeof(pi));
4672 memset(&si, 0,
sizeof(si));
4679 if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
4680 NULL, NULL, &si, &pi))
4683 (
errmsg(
"CreateProcess() call failed: %m (error code %lu)",
4685 UnmapViewOfFile(param);
4686 CloseHandle(paramHandle);
4690 if (!save_backend_variables(param,
port, pi.hProcess, pi.dwProcessId))
4696 if (!TerminateProcess(pi.hProcess, 255))
4698 (
errmsg_internal(
"could not terminate unstarted process: error code %lu",
4700 CloseHandle(pi.hProcess);
4701 CloseHandle(pi.hThread);
4702 UnmapViewOfFile(param);
4703 CloseHandle(paramHandle);
4708 if (!UnmapViewOfFile(param))
4710 (
errmsg(
"could not unmap view of backend parameter file: error code %lu",
4712 if (!CloseHandle(paramHandle))
4714 (
errmsg(
"could not close handle to backend parameter file: error code %lu",
4727 if (!TerminateProcess(pi.hProcess, 255))
4729 (
errmsg_internal(
"could not terminate process that failed to reserve memory: error code %lu",
4731 CloseHandle(pi.hProcess);
4732 CloseHandle(pi.hThread);
4733 if (++retry_count < 100)
4736 (
errmsg(
"giving up after too many tries to reserve shared memory"),
4737 errhint(
"This might be caused by ASLR or antivirus software.")));
4746 if (ResumeThread(pi.hThread) == -1)
4748 if (!TerminateProcess(pi.hProcess, 255))
4751 (
errmsg_internal(
"could not terminate unstartable process: error code %lu",
4753 CloseHandle(pi.hProcess);
4754 CloseHandle(pi.hThread);
4757 CloseHandle(pi.hProcess);
4758 CloseHandle(pi.hThread);
4760 (
errmsg_internal(
"could not resume thread of unstarted process: error code %lu",
4770 childinfo =
palloc(
sizeof(win32_deadchild_waitinfo));
4771 childinfo->procHandle = pi.hProcess;
4772 childinfo->procId = pi.dwProcessId;
4774 if (!RegisterWaitForSingleObject(&childinfo->waitHandle,
4776 pgwin32_deadchild_callback,
4779 WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD))
4781 (
errmsg_internal(
"could not register process for wait: error code %lu",
4786 CloseHandle(pi.hThread);
4788 return pi.dwProcessId;
4805 SubPostmasterMain(
int argc,
char *argv[])
4818 elog(
FATAL,
"invalid subpostmaster invocation");
4822 read_backend_variables(argv[2], &
port);
4846 if (strcmp(argv[1],
"--forkbackend") == 0 ||
4847 strcmp(argv[1],
"--forkavlauncher") == 0 ||
4848 strcmp(argv[1],
"--forkavworker") == 0 ||
4849 strcmp(argv[1],
"--forkaux") == 0 ||
4850 strncmp(argv[1],
"--forkbgworker=", 15) == 0)
4856 if (strcmp(argv[1],
"--forkavlauncher") == 0)
4857 AutovacuumLauncherIAm();
4858 if (strcmp(argv[1],
"--forkavworker") == 0)
4859 AutovacuumWorkerIAm();
4862 read_nondefault_variables();
4887 if (strcmp(argv[1],
"--forkbackend") == 0)
4910 (
errmsg(
"SSL configuration could not be loaded in child process")));
4937 if (strcmp(argv[1],
"--forkaux") == 0)
4952 auxtype = atoi(argv[3]);
4955 if (strcmp(argv[1],
"--forkavlauncher") == 0)
4968 if (strcmp(argv[1],
"--forkavworker") == 0)
4981 if (strncmp(argv[1],
"--forkbgworker=", 15) == 0)
4998 shmem_slot = atoi(argv[1] + 15);
5003 if (strcmp(argv[1],
"--forklog") == 0)
5023 #ifdef HAVE_PTHREAD_IS_THREADED_NP
5031 if (pthread_is_threaded_np() != 0)
5033 (
errcode(ERRCODE_INTERNAL_ERROR),
5035 errdetail(
"Please report this to <%s>.", PACKAGE_BUGREPORT)));
5092 sd_notify(0,
"READY=1");
5103 (
errmsg(
"database system is ready to accept read-only connections")));
5108 sd_notify(0,
"READY=1");
5320 av[ac++] =
"postgres";
5321 av[ac++] =
"--forkaux";
5330 pid = postmaster_forkexec(ac,
av);
5354 int save_errno = errno;
5361 (
errmsg(
"could not fork startup process: %m")));
5365 (
errmsg(
"could not fork archiver process: %m")));
5369 (
errmsg(
"could not fork background writer process: %m")));
5373 (
errmsg(
"could not fork checkpointer process: %m")));
5377 (
errmsg(
"could not fork WAL writer process: %m")));
5381 (
errmsg(
"could not fork WAL receiver process: %m")));
5385 (
errmsg(
"could not fork process: %m")));
5436 (
errcode(ERRCODE_INTERNAL_ERROR),
5437 errmsg(
"could not generate random cancel key")));
5457 ShmemBackendArrayAdd(bn);
5472 (
errcode(ERRCODE_OUT_OF_MEMORY),
5473 errmsg(
"out of memory")));
5529 #define OPTS_FILE "postmaster.opts"
5531 if ((fp = fopen(
OPTS_FILE,
"w")) == NULL)
5539 fprintf(fp,
"%s", fullprogname);
5540 for (
i = 1;
i < argc;
i++)
5585 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5586 errmsg(
"database connection requirement not indicated during registration")));
5597 (
errmsg(
"invalid processing mode in background worker")));
5612 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5613 errmsg(
"database connection requirement not indicated during registration")));
5624 (
errmsg(
"invalid processing mode in background worker")));
5634 sigprocmask(SIG_SETMASK, &
BlockSig, NULL);
5645 bgworker_forkexec(
int shmem_slot)
5653 av[ac++] =
"postgres";
5660 return postmaster_forkexec(ac,
av);
5701 switch ((worker_pid = bgworker_forkexec(rw->
rw_shmem_slot)))
5709 (
errmsg(
"could not fork worker process: %m")));
5719 #ifndef EXEC_BACKEND