80 #ifdef HAVE_SYS_SELECT_H
81 #include <sys/select.h>
89 #include <systemd/sd-daemon.h>
92 #ifdef HAVE_PTHREAD_IS_THREADED_NP
148 #define BACKEND_TYPE_NORMAL 0x0001
149 #define BACKEND_TYPE_AUTOVAC 0x0002
150 #define BACKEND_TYPE_WALSND 0x0004
151 #define BACKEND_TYPE_BGWORKER 0x0008
152 #define BACKEND_TYPE_ALL 0x000F
194 static Backend *ShmemBackendArray;
273 #define SmartShutdown 1
274 #define FastShutdown 2
275 #define ImmediateShutdown 3
354 #define SIGKILL_CHILDREN_AFTER_SECS 5
378 static bool LoadedSSL =
false;
382 static DNSServiceRef bonjour_sdref = NULL;
404 static void HandleChildCrash(
int pid,
int exitstatus,
const char *procname);
406 int pid,
int exitstatus);
424 #define SignalChildren(sig) SignalSomeChildren(sig, BACKEND_TYPE_ALL)
429 static bool CreateOptsFile(
int argc,
char *argv[],
char *fullprogname);
441 #define PgArchStartupAllowed() \
442 (((XLogArchivingActive() && pmState == PM_RUN) || \
443 (XLogArchivingAlways() && \
444 (pmState == PM_RECOVERY || pmState == PM_HOT_STANDBY))) && \
452 static pid_t waitpid(pid_t pid,
int *exitstatus,
int options);
453 static void WINAPI pgwin32_deadchild_callback(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
455 static HANDLE win32ChildQueue;
462 } win32_deadchild_waitinfo;
465 static pid_t backend_forkexec(
Port *
port);
466 static pid_t internal_forkexec(
int argc,
char *argv[],
Port *
port);
474 WSAPROTOCOL_INFO wsainfo;
477 typedef int InheritableSocket;
486 InheritableSocket portsocket;
501 #ifndef HAVE_SPINLOCKS
522 HANDLE PostmasterHandle;
523 HANDLE initial_signal_pipe;
533 static void read_backend_variables(
char *
id,
Port *
port);
534 static void restore_backend_variables(BackendParameters *param,
Port *
port);
537 static bool save_backend_variables(BackendParameters *param,
Port *
port);
539 static bool save_backend_variables(BackendParameters *param,
Port *
port,
540 HANDLE childProcess, pid_t childPid);
543 static void ShmemBackendArrayAdd(
Backend *bn);
544 static void ShmemBackendArrayRemove(
Backend *bn);
547 #define StartupDataBase() StartChildProcess(StartupProcess)
548 #define StartArchiver() StartChildProcess(ArchiverProcess)
549 #define StartBackgroundWriter() StartChildProcess(BgWriterProcess)
550 #define StartCheckpointer() StartChildProcess(CheckpointerProcess)
551 #define StartWalWriter() StartChildProcess(WalWriterProcess)
552 #define StartWalReceiver() StartChildProcess(WalReceiverProcess)
555 #define EXIT_STATUS_0(st) ((st) == 0)
556 #define EXIT_STATUS_1(st) (WIFEXITED(st) && WEXITSTATUS(st) == 1)
557 #define EXIT_STATUS_3(st) (WIFEXITED(st) && WEXITSTATUS(st) == 3)
567 HANDLE PostmasterHandle;
579 bool listen_addr_saved =
false;
581 char *output_config_variable = NULL;
704 while ((opt =
getopt(argc, argv,
"B:bc:C:D:d:EeFf:h:ijk:lN:nOPp:r:S:sTt:W:-:")) != -1)
718 output_config_variable = strdup(
optarg);
744 write_stderr(
"%s: invalid argument for option -f: \"%s\"\n",
823 write_stderr(
"%s: invalid argument for option -t: \"%s\"\n",
845 (
errcode(ERRCODE_SYNTAX_ERROR),
846 errmsg(
"--%s requires a value",
850 (
errcode(ERRCODE_SYNTAX_ERROR),
851 errmsg(
"-c %s requires a value",
863 write_stderr(
"Try \"%s --help\" for more information.\n",
876 write_stderr(
"Try \"%s --help\" for more information.\n",
888 if (output_config_variable != NULL)
913 puts(config_val ? config_val :
"");
942 write_stderr(
"%s: superuser_reserved_connections (%d) must be less than max_connections (%d)\n",
949 (
errmsg(
"WAL archival cannot be enabled when wal_level is \"minimal\"")));
952 (
errmsg(
"WAL streaming (max_wal_senders > 0) requires wal_level \"replica\" or \"logical\"")));
969 #ifdef HAVE_INT_OPTRESET
1074 if (output_config_variable != NULL)
1079 puts(config_val ? config_val :
"");
1110 win32ChildQueue = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 1);
1111 if (win32ChildQueue == NULL)
1113 (
errmsg(
"could not create I/O completion port for child queue")));
1157 errmsg(
"could not remove file \"%s\": %m",
1178 (
errmsg(
"ending log output to stderr"),
1179 errhint(
"Future log output will go to log destination \"%s\".",
1190 (
errmsg(
"starting %s", PG_VERSION_STR)));
1218 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1219 errmsg(
"invalid list syntax in parameter \"%s\"",
1220 "listen_addresses")));
1223 foreach(l, elemlist)
1225 char *curhost = (
char *)
lfirst(l);
1227 if (strcmp(curhost,
"*") == 0)
1242 if (!listen_addr_saved)
1245 listen_addr_saved =
true;
1250 (
errmsg(
"could not create listen socket for \"%s\"",
1256 (
errmsg(
"could not create any TCP/IP sockets")));
1266 DNSServiceErrorType err;
1274 err = DNSServiceRegister(&bonjour_sdref,
1278 "_postgresql._tcp.",
1286 if (err != kDNSServiceErr_NoError)
1288 (
errmsg(
"DNSServiceRegister() failed: error code %ld",
1301 #ifdef HAVE_UNIX_SOCKETS
1317 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1318 errmsg(
"invalid list syntax in parameter \"%s\"",
1319 "unix_socket_directories")));
1322 foreach(l, elemlist)
1324 char *socketdir = (
char *)
lfirst(l);
1340 (
errmsg(
"could not create Unix-domain socket in directory \"%s\"",
1346 (
errmsg(
"could not create any Unix-domain sockets")));
1358 (
errmsg(
"no socket created for listening")));
1365 if (!listen_addr_saved)
1389 write_stderr(
"%s: could not change permissions of external PID file \"%s\": %s\n",
1393 write_stderr(
"%s: could not write external PID file \"%s\": %s\n",
1420 (
errmsg(
"could not load pg_hba.conf")));
1432 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1443 if (pthread_is_threaded_np() != 0)
1445 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1446 errmsg(
"postmaster became multithreaded during startup"),
1447 errhint(
"Set the LC_ALL environment variable to a valid locale.")));
1548 (
errmsg(
"%s: could not locate my own executable path",
argv0)));
1553 postgres_exec_path) < 0)
1555 (
errmsg(
"%s: could not locate matching postgres executable",
1576 errmsg(
"could not open directory \"%s\": %m",
1578 errhint(
"This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
1605 write_stderr(
"%s: could not find the database system\n"
1606 "Expected to find it in the directory \"%s\",\n"
1607 "but could not open file \"%s\": %s\n",
1640 timeout->tv_sec =
Max(timeout->tv_sec, 0);
1641 timeout->tv_usec = 0;
1645 timeout->tv_sec = 60;
1646 timeout->tv_usec = 0;
1653 timeout->tv_sec = 0;
1654 timeout->tv_usec = 0;
1687 if (next_wakeup == 0 || this_wakeup < next_wakeup)
1688 next_wakeup = this_wakeup;
1692 if (next_wakeup != 0)
1699 timeout->tv_sec = secs;
1700 timeout->tv_usec = microsecs;
1703 if (timeout->tv_sec > 60)
1705 timeout->tv_sec = 60;
1706 timeout->tv_usec = 0;
1711 timeout->tv_sec = 60;
1712 timeout->tv_usec = 0;
1726 time_t last_lockfile_recheck_time,
1729 last_lockfile_recheck_time = last_touch_time = time(NULL);
1749 memcpy((
char *) &rmask, (
char *) &readmask,
sizeof(fd_set));
1763 struct timeval timeout;
1770 selres =
select(nSockets, &rmask, NULL, NULL, &timeout);
1782 errmsg(
"select() failed in postmaster: %m")));
1880 #ifdef HAVE_PTHREAD_IS_THREADED_NP
1886 Assert(pthread_is_threaded_np() == 0);
1913 (
errmsg(
"issuing SIGKILL to recalcitrant children")));
1934 (
errmsg(
"performing immediate shutdown because data directory lock file is invalid")));
1937 last_lockfile_recheck_time =
now;
1949 last_touch_time =
now;
2034 if (!ssl_done && !gss_done)
2036 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2037 errmsg(
"incomplete startup packet")));
2048 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2049 errmsg(
"invalid length of startup packet")));
2064 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2065 errmsg(
"incomplete startup packet")));
2089 if (!LoadedSSL ||
port->laddr.addr.ss_family == AF_UNIX)
2098 if (
send(
port->sock, &SSLok, 1, 0) != 1)
2104 errmsg(
"failed to send SSL negotiation response: %m")));
2121 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2122 errmsg(
"received unencrypted data after SSL request"),
2123 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
2138 if (
port->laddr.addr.ss_family != AF_UNIX)
2142 while (
send(
port->sock, &GSSok, 1, 0) != 1)
2148 errmsg(
"failed to send GSSAPI negotiation response: %m")));
2165 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2166 errmsg(
"received unencrypted data after GSSAPI encryption request"),
2167 errdetail(
"This could be either a client-software bug or evidence of an attempted man-in-the-middle attack.")));
2189 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2190 errmsg(
"unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
2209 List *unrecognized_protocol_options =
NIL;
2218 while (offset <
len)
2220 char *nameptr =
buf + offset;
2224 if (*nameptr ==
'\0')
2226 valoffset = offset + strlen(nameptr) + 1;
2227 if (valoffset >=
len)
2229 valptr =
buf + valoffset;
2231 if (strcmp(nameptr,
"database") == 0)
2233 else if (strcmp(nameptr,
"user") == 0)
2235 else if (strcmp(nameptr,
"options") == 0)
2237 else if (strcmp(nameptr,
"replication") == 0)
2246 if (strcmp(valptr,
"database") == 0)
2253 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
2254 errmsg(
"invalid value for parameter \"%s\": \"%s\"",
2257 errhint(
"Valid values are: \"false\", 0, \"true\", 1, \"database\".")));
2259 else if (strncmp(nameptr,
"_pq_.", 5) == 0)
2266 unrecognized_protocol_options =
2283 if (strcmp(nameptr,
"application_name") == 0)
2285 char *tmp_app_name =
pstrdup(valptr);
2289 port->application_name = tmp_app_name;
2292 offset = valoffset + strlen(valptr) + 1;
2299 if (offset !=
len - 1)
2301 (
errcode(ERRCODE_PROTOCOL_VIOLATION),
2302 errmsg(
"invalid startup packet layout: expected terminator as last byte")));
2311 unrecognized_protocol_options !=
NIL)
2316 if (
port->user_name == NULL ||
port->user_name[0] ==
'\0')
2318 (
errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
2319 errmsg(
"no PostgreSQL user name specified in startup packet")));
2322 if (
port->database_name == NULL ||
port->database_name[0] ==
'\0')
2333 if (strchr(
port->user_name,
'@') ==
2334 port->user_name + strlen(
port->user_name) - 1)
2335 *strchr(
port->user_name,
'@') =
'\0';
2366 port->database_name[0] =
'\0';
2378 switch (
port->canAcceptConnections)
2383 errmsg(
"the database system is starting up")));
2389 errmsg(
"the database system is not yet accepting connections"),
2390 errdetail(
"Consistent recovery state has not been yet reached.")));
2394 errmsg(
"the database system is not accepting connections"),
2395 errdetail(
"Hot standby mode is disabled.")));
2400 errmsg(
"the database system is shutting down")));
2405 errmsg(
"the database system is in recovery mode")));
2409 (
errcode(ERRCODE_TOO_MANY_CONNECTIONS),
2410 errmsg(
"sorry, too many clients already")));
2441 foreach(lc, unrecognized_protocol_options)
2458 int32 cancelAuthCode;
2461 #ifndef EXEC_BACKEND
2475 #ifndef EXEC_BACKEND
2482 bp = (
Backend *) &ShmemBackendArray[
i];
2484 if (bp->
pid == backendPID)
2490 (
errmsg_internal(
"processing cancel request: sending SIGINT to process %d",
2497 (
errmsg(
"wrong key in cancel request for process %d",
2501 #ifndef EXEC_BACKEND
2509 (
errmsg(
"PID %d in cancel request did not match any process",
2583 (
errcode(ERRCODE_OUT_OF_MEMORY),
2584 errmsg(
"out of memory")));
2638 errmsg_internal(
"could not close postmaster death monitoring pipe in child process: %m")));
2677 close(DNSServiceRefSockFD(bonjour_sdref));
2750 int save_errno = errno;
2763 (
errmsg(
"received SIGHUP, reloading configuration files")));
2787 (
errmsg(
"%s was not reloaded",
"pg_hba.conf")));
2791 (
errmsg(
"%s was not reloaded",
"pg_ident.conf")));
2801 (
errmsg(
"SSL configuration was not reloaded")));
2830 int save_errno = errno;
2842 postgres_signal_arg)));
2844 switch (postgres_signal_arg)
2857 (
errmsg(
"received smart shutdown request")));
2862 sd_notify(0,
"STOPPING=1");
2898 (
errmsg(
"received fast shutdown request")));
2903 sd_notify(0,
"STOPPING=1");
2916 (
errmsg(
"aborting any active transactions")));
2940 (
errmsg(
"received immediate shutdown request")));
2945 sd_notify(0,
"STOPPING=1");
2977 int save_errno = errno;
2992 while ((pid = waitpid(-1, &exitstatus, WNOHANG)) > 0)
3017 (
errmsg(
"shutdown at recovery target")));
3038 (
errmsg(
"aborting startup due to startup process failure")));
3071 _(
"startup process"));
3111 (
errmsg(
"database system is ready to accept connections")));
3116 sd_notify(0,
"READY=1");
3132 _(
"background writer process"));
3179 _(
"checkpointer process"));
3195 _(
"WAL writer process"));
3210 _(
"WAL receiver process"));
3225 _(
"autovacuum launcher process"));
3243 _(
"archiver process"));
3316 if (exitstatus == ERROR_WAIT_NO_CHILDREN)
3378 namebuf, pid, exitstatus);
3417 if (exitstatus == ERROR_WAIT_NO_CHILDREN)
3448 ShmemBackendArrayRemove(bp);
3498 (
errmsg(
"terminating any other active server processes")));
3543 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3564 ShmemBackendArrayRemove(bp);
3595 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3612 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3625 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3637 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3649 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3661 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3673 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3685 (
SendStop ?
"SIGSTOP" :
"SIGQUIT"),
3721 char activity_buffer[1024];
3722 const char *activity = NULL;
3727 sizeof(activity_buffer));
3735 (
errmsg(
"%s (PID %d) exited with exit code %d",
3737 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3746 (
errmsg(
"%s (PID %d) was terminated by exception 0x%X",
3747 procname, pid,
WTERMSIG(exitstatus)),
3748 errhint(
"See C include file \"ntstatus.h\" for a description of the hexadecimal value."),
3749 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3756 (
errmsg(
"%s (PID %d) was terminated by signal %d: %s",
3757 procname, pid,
WTERMSIG(exitstatus),
3759 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3768 (
errmsg(
"%s (PID %d) exited with unrecognized status %d",
3769 procname, pid, exitstatus),
3770 activity ?
errdetail(
"Failed process was running: %s", activity) : 0));
3994 (
errmsg(
"shutting down due to startup process failure")));
4000 (
errmsg(
"shutting down because restart_after_crash is off")));
4012 (
errmsg(
"all server processes terminated; reinitializing")));
4057 if (
kill(pid, signal) < 0)
4058 elog(
DEBUG3,
"kill(%ld,%d) failed: %m", (
long) pid, signal);
4067 if (
kill(-pid, signal) < 0)
4068 elog(
DEBUG3,
"kill(%ld,%d) failed: %m", (
long) (-pid), signal);
4084 bool signaled =
false;
4113 signal, (
int) bp->
pid)));
4169 (
errcode(ERRCODE_OUT_OF_MEMORY),
4170 errmsg(
"out of memory")));
4183 (
errcode(ERRCODE_INTERNAL_ERROR),
4184 errmsg(
"could not generate random cancel key")));
4206 pid = backend_forkexec(
port);
4239 int save_errno = errno;
4246 (
errmsg(
"could not fork new process for connection: %m")));
4254 (
int) pid, (
int)
port->sock)));
4266 ShmemBackendArrayAdd(bn);
4287 snprintf(buffer,
sizeof(buffer),
"E%s%s\n",
4288 _(
"could not fork new process for connection: "),
4298 rc =
send(
port->sock, buffer, strlen(buffer) + 1, 0);
4299 }
while (rc < 0 && errno ==
EINTR);
4344 port->remote_host =
"";
4345 port->remote_port =
"";
4372 remote_host[0] =
'\0';
4373 remote_port[0] =
'\0';
4375 remote_host,
sizeof(remote_host),
4376 remote_port,
sizeof(remote_port),
4386 port->remote_host = strdup(remote_host);
4387 port->remote_port = strdup(remote_port);
4394 (
errmsg(
"connection received: host=%s port=%s",
4399 (
errmsg(
"connection received: host=%s",
4416 strspn(remote_host,
"0123456789.") < strlen(remote_host) &&
4417 strspn(remote_host,
"0123456789ABCDEFabcdef:") < strlen(remote_host))
4418 port->remote_hostname = strdup(remote_host);
4479 if (
port->remote_port[0] !=
'\0')
4523 postmaster_forkexec(
int argc,
char *argv[])
4529 return internal_forkexec(argc, argv, &
port);
4547 av[ac++] =
"postgres";
4548 av[ac++] =
"--forkbackend";
4554 return internal_forkexec(ac,
av,
port);
4566 internal_forkexec(
int argc,
char *argv[],
Port *
port)
4568 static unsigned long tmpBackendFileNum = 0;
4571 BackendParameters param;
4574 if (!save_backend_variables(¶m,
port))
4597 errmsg(
"could not create file \"%s\": %m",
4603 if (fwrite(¶m,
sizeof(param), 1, fp) != 1)
4607 errmsg(
"could not write to file \"%s\": %m", tmpfilename)));
4617 errmsg(
"could not write to file \"%s\": %m", tmpfilename)));
4623 Assert(argv[argc] == NULL);
4624 Assert(strncmp(argv[1],
"--fork", 6) == 0);
4628 argv[2] = tmpfilename;
4633 if (execv(postgres_exec_path, argv) < 0)
4636 (
errmsg(
"could not execute server process \"%s\": %m",
4637 postgres_exec_path)));
4658 internal_forkexec(
int argc,
char *argv[],
Port *
port)
4660 int retry_count = 0;
4662 PROCESS_INFORMATION pi;
4667 BackendParameters *param;
4668 SECURITY_ATTRIBUTES
sa;
4669 char paramHandleStr[32];
4670 win32_deadchild_waitinfo *childinfo;
4674 Assert(argv[argc] == NULL);
4675 Assert(strncmp(argv[1],
"--fork", 6) == 0);
4682 ZeroMemory(&
sa,
sizeof(
sa));
4683 sa.nLength =
sizeof(
sa);
4684 sa.bInheritHandle = TRUE;
4685 paramHandle = CreateFileMapping(INVALID_HANDLE_VALUE,
4689 sizeof(BackendParameters),
4691 if (paramHandle == INVALID_HANDLE_VALUE)
4694 (
errmsg(
"could not create backend parameter file mapping: error code %lu",
4699 param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0,
sizeof(BackendParameters));
4703 (
errmsg(
"could not map backend parameter memory: error code %lu",
4705 CloseHandle(paramHandle);
4711 sprintf(paramHandleStr,
"%llu", (LONG_PTR) paramHandle);
4713 sprintf(paramHandleStr,
"%lu", (DWORD) paramHandle);
4715 argv[2] = paramHandleStr;
4718 cmdLine[
sizeof(cmdLine) - 1] =
'\0';
4719 cmdLine[
sizeof(cmdLine) - 2] =
'\0';
4720 snprintf(cmdLine,
sizeof(cmdLine) - 1,
"\"%s\"", postgres_exec_path);
4722 while (argv[++
i] != NULL)
4724 j = strlen(cmdLine);
4725 snprintf(cmdLine +
j,
sizeof(cmdLine) - 1 -
j,
" \"%s\"", argv[
i]);
4727 if (cmdLine[
sizeof(cmdLine) - 2] !=
'\0')
4730 (
errmsg(
"subprocess command line too long")));
4731 UnmapViewOfFile(param);
4732 CloseHandle(paramHandle);
4736 memset(&pi, 0,
sizeof(pi));
4737 memset(&si, 0,
sizeof(si));
4744 if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
4745 NULL, NULL, &si, &pi))
4748 (
errmsg(
"CreateProcess() call failed: %m (error code %lu)",
4750 UnmapViewOfFile(param);
4751 CloseHandle(paramHandle);
4755 if (!save_backend_variables(param,
port, pi.hProcess, pi.dwProcessId))
4761 if (!TerminateProcess(pi.hProcess, 255))
4763 (
errmsg_internal(
"could not terminate unstarted process: error code %lu",
4765 CloseHandle(pi.hProcess);
4766 CloseHandle(pi.hThread);
4767 UnmapViewOfFile(param);
4768 CloseHandle(paramHandle);
4773 if (!UnmapViewOfFile(param))
4775 (
errmsg(
"could not unmap view of backend parameter file: error code %lu",
4777 if (!CloseHandle(paramHandle))
4779 (
errmsg(
"could not close handle to backend parameter file: error code %lu",
4792 if (!TerminateProcess(pi.hProcess, 255))
4794 (
errmsg_internal(
"could not terminate process that failed to reserve memory: error code %lu",
4796 CloseHandle(pi.hProcess);
4797 CloseHandle(pi.hThread);
4798 if (++retry_count < 100)
4801 (
errmsg(
"giving up after too many tries to reserve shared memory"),
4802 errhint(
"This might be caused by ASLR or antivirus software.")));
4811 if (ResumeThread(pi.hThread) == -1)
4813 if (!TerminateProcess(pi.hProcess, 255))
4816 (
errmsg_internal(
"could not terminate unstartable process: error code %lu",
4818 CloseHandle(pi.hProcess);
4819 CloseHandle(pi.hThread);
4822 CloseHandle(pi.hProcess);
4823 CloseHandle(pi.hThread);
4825 (
errmsg_internal(
"could not resume thread of unstarted process: error code %lu",
4838 childinfo =
malloc(
sizeof(win32_deadchild_waitinfo));
4841 (
errcode(ERRCODE_OUT_OF_MEMORY),
4842 errmsg(
"out of memory")));
4844 childinfo->procHandle = pi.hProcess;
4845 childinfo->procId = pi.dwProcessId;
4847 if (!RegisterWaitForSingleObject(&childinfo->waitHandle,
4849 pgwin32_deadchild_callback,
4852 WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD))
4854 (
errmsg_internal(
"could not register process for wait: error code %lu",
4859 CloseHandle(pi.hThread);
4861 return pi.dwProcessId;
4878 SubPostmasterMain(
int argc,
char *argv[])
4891 elog(
FATAL,
"invalid subpostmaster invocation");
4895 read_backend_variables(argv[2], &
port);
4919 if (strcmp(argv[1],
"--forkbackend") == 0 ||
4920 strcmp(argv[1],
"--forkavlauncher") == 0 ||
4921 strcmp(argv[1],
"--forkavworker") == 0 ||
4922 strcmp(argv[1],
"--forkaux") == 0 ||
4923 strncmp(argv[1],
"--forkbgworker=", 15) == 0)
4929 if (strcmp(argv[1],
"--forkavlauncher") == 0)
4930 AutovacuumLauncherIAm();
4931 if (strcmp(argv[1],
"--forkavworker") == 0)
4932 AutovacuumWorkerIAm();
4935 read_nondefault_variables();
4960 if (strcmp(argv[1],
"--forkbackend") == 0)
4983 (
errmsg(
"SSL configuration could not be loaded in child process")));
5010 if (strcmp(argv[1],
"--forkaux") == 0)
5025 auxtype = atoi(argv[3]);
5028 if (strcmp(argv[1],
"--forkavlauncher") == 0)
5041 if (strcmp(argv[1],
"--forkavworker") == 0)
5054 if (strncmp(argv[1],
"--forkbgworker=", 15) == 0)
5071 shmem_slot = atoi(argv[1] + 15);
5076 if (strcmp(argv[1],
"--forklog") == 0)
5096 #ifdef HAVE_PTHREAD_IS_THREADED_NP
5104 if (pthread_is_threaded_np() != 0)
5106 (
errcode(ERRCODE_INTERNAL_ERROR),
5108 errdetail(
"Please report this to <%s>.", PACKAGE_BUGREPORT)));
5129 int save_errno = errno;
5169 sd_notify(0,
"READY=1");
5180 (
errmsg(
"database system is ready to accept read-only connections")));
5185 sd_notify(0,
"READY=1");
5403 av[ac++] =
"postgres";
5404 av[ac++] =
"--forkaux";
5413 pid = postmaster_forkexec(ac,
av);
5437 int save_errno = errno;
5444 (
errmsg(
"could not fork startup process: %m")));
5448 (
errmsg(
"could not fork archiver process: %m")));
5452 (
errmsg(
"could not fork background writer process: %m")));
5456 (
errmsg(
"could not fork checkpointer process: %m")));
5460 (
errmsg(
"could not fork WAL writer process: %m")));
5464 (
errmsg(
"could not fork WAL receiver process: %m")));
5468 (
errmsg(
"could not fork process: %m")));
5519 (
errcode(ERRCODE_INTERNAL_ERROR),
5520 errmsg(
"could not generate random cancel key")));
5540 ShmemBackendArrayAdd(bn);
5555 (
errcode(ERRCODE_OUT_OF_MEMORY),
5556 errmsg(
"out of memory")));
5612 #define OPTS_FILE "postmaster.opts"
5614 if ((fp = fopen(
OPTS_FILE,
"w")) == NULL)
5622 fprintf(fp,
"%s", fullprogname);
5623 for (
i = 1;
i < argc;
i++)
5668 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5669 errmsg(
"database connection requirement not indicated during registration")));
5676 (
errmsg(
"invalid processing mode in background worker")));
5691 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
5692 errmsg(
"database connection requirement not indicated during registration")));
5699 (
errmsg(
"invalid processing mode in background worker")));
5720 bgworker_forkexec(
int shmem_slot)
5728 av[ac++] =
"postgres";
5735 return postmaster_forkexec(ac,
av);
5776 switch ((worker_pid = bgworker_forkexec(rw->
rw_shmem_slot)))
5778 switch ((worker_pid =