mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
pgindent run.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
*
|
||||
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.41 2003/07/28 00:09:15 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.42 2003/08/04 00:43:21 momjian Exp $
|
||||
* ----------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@@ -85,6 +85,7 @@ static bool pgStatRunningInCollector = FALSE;
|
||||
static int pgStatTabstatAlloc = 0;
|
||||
static int pgStatTabstatUsed = 0;
|
||||
static PgStat_MsgTabstat **pgStatTabstatMessages = NULL;
|
||||
|
||||
#define TABSTAT_QUANTUM 4 /* we alloc this many at a time */
|
||||
|
||||
static int pgStatXactCommit = 0;
|
||||
@@ -146,8 +147,10 @@ static void pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len);
|
||||
void
|
||||
pgstat_init(void)
|
||||
{
|
||||
ACCEPT_TYPE_ARG3 alen;
|
||||
struct addrinfo *addrs = NULL, *addr, hints;
|
||||
ACCEPT_TYPE_ARG3 alen;
|
||||
struct addrinfo *addrs = NULL,
|
||||
*addr,
|
||||
hints;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@@ -197,7 +200,7 @@ pgstat_init(void)
|
||||
gai_strerror(ret))));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
|
||||
for (addr = addrs; addr; addr = addr->ai_next)
|
||||
{
|
||||
#ifdef HAVE_UNIX_SOCKETS
|
||||
@@ -233,11 +236,11 @@ pgstat_init(void)
|
||||
addrs = NULL;
|
||||
|
||||
alen = sizeof(pgStatAddr);
|
||||
if (getsockname(pgStatSock, (struct sockaddr *)&pgStatAddr, &alen) < 0)
|
||||
if (getsockname(pgStatSock, (struct sockaddr *) & pgStatAddr, &alen) < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not get address of socket for statistics: %m")));
|
||||
errmsg("could not get address of socket for statistics: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -265,7 +268,7 @@ pgstat_init(void)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not set statistics socket to nonblock mode: %m")));
|
||||
errmsg("could not set statistics socket to nonblock mode: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -276,7 +279,7 @@ pgstat_init(void)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not create pipe for statistics collector: %m")));
|
||||
errmsg("could not create pipe for statistics collector: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -320,10 +323,10 @@ pgstat_start(void)
|
||||
|
||||
/*
|
||||
* Do nothing if too soon since last collector start. This is a
|
||||
* safety valve to protect against continuous respawn attempts if
|
||||
* the collector is dying immediately at launch. Note that since
|
||||
* we will be re-called from the postmaster main loop, we will get
|
||||
* another chance later.
|
||||
* safety valve to protect against continuous respawn attempts if the
|
||||
* collector is dying immediately at launch. Note that since we will
|
||||
* be re-called from the postmaster main loop, we will get another
|
||||
* chance later.
|
||||
*/
|
||||
curtime = time(NULL);
|
||||
if ((unsigned int) (curtime - last_pgstat_start_time) <
|
||||
@@ -338,6 +341,7 @@ pgstat_start(void)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("statistics collector startup skipped")));
|
||||
|
||||
/*
|
||||
* We can only get here if someone tries to manually turn
|
||||
* pgstat_collect_startcollector on after it had been off.
|
||||
@@ -347,7 +351,8 @@ pgstat_start(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* Okay, fork off the collector. Remember its PID for pgstat_ispgstat.
|
||||
* Okay, fork off the collector. Remember its PID for
|
||||
* pgstat_ispgstat.
|
||||
*/
|
||||
|
||||
fflush(stdout);
|
||||
@@ -772,7 +777,7 @@ pgstat_reset_counters(void)
|
||||
if (!superuser())
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("must be superuser to reset statistics counters")));
|
||||
errmsg("must be superuser to reset statistics counters")));
|
||||
|
||||
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETCOUNTER);
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
@@ -897,7 +902,7 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
|
||||
*/
|
||||
if (pgStatTabstatUsed >= pgStatTabstatAlloc)
|
||||
{
|
||||
int newAlloc = pgStatTabstatAlloc + TABSTAT_QUANTUM;
|
||||
int newAlloc = pgStatTabstatAlloc + TABSTAT_QUANTUM;
|
||||
PgStat_MsgTabstat *newMessages;
|
||||
PgStat_MsgTabstat **msgArray;
|
||||
|
||||
@@ -1251,7 +1256,7 @@ pgstat_main(void)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not create pipe for statistics buffer: %m")));
|
||||
errmsg("could not create pipe for statistics buffer: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1316,7 +1321,7 @@ pgstat_main(void)
|
||||
/* assume the problem is out-of-memory */
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1394,7 +1399,7 @@ pgstat_main(void)
|
||||
continue;
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("select failed in statistics collector: %m")));
|
||||
errmsg("select failed in statistics collector: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1436,7 +1441,7 @@ pgstat_main(void)
|
||||
continue;
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not read from statistics pipe: %m")));
|
||||
errmsg("could not read from statistics pipe: %m")));
|
||||
exit(1);
|
||||
}
|
||||
if (len == 0) /* EOF on the pipe! */
|
||||
@@ -1455,7 +1460,7 @@ pgstat_main(void)
|
||||
* that we can restart both processes.
|
||||
*/
|
||||
ereport(LOG,
|
||||
(errmsg("invalid statistics message length")));
|
||||
(errmsg("invalid statistics message length")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1579,7 +1584,7 @@ pgstat_recvbuffer(void)
|
||||
int msg_send = 0; /* next send index in buffer */
|
||||
int msg_recv = 0; /* next receive index */
|
||||
int msg_have = 0; /* number of bytes stored */
|
||||
struct sockaddr_storage fromaddr;
|
||||
struct sockaddr_storage fromaddr;
|
||||
int fromlen;
|
||||
bool overflow = false;
|
||||
|
||||
@@ -1607,7 +1612,7 @@ pgstat_recvbuffer(void)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not set statistics pipe to nonblock mode: %m")));
|
||||
errmsg("could not set statistics pipe to nonblock mode: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1619,7 +1624,7 @@ pgstat_recvbuffer(void)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1692,13 +1697,13 @@ pgstat_recvbuffer(void)
|
||||
{
|
||||
fromlen = sizeof(fromaddr);
|
||||
len = recvfrom(pgStatSock, (char *) &input_buffer,
|
||||
sizeof(PgStat_Msg), 0,
|
||||
(struct sockaddr *) &fromaddr, &fromlen);
|
||||
sizeof(PgStat_Msg), 0,
|
||||
(struct sockaddr *) &fromaddr, &fromlen);
|
||||
if (len < 0)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("failed to read statistics message: %m")));
|
||||
errmsg("failed to read statistics message: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1887,7 +1892,7 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1919,7 +1924,7 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
|
||||
/* assume the problem is out-of-memory */
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -2234,7 +2239,7 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
/* in backend, can do normal error */
|
||||
@@ -2621,7 +2626,7 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -2803,7 +2808,7 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
|
||||
/* assume the problem is out-of-memory */
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.338 2003/08/01 23:25:00 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.339 2003/08/04 00:43:21 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -169,14 +169,15 @@ int ReservedBackends;
|
||||
static char *progname = (char *) NULL;
|
||||
|
||||
/* The socket(s) we're listening to. */
|
||||
#define MAXLISTEN 10
|
||||
#define MAXLISTEN 10
|
||||
static int ListenSocket[MAXLISTEN];
|
||||
|
||||
/* Used to reduce macros tests */
|
||||
#ifdef EXEC_BACKEND
|
||||
const bool ExecBackend = true;
|
||||
const bool ExecBackend = true;
|
||||
|
||||
#else
|
||||
const bool ExecBackend = false;
|
||||
const bool ExecBackend = false;
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -210,15 +211,15 @@ bool LogSourcePort;
|
||||
bool Log_connections = false;
|
||||
bool Db_user_namespace = false;
|
||||
|
||||
char *rendezvous_name;
|
||||
char *rendezvous_name;
|
||||
|
||||
/* For FNCTL_NONBLOCK */
|
||||
#if defined(WIN32) || defined(__BEOS__)
|
||||
long ioctlsocket_ret;
|
||||
long ioctlsocket_ret;
|
||||
#endif
|
||||
|
||||
/* list of library:init-function to be preloaded */
|
||||
char *preload_libraries_string = NULL;
|
||||
char *preload_libraries_string = NULL;
|
||||
|
||||
/* Startup/shutdown state */
|
||||
static pid_t StartupPID = 0,
|
||||
@@ -290,7 +291,8 @@ static void SignalChildren(int signal);
|
||||
static int CountChildren(void);
|
||||
static bool CreateOptsFile(int argc, char *argv[]);
|
||||
static pid_t SSDataBase(int xlop);
|
||||
static void postmaster_error(const char *fmt,...)
|
||||
static void
|
||||
postmaster_error(const char *fmt,...)
|
||||
/* This lets gcc check the format string for consistency. */
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
@@ -327,8 +329,8 @@ checkDataDir(const char *checkdir)
|
||||
else
|
||||
ereport(FATAL,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not read permissions of directory \"%s\": %m",
|
||||
checkdir)));
|
||||
errmsg("could not read permissions of directory \"%s\": %m",
|
||||
checkdir)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -357,7 +359,7 @@ checkDataDir(const char *checkdir)
|
||||
{
|
||||
fprintf(stderr,
|
||||
gettext("%s could not find the database system.\n"
|
||||
"Expected to find it in the PGDATA directory \"%s\",\n"
|
||||
"Expected to find it in the PGDATA directory \"%s\",\n"
|
||||
"but failed to open file \"%s\": %s\n"),
|
||||
progname, checkdir, path, strerror(errno));
|
||||
ExitPostmaster(2);
|
||||
@@ -374,17 +376,16 @@ reg_reply(DNSServiceRegistrationReplyErrorType errorCode, void *context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
PostmasterMain(int argc, char *argv[])
|
||||
{
|
||||
int opt;
|
||||
int status;
|
||||
int opt;
|
||||
int status;
|
||||
char original_extraoptions[MAXPGPATH];
|
||||
char *potential_DataDir = NULL;
|
||||
int i;
|
||||
char *potential_DataDir = NULL;
|
||||
int i;
|
||||
|
||||
*original_extraoptions = '\0';
|
||||
|
||||
@@ -581,7 +582,7 @@ PostmasterMain(int argc, char *argv[])
|
||||
|
||||
default:
|
||||
fprintf(stderr,
|
||||
gettext("Try '%s --help' for more information.\n"),
|
||||
gettext("Try '%s --help' for more information.\n"),
|
||||
progname);
|
||||
ExitPostmaster(1);
|
||||
}
|
||||
@@ -682,8 +683,8 @@ PostmasterMain(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
/*
|
||||
* process any libraries that should be preloaded and
|
||||
* optionally pre-initialized
|
||||
* process any libraries that should be preloaded and optionally
|
||||
* pre-initialized
|
||||
*/
|
||||
if (preload_libraries_string)
|
||||
process_preload_libraries(preload_libraries_string);
|
||||
@@ -725,13 +726,14 @@ PostmasterMain(int argc, char *argv[])
|
||||
{
|
||||
if (VirtualHost && VirtualHost[0])
|
||||
{
|
||||
char *curhost, *endptr;
|
||||
char c = 0;
|
||||
char *curhost,
|
||||
*endptr;
|
||||
char c = 0;
|
||||
|
||||
curhost = VirtualHost;
|
||||
for (;;)
|
||||
{
|
||||
while (*curhost == ' ') /* skip any extra spaces */
|
||||
while (*curhost == ' ') /* skip any extra spaces */
|
||||
curhost++;
|
||||
if (*curhost == '\0')
|
||||
break;
|
||||
@@ -747,8 +749,8 @@ PostmasterMain(int argc, char *argv[])
|
||||
ListenSocket, MAXLISTEN);
|
||||
if (status != STATUS_OK)
|
||||
ereport(LOG,
|
||||
(errmsg("could not create listen socket for \"%s\"",
|
||||
curhost)));
|
||||
(errmsg("could not create listen socket for \"%s\"",
|
||||
curhost)));
|
||||
if (endptr)
|
||||
{
|
||||
*endptr = c;
|
||||
@@ -766,10 +768,10 @@ PostmasterMain(int argc, char *argv[])
|
||||
ListenSocket, MAXLISTEN);
|
||||
if (status != STATUS_OK)
|
||||
ereport(LOG,
|
||||
(errmsg("could not create TCP/IP listen socket")));
|
||||
(errmsg("could not create TCP/IP listen socket")));
|
||||
}
|
||||
|
||||
#ifdef USE_RENDEZVOUS
|
||||
#ifdef USE_RENDEZVOUS
|
||||
if (rendezvous_name != NULL)
|
||||
{
|
||||
DNSServiceRegistrationCreate(rendezvous_name,
|
||||
@@ -777,7 +779,7 @@ PostmasterMain(int argc, char *argv[])
|
||||
"",
|
||||
htonl(PostPortNumber),
|
||||
"",
|
||||
(DNSServiceRegistrationReply)reg_reply,
|
||||
(DNSServiceRegistrationReply) reg_reply,
|
||||
NULL);
|
||||
}
|
||||
#endif
|
||||
@@ -842,8 +844,8 @@ PostmasterMain(int argc, char *argv[])
|
||||
|
||||
/*
|
||||
* Reset whereToSendOutput from Debug (its starting state) to None.
|
||||
* This prevents ereport from sending log messages to stderr unless the
|
||||
* syslog/stderr switch permits. We don't do this until the
|
||||
* This prevents ereport from sending log messages to stderr unless
|
||||
* the syslog/stderr switch permits. We don't do this until the
|
||||
* postmaster is fully launched, since startup failures may as well be
|
||||
* reported to stderr.
|
||||
*/
|
||||
@@ -989,10 +991,11 @@ usage(const char *progname)
|
||||
static int
|
||||
ServerLoop(void)
|
||||
{
|
||||
fd_set readmask;
|
||||
fd_set readmask;
|
||||
int nSockets;
|
||||
struct timeval now, later;
|
||||
struct timezone tz;
|
||||
struct timeval now,
|
||||
later;
|
||||
struct timezone tz;
|
||||
int i;
|
||||
|
||||
gettimeofday(&now, &tz);
|
||||
@@ -1090,8 +1093,8 @@ ServerLoop(void)
|
||||
}
|
||||
|
||||
/*
|
||||
* New connection pending on any of our sockets? If so,
|
||||
* fork a child process to deal with it.
|
||||
* New connection pending on any of our sockets? If so, fork a
|
||||
* child process to deal with it.
|
||||
*/
|
||||
for (i = 0; i < MAXLISTEN; i++)
|
||||
{
|
||||
@@ -1105,8 +1108,8 @@ ServerLoop(void)
|
||||
BackendStartup(port);
|
||||
|
||||
/*
|
||||
* We no longer need the open socket
|
||||
* or port structure in this process
|
||||
* We no longer need the open socket or port structure
|
||||
* in this process
|
||||
*/
|
||||
StreamClose(port->sock);
|
||||
ConnFree(port);
|
||||
@@ -1136,7 +1139,7 @@ initMasks(fd_set *rmask)
|
||||
|
||||
for (i = 0; i < MAXLISTEN; i++)
|
||||
{
|
||||
int fd = ListenSocket[i];
|
||||
int fd = ListenSocket[i];
|
||||
|
||||
if (fd == -1)
|
||||
break;
|
||||
@@ -1173,7 +1176,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
{
|
||||
/*
|
||||
* EOF after SSLdone probably means the client didn't like our
|
||||
* response to NEGOTIATE_SSL_CODE. That's not an error condition,
|
||||
* response to NEGOTIATE_SSL_CODE. That's not an error condition,
|
||||
* so don't clutter the log with a complaint.
|
||||
*/
|
||||
if (!SSLdone)
|
||||
@@ -1197,9 +1200,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
|
||||
/*
|
||||
* Allocate at least the size of an old-style startup packet, plus one
|
||||
* extra byte, and make sure all are zeroes. This ensures we will have
|
||||
* null termination of all strings, in both fixed- and variable-length
|
||||
* packet layouts.
|
||||
* extra byte, and make sure all are zeroes. This ensures we will
|
||||
* have null termination of all strings, in both fixed- and
|
||||
* variable-length packet layouts.
|
||||
*/
|
||||
if (len <= (int32) sizeof(StartupPacket))
|
||||
buf = palloc0(sizeof(StartupPacket) + 1);
|
||||
@@ -1243,7 +1246,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
{
|
||||
ereport(COMMERROR,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("failed to send SSL negotiation response: %m")));
|
||||
errmsg("failed to send SSL negotiation response: %m")));
|
||||
return STATUS_ERROR; /* close the connection */
|
||||
}
|
||||
|
||||
@@ -1259,41 +1262,41 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
/* Could add additional special packet types here */
|
||||
|
||||
/*
|
||||
* Set FrontendProtocol now so that ereport() knows what format to send
|
||||
* if we fail during startup.
|
||||
* Set FrontendProtocol now so that ereport() knows what format to
|
||||
* send if we fail during startup.
|
||||
*/
|
||||
FrontendProtocol = proto;
|
||||
|
||||
/* Check we can handle the protocol the frontend is using. */
|
||||
|
||||
if (PG_PROTOCOL_MAJOR(proto) < PG_PROTOCOL_MAJOR(PG_PROTOCOL_EARLIEST) ||
|
||||
PG_PROTOCOL_MAJOR(proto) > PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) ||
|
||||
(PG_PROTOCOL_MAJOR(proto) == PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) &&
|
||||
PG_PROTOCOL_MINOR(proto) > PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST)))
|
||||
PG_PROTOCOL_MAJOR(proto) > PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) ||
|
||||
(PG_PROTOCOL_MAJOR(proto) == PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) &&
|
||||
PG_PROTOCOL_MINOR(proto) > PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST)))
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
|
||||
PG_PROTOCOL_MAJOR(proto), PG_PROTOCOL_MINOR(proto),
|
||||
PG_PROTOCOL_MAJOR(proto), PG_PROTOCOL_MINOR(proto),
|
||||
PG_PROTOCOL_MAJOR(PG_PROTOCOL_EARLIEST),
|
||||
PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST),
|
||||
PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST))));
|
||||
|
||||
/*
|
||||
* Now fetch parameters out of startup packet and save them into the
|
||||
* Port structure. All data structures attached to the Port struct
|
||||
* Port structure. All data structures attached to the Port struct
|
||||
* must be allocated in TopMemoryContext so that they won't disappear
|
||||
* when we pass them to PostgresMain (see BackendFork). We need not worry
|
||||
* about leaking this storage on failure, since we aren't in the postmaster
|
||||
* process anymore.
|
||||
* when we pass them to PostgresMain (see BackendFork). We need not
|
||||
* worry about leaking this storage on failure, since we aren't in the
|
||||
* postmaster process anymore.
|
||||
*/
|
||||
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
|
||||
|
||||
if (PG_PROTOCOL_MAJOR(proto) >= 3)
|
||||
{
|
||||
int32 offset = sizeof(ProtocolVersion);
|
||||
int32 offset = sizeof(ProtocolVersion);
|
||||
|
||||
/*
|
||||
* Scan packet body for name/option pairs. We can assume any
|
||||
* Scan packet body for name/option pairs. We can assume any
|
||||
* string beginning within the packet body is null-terminated,
|
||||
* thanks to zeroing extra byte above.
|
||||
*/
|
||||
@@ -1301,9 +1304,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
|
||||
while (offset < len)
|
||||
{
|
||||
char *nameptr = ((char *) buf) + offset;
|
||||
int32 valoffset;
|
||||
char *valptr;
|
||||
char *nameptr = ((char *) buf) + offset;
|
||||
int32 valoffset;
|
||||
char *valptr;
|
||||
|
||||
if (*nameptr == '\0')
|
||||
break; /* found packet terminator */
|
||||
@@ -1328,11 +1331,12 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
}
|
||||
offset = valoffset + strlen(valptr) + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we didn't find a packet terminator exactly at the end of the
|
||||
* given packet length, complain.
|
||||
*/
|
||||
if (offset != len-1)
|
||||
if (offset != len - 1)
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||
errmsg("invalid startup packet layout: expected terminator as last byte")));
|
||||
@@ -1340,10 +1344,11 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Get the parameters from the old-style, fixed-width-fields startup
|
||||
* packet as C strings. The packet destination was cleared first so a
|
||||
* short packet has zeros silently added. We have to be prepared to
|
||||
* truncate the pstrdup result for oversize fields, though.
|
||||
* Get the parameters from the old-style, fixed-width-fields
|
||||
* startup packet as C strings. The packet destination was
|
||||
* cleared first so a short packet has zeros silently added. We
|
||||
* have to be prepared to truncate the pstrdup result for oversize
|
||||
* fields, though.
|
||||
*/
|
||||
StartupPacket *packet = (StartupPacket *) buf;
|
||||
|
||||
@@ -1363,7 +1368,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
if (port->user_name == NULL || port->user_name[0] == '\0')
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
|
||||
errmsg("no PostgreSQL user name specified in startup packet")));
|
||||
errmsg("no PostgreSQL user name specified in startup packet")));
|
||||
|
||||
/* The database defaults to the user name. */
|
||||
if (port->database_name == NULL || port->database_name[0] == '\0')
|
||||
@@ -1468,10 +1473,8 @@ processCancelRequest(Port *port, void *pkt)
|
||||
return;
|
||||
}
|
||||
else if (ExecBackend)
|
||||
{
|
||||
AttachSharedMemoryAndSemaphores();
|
||||
}
|
||||
|
||||
|
||||
/* See if we have a matching backend */
|
||||
|
||||
for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
|
||||
@@ -1590,7 +1593,7 @@ ConnFree(Port *conn)
|
||||
void
|
||||
ClosePostmasterPorts(bool pgstat_too)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
/* Close the listen sockets */
|
||||
for (i = 0; i < MAXLISTEN; i++)
|
||||
@@ -1639,7 +1642,7 @@ SIGHUP_handler(SIGNAL_ARGS)
|
||||
if (Shutdown <= SmartShutdown)
|
||||
{
|
||||
ereport(LOG,
|
||||
(errmsg("received SIGHUP, reloading configuration files")));
|
||||
(errmsg("received SIGHUP, reloading configuration files")));
|
||||
ProcessConfigFile(PGC_SIGHUP);
|
||||
#ifdef EXEC_BACKEND
|
||||
write_nondefault_variables(PGC_SIGHUP);
|
||||
@@ -1806,9 +1809,9 @@ reaper(SIGNAL_ARGS)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Check if this child was the statistics collector. If so,
|
||||
* try to start a new one. (If fail, we'll try again in
|
||||
* future cycles of the main loop.)
|
||||
* Check if this child was the statistics collector. If so, try to
|
||||
* start a new one. (If fail, we'll try again in future cycles of
|
||||
* the main loop.)
|
||||
*/
|
||||
if (pgstat_ispgstat(pid))
|
||||
{
|
||||
@@ -1883,7 +1886,7 @@ reaper(SIGNAL_ARGS)
|
||||
*/
|
||||
CleanupProc(pid, exitstatus);
|
||||
|
||||
} /* loop over pending child-death reports */
|
||||
} /* loop over pending child-death reports */
|
||||
#endif
|
||||
|
||||
if (FatalError)
|
||||
@@ -1895,7 +1898,7 @@ reaper(SIGNAL_ARGS)
|
||||
if (DLGetHead(BackendList) || StartupPID > 0 || ShutdownPID > 0)
|
||||
goto reaper_done;
|
||||
ereport(LOG,
|
||||
(errmsg("all server processes terminated; reinitializing")));
|
||||
(errmsg("all server processes terminated; reinitializing")));
|
||||
|
||||
shmem_exit(0);
|
||||
reset_shared(PostPortNumber);
|
||||
@@ -1979,11 +1982,11 @@ CleanupProc(int pid,
|
||||
if (!FatalError)
|
||||
{
|
||||
LogChildExit(LOG,
|
||||
(pid == CheckPointPID) ? gettext("checkpoint process") :
|
||||
(pid == CheckPointPID) ? gettext("checkpoint process") :
|
||||
gettext("server process"),
|
||||
pid, exitstatus);
|
||||
ereport(LOG,
|
||||
(errmsg("terminating any other active server processes")));
|
||||
(errmsg("terminating any other active server processes")));
|
||||
}
|
||||
|
||||
curr = DLGetHead(BackendList);
|
||||
@@ -2045,26 +2048,29 @@ LogChildExit(int lev, const char *procname, int pid, int exitstatus)
|
||||
{
|
||||
if (WIFEXITED(exitstatus))
|
||||
ereport(lev,
|
||||
/*
|
||||
* translator: %s is a noun phrase describing a child process,
|
||||
* such as "server process"
|
||||
*/
|
||||
|
||||
/*
|
||||
* translator: %s is a noun phrase describing a child process,
|
||||
* such as "server process"
|
||||
*/
|
||||
(errmsg("%s (pid %d) exited with exit code %d",
|
||||
procname, pid, WEXITSTATUS(exitstatus))));
|
||||
else if (WIFSIGNALED(exitstatus))
|
||||
ereport(lev,
|
||||
/*
|
||||
* translator: %s is a noun phrase describing a child process,
|
||||
* such as "server process"
|
||||
*/
|
||||
|
||||
/*
|
||||
* translator: %s is a noun phrase describing a child process,
|
||||
* such as "server process"
|
||||
*/
|
||||
(errmsg("%s (pid %d) was terminated by signal %d",
|
||||
procname, pid, WTERMSIG(exitstatus))));
|
||||
else
|
||||
ereport(lev,
|
||||
/*
|
||||
* translator: %s is a noun phrase describing a child process,
|
||||
* such as "server process"
|
||||
*/
|
||||
|
||||
/*
|
||||
* translator: %s is a noun phrase describing a child process,
|
||||
* such as "server process"
|
||||
*/
|
||||
(errmsg("%s (pid %d) exited with unexpected status %d",
|
||||
procname, pid, exitstatus)));
|
||||
}
|
||||
@@ -2195,7 +2201,7 @@ BackendStartup(Port *port)
|
||||
free(bn);
|
||||
errno = save_errno;
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork new process for connection: %m")));
|
||||
(errmsg("could not fork new process for connection: %m")));
|
||||
report_fork_failure_to_client(port, save_errno);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
@@ -2284,18 +2290,19 @@ split_opts(char **argv, int *argcp, char *s)
|
||||
static int
|
||||
BackendFork(Port *port)
|
||||
{
|
||||
char **av;
|
||||
int maxac;
|
||||
int ac;
|
||||
char **av;
|
||||
int maxac;
|
||||
int ac;
|
||||
char debugbuf[32];
|
||||
char protobuf[32];
|
||||
|
||||
#ifdef EXEC_BACKEND
|
||||
char pbuf[NAMEDATALEN + 256];
|
||||
#endif
|
||||
int i;
|
||||
int status;
|
||||
struct timeval now;
|
||||
struct timezone tz;
|
||||
int i;
|
||||
int status;
|
||||
struct timeval now;
|
||||
struct timezone tz;
|
||||
char remote_host[NI_MAXHOST];
|
||||
char remote_port[NI_MAXSERV];
|
||||
|
||||
@@ -2324,8 +2331,8 @@ BackendFork(Port *port)
|
||||
MyProcPid = getpid();
|
||||
|
||||
/*
|
||||
* Initialize libpq and enable reporting of ereport errors to the client.
|
||||
* Must do this now because authentication uses libpq to send
|
||||
* Initialize libpq and enable reporting of ereport errors to the
|
||||
* client. Must do this now because authentication uses libpq to send
|
||||
* messages.
|
||||
*/
|
||||
pq_init(); /* initialize libpq to talk to client */
|
||||
@@ -2350,7 +2357,7 @@ BackendFork(Port *port)
|
||||
if (getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_port),
|
||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
||||
{
|
||||
getnameinfo_all(&port->raddr.addr, port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
@@ -2366,7 +2373,7 @@ BackendFork(Port *port)
|
||||
if (LogSourcePort)
|
||||
{
|
||||
/* modify remote_host for use in ps status */
|
||||
char tmphost[NI_MAXHOST];
|
||||
char tmphost[NI_MAXHOST];
|
||||
|
||||
snprintf(tmphost, sizeof(tmphost), "%s:%s", remote_host, remote_port);
|
||||
StrNCpy(remote_host, tmphost, sizeof(remote_host));
|
||||
@@ -2484,14 +2491,15 @@ BackendFork(Port *port)
|
||||
*/
|
||||
av[ac++] = "-p";
|
||||
#ifdef EXEC_BACKEND
|
||||
Assert(UsedShmemSegID != 0 && UsedShmemSegAddr != NULL);
|
||||
Assert(UsedShmemSegID != 0 && UsedShmemSegAddr != NULL);
|
||||
/* database name at the end because it might contain commas */
|
||||
snprintf(pbuf, NAMEDATALEN + 256, "%d,%d,%d,%p,%s", port->sock, canAcceptConnections(),
|
||||
UsedShmemSegID, UsedShmemSegAddr, port->database_name);
|
||||
UsedShmemSegID, UsedShmemSegAddr, port->database_name);
|
||||
av[ac++] = pbuf;
|
||||
#else
|
||||
av[ac++] = port->database_name;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Pass the (insecure) option switches from the connection request.
|
||||
* (It's OK to mangle port->cmdline_options now.)
|
||||
@@ -2507,7 +2515,7 @@ BackendFork(Port *port)
|
||||
* Release postmaster's working memory context so that backend can
|
||||
* recycle the space. Note this does not trash *MyProcPort, because
|
||||
* ConnCreate() allocated that space with malloc() ... else we'd need
|
||||
* to copy the Port data here. Also, subsidiary data such as the
|
||||
* to copy the Port data here. Also, subsidiary data such as the
|
||||
* username isn't lost either; see ProcessStartupPacket().
|
||||
*/
|
||||
MemoryContextSwitchTo(TopMemoryContext);
|
||||
@@ -2565,21 +2573,21 @@ sigusr1_handler(SIGNAL_ARGS)
|
||||
if (CheckPointWarning != 0)
|
||||
{
|
||||
/*
|
||||
* This only times checkpoints forced by running out of
|
||||
* segment files. Other checkpoints could reduce
|
||||
* the frequency of forced checkpoints.
|
||||
* This only times checkpoints forced by running out of
|
||||
* segment files. Other checkpoints could reduce the
|
||||
* frequency of forced checkpoints.
|
||||
*/
|
||||
time_t now = time(NULL);
|
||||
time_t now = time(NULL);
|
||||
|
||||
if (LastSignalledCheckpoint != 0)
|
||||
{
|
||||
int elapsed_secs = now - LastSignalledCheckpoint;
|
||||
int elapsed_secs = now - LastSignalledCheckpoint;
|
||||
|
||||
if (elapsed_secs < CheckPointWarning)
|
||||
ereport(LOG,
|
||||
(errmsg("checkpoints are occurring too frequently (%d seconds apart)",
|
||||
elapsed_secs),
|
||||
errhint("Consider increasing CHECKPOINT_SEGMENTS.")));
|
||||
errhint("Consider increasing CHECKPOINT_SEGMENTS.")));
|
||||
}
|
||||
LastSignalledCheckpoint = now;
|
||||
}
|
||||
@@ -2763,6 +2771,7 @@ SSDataBase(int xlop)
|
||||
int ac = 0;
|
||||
char nbbuf[32];
|
||||
char xlbuf[32];
|
||||
|
||||
#ifdef EXEC_BACKEND
|
||||
char pbuf[NAMEDATALEN + 256];
|
||||
#endif
|
||||
@@ -2817,10 +2826,10 @@ SSDataBase(int xlop)
|
||||
|
||||
av[ac++] = "-p";
|
||||
#ifdef EXEC_BACKEND
|
||||
Assert(UsedShmemSegID != 0 && UsedShmemSegAddr != NULL);
|
||||
Assert(UsedShmemSegID != 0 && UsedShmemSegAddr != NULL);
|
||||
/* database name at the end because it might contain commas */
|
||||
snprintf(pbuf, NAMEDATALEN + 256, "%d,%p,%s", UsedShmemSegID,
|
||||
UsedShmemSegAddr, "template1");
|
||||
UsedShmemSegAddr, "template1");
|
||||
av[ac++] = pbuf;
|
||||
#else
|
||||
av[ac++] = "template1";
|
||||
@@ -2850,7 +2859,7 @@ SSDataBase(int xlop)
|
||||
break;
|
||||
case BS_XLOG_CHECKPOINT:
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork checkpoint process: %m")));
|
||||
(errmsg("could not fork checkpoint process: %m")));
|
||||
break;
|
||||
case BS_XLOG_SHUTDOWN:
|
||||
ereport(LOG,
|
||||
|
||||
Reference in New Issue
Block a user