mirror of
https://github.com/postgres/postgres.git
synced 2025-10-24 01:29:19 +03:00
Error message editing in backend/libpq, backend/postmaster, backend/tcop.
Along the way, fix some logic problems in pgstat_initstats, notably the bogus assumption that malloc returns zeroed memory.
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.37 2003/06/12 07:36:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.38 2003/07/22 19:00:10 tgl Exp $
|
||||
* ----------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@@ -81,13 +81,15 @@ static time_t last_pgstat_start_time;
|
||||
static long pgStatNumMessages = 0;
|
||||
|
||||
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;
|
||||
static int pgStatXactRollback = 0;
|
||||
|
||||
|
||||
static TransactionId pgStatDBHashXact = InvalidTransactionId;
|
||||
static HTAB *pgStatDBHash = NULL;
|
||||
static HTAB *pgStatBeDead = NULL;
|
||||
@@ -145,7 +147,7 @@ void
|
||||
pgstat_init(void)
|
||||
{
|
||||
ACCEPT_TYPE_ARG3 alen;
|
||||
struct addrinfo *addr, hints;
|
||||
struct addrinfo *addr = NULL, hints;
|
||||
int ret;
|
||||
|
||||
/*
|
||||
@@ -190,15 +192,18 @@ pgstat_init(void)
|
||||
ret = getaddrinfo2("localhost", NULL, &hints, &addr);
|
||||
if (ret || !addr)
|
||||
{
|
||||
elog(LOG, "PGSTAT: getaddrinfo2() failed: %s",
|
||||
gai_strerror(ret));
|
||||
ereport(LOG,
|
||||
(errmsg("getaddrinfo2(\"localhost\") failed: %s",
|
||||
gai_strerror(ret))));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
if ((pgStatSock = socket(addr->ai_family,
|
||||
addr->ai_socktype, addr->ai_protocol)) < 0)
|
||||
addr->ai_socktype, addr->ai_protocol)) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: socket() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not create socket for statistics: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -208,7 +213,9 @@ pgstat_init(void)
|
||||
*/
|
||||
if (bind(pgStatSock, addr->ai_addr, addr->ai_addrlen) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: bind() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not bind socket for statistics: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
freeaddrinfo2(hints.ai_family, addr);
|
||||
@@ -217,7 +224,9 @@ pgstat_init(void)
|
||||
alen = sizeof(pgStatAddr);
|
||||
if (getsockname(pgStatSock, (struct sockaddr *)&pgStatAddr, &alen) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: getsockname() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not get address of socket for statistics: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -229,7 +238,9 @@ pgstat_init(void)
|
||||
*/
|
||||
if (connect(pgStatSock, (struct sockaddr *) & pgStatAddr, alen) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: connect() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not connect socket for statistics: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -241,7 +252,9 @@ pgstat_init(void)
|
||||
*/
|
||||
if (FCNTL_NONBLOCK(pgStatSock) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: fcntl() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not set statistics socket to nonblock mode: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -250,7 +263,9 @@ pgstat_init(void)
|
||||
*/
|
||||
if (pipe(pgStatPmPipe) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: pipe() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not create pipe for statistics collector: %m")));
|
||||
goto startup_failed;
|
||||
}
|
||||
|
||||
@@ -258,9 +273,7 @@ pgstat_init(void)
|
||||
|
||||
startup_failed:
|
||||
if (addr)
|
||||
{
|
||||
freeaddrinfo2(hints.ai_family, addr);
|
||||
}
|
||||
|
||||
if (pgStatSock >= 0)
|
||||
closesocket(pgStatSock);
|
||||
@@ -312,7 +325,8 @@ pgstat_start(void)
|
||||
*/
|
||||
if (pgStatSock < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: statistics collector startup skipped");
|
||||
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.
|
||||
@@ -340,7 +354,8 @@ pgstat_start(void)
|
||||
/* Specific beos actions */
|
||||
beos_backend_startup_failed();
|
||||
#endif
|
||||
elog(LOG, "PGSTAT: fork() failed: %m");
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork statistics buffer: %m")));
|
||||
return;
|
||||
|
||||
case 0:
|
||||
@@ -744,7 +759,9 @@ pgstat_reset_counters(void)
|
||||
return;
|
||||
|
||||
if (!superuser())
|
||||
elog(ERROR, "Only database superusers can reset statistic counters");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
|
||||
errmsg("must be superuser to reset statistics counters")));
|
||||
|
||||
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_RESETCOUNTER);
|
||||
pgstat_send(&msg, sizeof(msg));
|
||||
@@ -802,32 +819,41 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
|
||||
}
|
||||
|
||||
/*
|
||||
* On the first of all calls initialize the message buffers.
|
||||
* On the first of all calls create some message buffers.
|
||||
*/
|
||||
if (pgStatTabstatAlloc == 0)
|
||||
if (pgStatTabstatMessages == NULL)
|
||||
{
|
||||
pgStatTabstatAlloc = 4;
|
||||
pgStatTabstatMessages = (PgStat_MsgTabstat **)
|
||||
malloc(sizeof(PgStat_MsgTabstat *) * pgStatTabstatAlloc);
|
||||
if (pgStatTabstatMessages == NULL)
|
||||
PgStat_MsgTabstat *newMessages;
|
||||
PgStat_MsgTabstat **msgArray;
|
||||
|
||||
newMessages = (PgStat_MsgTabstat *)
|
||||
malloc(sizeof(PgStat_MsgTabstat) * TABSTAT_QUANTUM);
|
||||
if (newMessages == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTATBE: malloc() failed");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < pgStatTabstatAlloc; i++)
|
||||
msgArray = (PgStat_MsgTabstat **)
|
||||
malloc(sizeof(PgStat_MsgTabstat *) * TABSTAT_QUANTUM);
|
||||
if (msgArray == NULL)
|
||||
{
|
||||
pgStatTabstatMessages[i] = (PgStat_MsgTabstat *)
|
||||
malloc(sizeof(PgStat_MsgTabstat));
|
||||
if (pgStatTabstatMessages[i] == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTATBE: malloc() failed");
|
||||
return;
|
||||
}
|
||||
free(newMessages);
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
return;
|
||||
}
|
||||
MemSet(newMessages, 0, sizeof(PgStat_MsgTabstat) * TABSTAT_QUANTUM);
|
||||
for (i = 0; i < TABSTAT_QUANTUM; i++)
|
||||
msgArray[i] = newMessages++;
|
||||
pgStatTabstatMessages = msgArray;
|
||||
pgStatTabstatAlloc = TABSTAT_QUANTUM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Lookup the so far used table slots for this relation.
|
||||
* Search the already-used message slots for this relation.
|
||||
*/
|
||||
for (mb = 0; mb < pgStatTabstatUsed; mb++)
|
||||
{
|
||||
@@ -849,7 +875,6 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
|
||||
*/
|
||||
i = pgStatTabstatMessages[mb]->m_nentries++;
|
||||
useent = &pgStatTabstatMessages[mb]->m_entry[i];
|
||||
memset(useent, 0, sizeof(PgStat_TableEntry));
|
||||
useent->t_id = rel_id;
|
||||
stats->tabentry = (void *) useent;
|
||||
return;
|
||||
@@ -860,27 +885,35 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
|
||||
*/
|
||||
if (pgStatTabstatUsed >= pgStatTabstatAlloc)
|
||||
{
|
||||
pgStatTabstatAlloc += 4;
|
||||
pgStatTabstatMessages = (PgStat_MsgTabstat **)
|
||||
realloc(pgStatTabstatMessages,
|
||||
sizeof(PgStat_MsgTabstat *) * pgStatTabstatAlloc);
|
||||
if (pgStatTabstatMessages == NULL)
|
||||
int newAlloc = pgStatTabstatAlloc + TABSTAT_QUANTUM;
|
||||
PgStat_MsgTabstat *newMessages;
|
||||
PgStat_MsgTabstat **msgArray;
|
||||
|
||||
newMessages = (PgStat_MsgTabstat *)
|
||||
malloc(sizeof(PgStat_MsgTabstat) * TABSTAT_QUANTUM);
|
||||
if (newMessages == NULL)
|
||||
{
|
||||
pgStatTabstatAlloc -= 4;
|
||||
elog(LOG, "PGSTATBE: malloc() failed");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
return;
|
||||
}
|
||||
for (i = pgStatTabstatUsed; i < pgStatTabstatAlloc; i++)
|
||||
msgArray = (PgStat_MsgTabstat **)
|
||||
realloc(pgStatTabstatMessages,
|
||||
sizeof(PgStat_MsgTabstat *) * newAlloc);
|
||||
if (msgArray == NULL)
|
||||
{
|
||||
pgStatTabstatMessages[i] = (PgStat_MsgTabstat *)
|
||||
malloc(sizeof(PgStat_MsgTabstat));
|
||||
if (pgStatTabstatMessages[i] == NULL)
|
||||
{
|
||||
pgStatTabstatAlloc -= 4;
|
||||
elog(LOG, "PGSTATBE: malloc() failed");
|
||||
return;
|
||||
}
|
||||
free(newMessages);
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
return;
|
||||
}
|
||||
MemSet(newMessages, 0, sizeof(PgStat_MsgTabstat) * TABSTAT_QUANTUM);
|
||||
for (i = 0; i < TABSTAT_QUANTUM; i++)
|
||||
msgArray[pgStatTabstatAlloc + i] = newMessages++;
|
||||
pgStatTabstatMessages = msgArray;
|
||||
pgStatTabstatAlloc = newAlloc;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -889,10 +922,8 @@ pgstat_initstats(PgStat_Info *stats, Relation rel)
|
||||
mb = pgStatTabstatUsed++;
|
||||
pgStatTabstatMessages[mb]->m_nentries = 1;
|
||||
useent = &pgStatTabstatMessages[mb]->m_entry[0];
|
||||
memset(useent, 0, sizeof(PgStat_TableEntry));
|
||||
useent->t_id = rel_id;
|
||||
stats->tabentry = (void *) useent;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1205,14 +1236,17 @@ pgstat_main(void)
|
||||
*/
|
||||
if (pipe(pgStatPipe) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: pipe() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not create pipe for statistics buffer: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
switch (fork())
|
||||
{
|
||||
case -1:
|
||||
elog(LOG, "PGSTAT: fork() failed: %m");
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork statistics collector: %m")));
|
||||
exit(1);
|
||||
|
||||
case 0:
|
||||
@@ -1266,7 +1300,10 @@ pgstat_main(void)
|
||||
&hash_ctl, HASH_ELEM | HASH_FUNCTION);
|
||||
if (pgStatBeDead == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Creation of dead backend hash table failed");
|
||||
/* assume the problem is out-of-memory */
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1277,7 +1314,8 @@ pgstat_main(void)
|
||||
sizeof(PgStat_StatBeEntry) * MaxBackends);
|
||||
if (pgStatBeTable == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Allocation of backend table failed");
|
||||
ereport(LOG,
|
||||
(errmsg("allocation of backend table failed")));
|
||||
exit(1);
|
||||
}
|
||||
memset(pgStatBeTable, 0, sizeof(PgStat_StatBeEntry) * MaxBackends);
|
||||
@@ -1341,7 +1379,9 @@ pgstat_main(void)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
elog(LOG, "PGSTAT: select() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("select failed in statistics collector: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1381,7 +1421,9 @@ pgstat_main(void)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
elog(LOG, "PGSTAT: read() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not read from statistics pipe: %m")));
|
||||
exit(1);
|
||||
}
|
||||
if (len == 0) /* EOF on the pipe! */
|
||||
@@ -1399,7 +1441,8 @@ pgstat_main(void)
|
||||
* sync with the buffer process somehow. Abort so
|
||||
* that we can restart both processes.
|
||||
*/
|
||||
elog(LOG, "PGSTAT: bogus message length");
|
||||
ereport(LOG,
|
||||
(errmsg("invalid statistics message length")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1549,7 +1592,9 @@ pgstat_recvbuffer(void)
|
||||
*/
|
||||
if (FCNTL_NONBLOCK(writePipe) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTATBUFF: fcntl() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("could not set statistics pipe to nonblock mode: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1559,7 +1604,9 @@ pgstat_recvbuffer(void)
|
||||
msgbuffer = (char *) malloc(PGSTAT_RECVBUFFERSZ);
|
||||
if (msgbuffer == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTATBUFF: malloc() failed");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1586,7 +1633,8 @@ pgstat_recvbuffer(void)
|
||||
{
|
||||
if (!overflow)
|
||||
{
|
||||
elog(LOG, "PGSTATBUFF: Warning - receive buffer full");
|
||||
ereport(LOG,
|
||||
(errmsg("statistics buffer is full")));
|
||||
overflow = true;
|
||||
}
|
||||
}
|
||||
@@ -1617,7 +1665,9 @@ pgstat_recvbuffer(void)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
elog(LOG, "PGSTATBUFF: select() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("select failed in statistics buffer: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1633,7 +1683,9 @@ pgstat_recvbuffer(void)
|
||||
(struct sockaddr *) &fromaddr, &fromlen);
|
||||
if (len < 0)
|
||||
{
|
||||
elog(LOG, "PGSTATBUFF: recvfrom() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("failed to read statistics message: %m")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1706,7 +1758,9 @@ pgstat_recvbuffer(void)
|
||||
{
|
||||
if (errno == EINTR || errno == EAGAIN)
|
||||
continue; /* not enough space in pipe */
|
||||
elog(LOG, "PGSTATBUFF: write() failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("failed to write statistics pipe: %m")));
|
||||
exit(1);
|
||||
}
|
||||
/* NB: len < xfr is okay */
|
||||
@@ -1759,7 +1813,8 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
|
||||
*/
|
||||
if (msg->m_backendid < 1 || msg->m_backendid > MaxBackends)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Invalid backend ID %d", msg->m_backendid);
|
||||
ereport(LOG,
|
||||
(errmsg("invalid backend ID %d", msg->m_backendid)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1817,7 +1872,9 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
|
||||
HASH_ENTER, &found);
|
||||
if (dbentry == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: DB hash table out of memory - abort");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1846,8 +1903,10 @@ pgstat_add_backend(PgStat_MsgHdr *msg)
|
||||
HASH_ELEM | HASH_FUNCTION);
|
||||
if (dbentry->tables == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: failed to initialize hash table for "
|
||||
"new database entry");
|
||||
/* assume the problem is out-of-memory */
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -1895,10 +1954,13 @@ pgstat_sub_backend(int procpid)
|
||||
*/
|
||||
deadbe = (PgStat_StatBeDead *) hash_search(pgStatBeDead,
|
||||
(void *) &procpid,
|
||||
HASH_ENTER, &found);
|
||||
HASH_ENTER,
|
||||
&found);
|
||||
if (deadbe == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: dead backend hash table out of memory");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
if (!found)
|
||||
@@ -1945,8 +2007,10 @@ pgstat_write_statsfile(void)
|
||||
fpout = fopen(pgStat_tmpfname, PG_BINARY_W);
|
||||
if (fpout == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: cannot open temp stats file %s: %m",
|
||||
pgStat_tmpfname);
|
||||
ereport(LOG,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("cannot write temp statistics file \"%s\": %m",
|
||||
pgStat_tmpfname)));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1971,8 +2035,9 @@ pgstat_write_statsfile(void)
|
||||
(void *) &(dbentry->databaseid),
|
||||
HASH_REMOVE, NULL) == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: database hash table corrupted "
|
||||
"during cleanup - abort");
|
||||
ereport(LOG,
|
||||
(errmsg("database hash table corrupted "
|
||||
"during cleanup --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -2007,10 +2072,11 @@ pgstat_write_statsfile(void)
|
||||
(void *) &(tabentry->tableid),
|
||||
HASH_REMOVE, NULL) == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: tables hash table for "
|
||||
"database %d corrupted during "
|
||||
"cleanup - abort",
|
||||
dbentry->databaseid);
|
||||
ereport(LOG,
|
||||
(errmsg("tables hash table for "
|
||||
"database %u corrupted during "
|
||||
"cleanup --- abort",
|
||||
dbentry->databaseid)));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -2049,20 +2115,24 @@ pgstat_write_statsfile(void)
|
||||
|
||||
/*
|
||||
* No more output to be done. Close the temp file and replace the old
|
||||
* pgstat.stat with it's content.
|
||||
* pgstat.stat with it.
|
||||
*/
|
||||
fputc('E', fpout);
|
||||
if (fclose(fpout) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Error closing temp stats file %s: %m",
|
||||
pgStat_tmpfname);
|
||||
ereport(LOG,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not write temp statistics file \"%s\": %m",
|
||||
pgStat_tmpfname)));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (rename(pgStat_tmpfname, pgStat_fname) < 0)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Cannot rename temp stats file %s: %m",
|
||||
pgStat_fname);
|
||||
ereport(LOG,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not rename temp statistics file \"%s\" to \"%s\": %m",
|
||||
pgStat_tmpfname, pgStat_fname)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2082,8 +2152,9 @@ pgstat_write_statsfile(void)
|
||||
(void *) &(deadbe->procpid),
|
||||
HASH_REMOVE, NULL) == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: dead backend hash table corrupted "
|
||||
"during cleanup - abort");
|
||||
ereport(LOG,
|
||||
(errmsg("dead-backend hash table corrupted "
|
||||
"during cleanup --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -2145,13 +2216,18 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
HASH_ELEM | HASH_FUNCTION | mcxt_flags);
|
||||
if (*dbhash == NULL)
|
||||
{
|
||||
/* assume the problem is out-of-memory */
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Creation of DB hash table failed");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
/* in backend, can do normal error */
|
||||
elog(ERROR, "PGSTAT: Creation of DB hash table failed");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2187,18 +2263,10 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
case 'D':
|
||||
if (fread(&dbbuf, 1, sizeof(dbbuf), fpin) != sizeof(dbbuf))
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2206,34 +2274,31 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
*/
|
||||
dbentry = (PgStat_StatDBEntry *) hash_search(*dbhash,
|
||||
(void *) &dbbuf.databaseid,
|
||||
HASH_ENTER, &found);
|
||||
HASH_ENTER,
|
||||
&found);
|
||||
if (dbentry == NULL)
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: DB hash table out of memory");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(fpin);
|
||||
elog(ERROR, "PGSTAT: DB hash table out of memory");
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(dbentry, &dbbuf, sizeof(PgStat_StatDBEntry));
|
||||
@@ -2247,7 +2312,6 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
if (onlydb != InvalidOid && onlydb != dbbuf.databaseid)
|
||||
break;
|
||||
|
||||
|
||||
memset(&hash_ctl, 0, sizeof(hash_ctl));
|
||||
hash_ctl.keysize = sizeof(Oid);
|
||||
hash_ctl.entrysize = sizeof(PgStat_StatTabEntry);
|
||||
@@ -2259,18 +2323,19 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
HASH_ELEM | HASH_FUNCTION | mcxt_flags);
|
||||
if (dbentry->tables == NULL)
|
||||
{
|
||||
/* assume the problem is out-of-memory */
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: failed to initialize "
|
||||
"hash table for new database entry");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(fpin);
|
||||
elog(ERROR, "PGSTAT: failed to initialize "
|
||||
"hash table for new database entry");
|
||||
}
|
||||
/* in backend, can do normal error */
|
||||
fclose(fpin);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2293,18 +2358,10 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
case 'T':
|
||||
if (fread(&tabbuf, 1, sizeof(tabbuf), fpin) != sizeof(tabbuf))
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2320,30 +2377,24 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: Tab hash table out of memory");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fclose(fpin);
|
||||
elog(ERROR, "PGSTAT: Tab hash table out of memory");
|
||||
}
|
||||
/* in backend, can do normal error */
|
||||
fclose(fpin);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(tabentry, &tabbuf, sizeof(tabbuf));
|
||||
@@ -2361,18 +2412,10 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
if (fread(&maxbackends, 1, sizeof(maxbackends), fpin) !=
|
||||
sizeof(maxbackends))
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
if (maxbackends == 0)
|
||||
{
|
||||
@@ -2415,18 +2458,10 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
sizeof(PgStat_StatBeEntry), fpin) !=
|
||||
sizeof(PgStat_StatBeEntry))
|
||||
{
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2456,18 +2491,10 @@ pgstat_read_statsfile(HTAB **dbhash, Oid onlydb,
|
||||
return;
|
||||
|
||||
default:
|
||||
if (pgStatRunningInCollector)
|
||||
{
|
||||
elog(LOG, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(WARNING, "PGSTAT: corrupted pgstat.stat file");
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
ereport(pgStatRunningInCollector ? LOG : WARNING,
|
||||
(errmsg("corrupted pgstat.stat file")));
|
||||
fclose(fpin);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2579,8 +2606,9 @@ pgstat_recv_tabstat(PgStat_MsgTabstat *msg, int len)
|
||||
HASH_ENTER, &found);
|
||||
if (tabentry == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: tables hash table out of memory for "
|
||||
"database %d - abort", dbentry->databaseid);
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory in statistics collector --- abort")));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -2759,8 +2787,10 @@ pgstat_recv_resetcounter(PgStat_MsgResetcounter *msg, int len)
|
||||
HASH_ELEM | HASH_FUNCTION);
|
||||
if (dbentry->tables == NULL)
|
||||
{
|
||||
elog(LOG, "PGSTAT: failed to reinitialize hash table for "
|
||||
"database entry");
|
||||
/* assume the problem is out-of-memory */
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
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.333 2003/06/12 07:36:51 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.334 2003/07/22 19:00:10 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -327,10 +327,15 @@ checkDataDir(const char *checkdir)
|
||||
if (stat(checkdir, &stat_buf) == -1)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
elog(FATAL, "data directory %s was not found", checkdir);
|
||||
ereport(FATAL,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("data directory \"%s\" does not exist",
|
||||
checkdir)));
|
||||
else
|
||||
elog(FATAL, "could not read permissions of directory %s: %m",
|
||||
checkdir);
|
||||
ereport(FATAL,
|
||||
(errcode_for_file_access(),
|
||||
errmsg("could not read permissions of directory \"%s\": %m",
|
||||
checkdir)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -342,8 +347,11 @@ checkDataDir(const char *checkdir)
|
||||
*/
|
||||
#if !defined(__CYGWIN__) && !defined(WIN32)
|
||||
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
|
||||
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)",
|
||||
checkdir);
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
|
||||
errmsg("data directory \"%s\" has group or world access",
|
||||
checkdir),
|
||||
errdetail("permissions should be u=rwx (0700)")));
|
||||
#endif
|
||||
|
||||
/* Look for PG_VERSION before looking for pg_control */
|
||||
@@ -560,9 +568,15 @@ PostmasterMain(int argc, char *argv[])
|
||||
if (!value)
|
||||
{
|
||||
if (opt == '-')
|
||||
elog(ERROR, "--%s requires argument", optarg);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("--%s requires a value",
|
||||
optarg)));
|
||||
else
|
||||
elog(ERROR, "-c %s requires argument", optarg);
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_SYNTAX_ERROR),
|
||||
errmsg("-c %s requires a value",
|
||||
optarg)));
|
||||
}
|
||||
|
||||
SetConfigOption(name, value, PGC_POSTMASTER, PGC_S_ARGV);
|
||||
@@ -654,8 +668,9 @@ PostmasterMain(int argc, char *argv[])
|
||||
* On some systems our dynloader code needs the executable's pathname.
|
||||
*/
|
||||
if (FindExec(pg_pathname, progname, "postgres") < 0)
|
||||
elog(FATAL, "%s: could not locate executable, bailing out...",
|
||||
progname);
|
||||
ereport(FATAL,
|
||||
(errmsg("%s: could not locate postgres executable",
|
||||
progname)));
|
||||
|
||||
/*
|
||||
* Initialize SSL library, if specified.
|
||||
@@ -830,7 +845,7 @@ PostmasterMain(int argc, char *argv[])
|
||||
|
||||
/*
|
||||
* Reset whereToSendOutput from Debug (its starting state) to None.
|
||||
* This prevents elog from sending log messages to stderr unless 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.
|
||||
@@ -1049,7 +1064,9 @@ ServerLoop(void)
|
||||
PG_SETMASK(&BlockSig);
|
||||
if (errno == EINTR || errno == EWOULDBLOCK)
|
||||
continue;
|
||||
elog(LOG, "ServerLoop: select failed: %m");
|
||||
ereport(LOG,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("select failed in postmaster: %m")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -1138,10 +1155,10 @@ initMasks(fd_set *rmask, fd_set *wmask)
|
||||
/*
|
||||
* Read the startup packet and do something according to it.
|
||||
*
|
||||
* Returns STATUS_OK or STATUS_ERROR, or might call elog(FATAL) and
|
||||
* Returns STATUS_OK or STATUS_ERROR, or might call ereport(FATAL) and
|
||||
* not return at all.
|
||||
*
|
||||
* (Note that elog(FATAL) stuff is sent to the client, so only use it
|
||||
* (Note that ereport(FATAL) stuff is sent to the client, so only use it
|
||||
* if that's what you want. Return STATUS_ERROR if you don't want to
|
||||
* send anything to the client, which would typically be appropriate
|
||||
* if we detect a communications failure.)
|
||||
@@ -1163,7 +1180,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
* so don't clutter the log with a complaint.
|
||||
*/
|
||||
if (!SSLdone)
|
||||
elog(COMMERROR, "incomplete startup packet");
|
||||
ereport(COMMERROR,
|
||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||
errmsg("incomplete startup packet")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -1173,7 +1192,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
if (len < (int32) sizeof(ProtocolVersion) ||
|
||||
len > MAX_STARTUP_PACKET_LENGTH)
|
||||
{
|
||||
elog(COMMERROR, "invalid length of startup packet");
|
||||
ereport(COMMERROR,
|
||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||
errmsg("invalid length of startup packet")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -1190,7 +1211,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
|
||||
if (pq_getbytes(buf, len) == EOF)
|
||||
{
|
||||
elog(COMMERROR, "incomplete startup packet");
|
||||
ereport(COMMERROR,
|
||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||
errmsg("incomplete startup packet")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -1221,7 +1244,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
#endif
|
||||
if (send(port->sock, &SSLok, 1, 0) != 1)
|
||||
{
|
||||
elog(COMMERROR, "failed to send SSL negotiation response: %m");
|
||||
ereport(COMMERROR,
|
||||
(errcode_for_socket_access(),
|
||||
errmsg("failed to send SSL negotiation response: %m")));
|
||||
return STATUS_ERROR; /* close the connection */
|
||||
}
|
||||
|
||||
@@ -1237,7 +1262,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
/* Could add additional special packet types here */
|
||||
|
||||
/*
|
||||
* Set FrontendProtocol now so that elog() knows what format to send
|
||||
* Set FrontendProtocol now so that ereport() knows what format to send
|
||||
* if we fail during startup.
|
||||
*/
|
||||
FrontendProtocol = proto;
|
||||
@@ -1248,11 +1273,13 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
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)))
|
||||
elog(FATAL, "unsupported frontend protocol %u.%u: server supports %u.0 to %u.%u",
|
||||
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));
|
||||
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(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
|
||||
@@ -1309,7 +1336,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
* given packet length, complain.
|
||||
*/
|
||||
if (offset != len-1)
|
||||
elog(FATAL, "invalid startup packet layout: expected terminator as last byte");
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||
errmsg("invalid startup packet layout: expected terminator as last byte")));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1335,7 +1364,9 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
|
||||
/* Check a user name was given. */
|
||||
if (port->user_name == NULL || port->user_name[0] == '\0')
|
||||
elog(FATAL, "no PostgreSQL user name specified in startup packet");
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION),
|
||||
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')
|
||||
@@ -1388,16 +1419,24 @@ ProcessStartupPacket(Port *port, bool SSLdone)
|
||||
switch (cac)
|
||||
{
|
||||
case CAC_STARTUP:
|
||||
elog(FATAL, "The database system is starting up");
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||
errmsg("the database system is starting up")));
|
||||
break;
|
||||
case CAC_SHUTDOWN:
|
||||
elog(FATAL, "The database system is shutting down");
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||
errmsg("the database system is shutting down")));
|
||||
break;
|
||||
case CAC_RECOVERY:
|
||||
elog(FATAL, "The database system is in recovery mode");
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_CANNOT_CONNECT_NOW),
|
||||
errmsg("the database system is in recovery mode")));
|
||||
break;
|
||||
case CAC_TOOMANY:
|
||||
elog(FATAL, "Sorry, too many clients already");
|
||||
ereport(FATAL,
|
||||
(errcode(ERRCODE_TOO_MANY_CONNECTIONS),
|
||||
errmsg("sorry, too many clients already")));
|
||||
break;
|
||||
case CAC_OK:
|
||||
default:
|
||||
@@ -1427,7 +1466,8 @@ processCancelRequest(Port *port, void *pkt)
|
||||
|
||||
if (backendPID == CheckPointPID)
|
||||
{
|
||||
elog(DEBUG2, "processCancelRequest: CheckPointPID in cancel request for process %d", backendPID);
|
||||
elog(DEBUG2, "ignoring cancel request for checkpoint process %d",
|
||||
backendPID);
|
||||
return;
|
||||
}
|
||||
else if (ExecBackend)
|
||||
@@ -1501,7 +1541,9 @@ ConnCreate(int serverFd)
|
||||
|
||||
if (!(port = (Port *) calloc(1, sizeof(Port))))
|
||||
{
|
||||
elog(LOG, "ConnCreate: malloc failed");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
SignalChildren(SIGQUIT);
|
||||
ExitPostmaster(1);
|
||||
}
|
||||
@@ -1600,7 +1642,8 @@ SIGHUP_handler(SIGNAL_ARGS)
|
||||
|
||||
if (Shutdown <= SmartShutdown)
|
||||
{
|
||||
elog(LOG, "Received SIGHUP, reloading configuration files");
|
||||
ereport(LOG,
|
||||
(errmsg("received SIGHUP, reloading configuration files")));
|
||||
ProcessConfigFile(PGC_SIGHUP);
|
||||
#ifdef EXEC_BACKEND
|
||||
write_nondefault_variables(PGC_SIGHUP);
|
||||
@@ -1627,7 +1670,7 @@ pmdie(SIGNAL_ARGS)
|
||||
|
||||
PG_SETMASK(&BlockSig);
|
||||
|
||||
elog(DEBUG2, "pmdie %d", postgres_signal_arg);
|
||||
elog(DEBUG2, "postmaster received signal %d", postgres_signal_arg);
|
||||
|
||||
switch (postgres_signal_arg)
|
||||
{
|
||||
@@ -1641,7 +1684,8 @@ pmdie(SIGNAL_ARGS)
|
||||
if (Shutdown >= SmartShutdown)
|
||||
break;
|
||||
Shutdown = SmartShutdown;
|
||||
elog(LOG, "smart shutdown request");
|
||||
ereport(LOG,
|
||||
(errmsg("received smart shutdown request")));
|
||||
if (DLGetHead(BackendList)) /* let reaper() handle this */
|
||||
break;
|
||||
|
||||
@@ -1671,13 +1715,15 @@ pmdie(SIGNAL_ARGS)
|
||||
*/
|
||||
if (Shutdown >= FastShutdown)
|
||||
break;
|
||||
elog(LOG, "fast shutdown request");
|
||||
ereport(LOG,
|
||||
(errmsg("received fast shutdown request")));
|
||||
if (DLGetHead(BackendList)) /* let reaper() handle this */
|
||||
{
|
||||
Shutdown = FastShutdown;
|
||||
if (!FatalError)
|
||||
{
|
||||
elog(LOG, "aborting any active transactions");
|
||||
ereport(LOG,
|
||||
(errmsg("aborting any active transactions")));
|
||||
SignalChildren(SIGTERM);
|
||||
}
|
||||
break;
|
||||
@@ -1713,7 +1759,8 @@ pmdie(SIGNAL_ARGS)
|
||||
* abort all children with SIGQUIT and exit without attempt to
|
||||
* properly shutdown data base system.
|
||||
*/
|
||||
elog(LOG, "immediate shutdown request");
|
||||
ereport(LOG,
|
||||
(errmsg("received immediate shutdown request")));
|
||||
if (ShutdownPID > 0)
|
||||
kill(ShutdownPID, SIGQUIT);
|
||||
if (StartupPID > 0)
|
||||
@@ -1795,7 +1842,8 @@ reaper(SIGNAL_ARGS)
|
||||
{
|
||||
LogChildExit(LOG, gettext("startup process"),
|
||||
pid, exitstatus);
|
||||
elog(LOG, "aborting startup due to startup process failure");
|
||||
ereport(LOG,
|
||||
(errmsg("aborting startup due to startup process failure")));
|
||||
ExitPostmaster(1);
|
||||
}
|
||||
StartupPID = 0;
|
||||
@@ -1849,7 +1897,8 @@ reaper(SIGNAL_ARGS)
|
||||
*/
|
||||
if (DLGetHead(BackendList) || StartupPID > 0 || ShutdownPID > 0)
|
||||
goto reaper_done;
|
||||
elog(LOG, "all server processes terminated; reinitializing shared memory and semaphores");
|
||||
ereport(LOG,
|
||||
(errmsg("all server processes terminated; reinitializing")));
|
||||
|
||||
shmem_exit(0);
|
||||
reset_shared(PostPortNumber);
|
||||
@@ -1936,7 +1985,8 @@ CleanupProc(int pid,
|
||||
(pid == CheckPointPID) ? gettext("checkpoint process") :
|
||||
gettext("server process"),
|
||||
pid, exitstatus);
|
||||
elog(LOG, "terminating any other active server processes");
|
||||
ereport(LOG,
|
||||
(errmsg("terminating any other active server processes")));
|
||||
}
|
||||
|
||||
curr = DLGetHead(BackendList);
|
||||
@@ -1957,7 +2007,7 @@ CleanupProc(int pid,
|
||||
*/
|
||||
if (!FatalError)
|
||||
{
|
||||
elog(DEBUG2, "CleanupProc: sending %s to process %d",
|
||||
elog(DEBUG2, "sending %s to process %d",
|
||||
(SendStop ? "SIGSTOP" : "SIGQUIT"), (int) bp->pid);
|
||||
kill(bp->pid, (SendStop ? SIGSTOP : SIGQUIT));
|
||||
}
|
||||
@@ -1996,19 +2046,30 @@ CleanupProc(int pid,
|
||||
static void
|
||||
LogChildExit(int lev, const char *procname, int pid, int exitstatus)
|
||||
{
|
||||
/*
|
||||
* translator: the first %s in these messages is a noun phrase
|
||||
* describing a child process, such as "server process"
|
||||
*/
|
||||
if (WIFEXITED(exitstatus))
|
||||
elog(lev, "%s (pid %d) exited with exit code %d",
|
||||
procname, pid, WEXITSTATUS(exitstatus));
|
||||
ereport(lev,
|
||||
/*
|
||||
* 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))
|
||||
elog(lev, "%s (pid %d) was terminated by signal %d",
|
||||
procname, pid, WTERMSIG(exitstatus));
|
||||
ereport(lev,
|
||||
/*
|
||||
* 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
|
||||
elog(lev, "%s (pid %d) exited with unexpected status %d",
|
||||
procname, pid, exitstatus);
|
||||
ereport(lev,
|
||||
/*
|
||||
* 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)));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2029,7 +2090,7 @@ SignalChildren(int signal)
|
||||
|
||||
if (bp->pid != MyProcPid)
|
||||
{
|
||||
elog(DEBUG2, "SignalChildren: sending signal %d to process %d",
|
||||
elog(DEBUG2, "sending signal %d to process %d",
|
||||
signal, (int) bp->pid);
|
||||
kill(bp->pid, signal);
|
||||
}
|
||||
@@ -2067,7 +2128,9 @@ BackendStartup(Port *port)
|
||||
bn = (Backend *) malloc(sizeof(Backend));
|
||||
if (!bn)
|
||||
{
|
||||
elog(LOG, "out of memory; connection startup aborted");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
@@ -2118,7 +2181,8 @@ BackendStartup(Port *port)
|
||||
status = BackendFork(port);
|
||||
|
||||
if (status != 0)
|
||||
elog(LOG, "connection startup failed");
|
||||
ereport(LOG,
|
||||
(errmsg("connection startup failed")));
|
||||
proc_exit(status);
|
||||
}
|
||||
|
||||
@@ -2132,15 +2196,16 @@ BackendStartup(Port *port)
|
||||
beos_backend_startup_failed();
|
||||
#endif
|
||||
free(bn);
|
||||
elog(LOG, "connection startup failed (fork failure): %s",
|
||||
strerror(save_errno));
|
||||
errno = save_errno;
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork new process for connection: %m")));
|
||||
report_fork_failure_to_client(port, save_errno);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
/* in parent, normal */
|
||||
elog(DEBUG2, "BackendStartup: forked pid=%d socket=%d", (int) pid,
|
||||
port->sock);
|
||||
elog(DEBUG2, "forked new backend, pid=%d socket=%d",
|
||||
(int) pid, port->sock);
|
||||
|
||||
/*
|
||||
* Everything's been successful, it's safe to add this backend to our
|
||||
@@ -2166,9 +2231,9 @@ report_fork_failure_to_client(Port *port, int errnum)
|
||||
{
|
||||
char buffer[1000];
|
||||
|
||||
/* Format the error message packet */
|
||||
/* Format the error message packet (always V2 protocol) */
|
||||
snprintf(buffer, sizeof(buffer), "E%s%s\n",
|
||||
gettext("Server process fork() failed: "),
|
||||
gettext("could not fork new process for connection: "),
|
||||
strerror(errnum));
|
||||
|
||||
/* Set port to non-blocking. Don't do send() if this fails */
|
||||
@@ -2262,12 +2327,12 @@ BackendFork(Port *port)
|
||||
MyProcPid = getpid();
|
||||
|
||||
/*
|
||||
* Initialize libpq and enable reporting of elog errors to the client.
|
||||
* 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 */
|
||||
whereToSendOutput = Remote; /* now safe to elog to client */
|
||||
whereToSendOutput = Remote; /* now safe to ereport to client */
|
||||
|
||||
/*
|
||||
* We arrange for a simple exit(0) if we receive SIGTERM or SIGQUIT
|
||||
@@ -2286,10 +2351,10 @@ BackendFork(Port *port)
|
||||
remote_host[0] = '\0';
|
||||
remote_port[0] = '\0';
|
||||
if (!getnameinfo((struct sockaddr *)&port->raddr.addr,
|
||||
port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_host),
|
||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
||||
port->raddr.salen,
|
||||
remote_host, sizeof(remote_host),
|
||||
remote_port, sizeof(remote_host),
|
||||
(log_hostname ? 0 : NI_NUMERICHOST) | NI_NUMERICSERV))
|
||||
{
|
||||
getnameinfo((struct sockaddr *)&port->raddr.addr,
|
||||
port->raddr.salen,
|
||||
@@ -2299,21 +2364,17 @@ BackendFork(Port *port)
|
||||
}
|
||||
|
||||
if (Log_connections)
|
||||
{
|
||||
elog(LOG, "connection received: host=%s port=%s",
|
||||
remote_host, remote_port);
|
||||
}
|
||||
ereport(LOG,
|
||||
(errmsg("connection received: host=%s port=%s",
|
||||
remote_host, remote_port)));
|
||||
|
||||
if (LogSourcePort)
|
||||
{
|
||||
/* modify remote_host for use in ps status */
|
||||
int slen = strlen(remote_host) + 10;
|
||||
char *str = palloc(slen);
|
||||
char tmphost[sizeof(remote_host) + 10];
|
||||
|
||||
snprintf(str, slen, "%s:%s", remote_host, remote_port);
|
||||
strncpy(remote_host, str, sizeof(remote_host));
|
||||
remote_host[sizeof(remote_host) - 1] = '\0';
|
||||
pfree(str);
|
||||
snprintf(tmphost, sizeof(tmphost), "%s:%s", remote_host, remote_port);
|
||||
StrNCpy(remote_host, tmphost, sizeof(remote_host));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2332,7 +2393,7 @@ BackendFork(Port *port)
|
||||
* indefinitely. PreAuthDelay doesn't count against the time limit.
|
||||
*/
|
||||
if (!enable_sig_alarm(AuthenticationTimeout * 1000, false))
|
||||
elog(FATAL, "BackendFork: Unable to set timer for auth timeout");
|
||||
elog(FATAL, "could not set timer for authorization timeout");
|
||||
|
||||
/*
|
||||
* Receive the startup packet (which might turn out to be a cancel
|
||||
@@ -2361,12 +2422,13 @@ BackendFork(Port *port)
|
||||
* SIGTERM/SIGQUIT again until backend startup is complete.
|
||||
*/
|
||||
if (!disable_sig_alarm(false))
|
||||
elog(FATAL, "BackendFork: Unable to disable timer for auth timeout");
|
||||
elog(FATAL, "could not disable timer for authorization timeout");
|
||||
PG_SETMASK(&BlockSig);
|
||||
|
||||
if (Log_connections)
|
||||
elog(LOG, "connection authorized: user=%s database=%s",
|
||||
port->user_name, port->database_name);
|
||||
ereport(LOG,
|
||||
(errmsg("connection authorized: user=%s database=%s",
|
||||
port->user_name, port->database_name)));
|
||||
|
||||
/*
|
||||
* Don't want backend to be able to see the postmaster random number
|
||||
@@ -2519,9 +2581,10 @@ sigusr1_handler(SIGNAL_ARGS)
|
||||
int elapsed_secs = now - LastSignalledCheckpoint;
|
||||
|
||||
if (elapsed_secs < CheckPointWarning)
|
||||
elog(LOG, "Checkpoint segments are being created too frequently (%d secs)"
|
||||
"\n\tConsider increasing CHECKPOINT_SEGMENTS",
|
||||
elapsed_secs);
|
||||
ereport(LOG,
|
||||
(errmsg("checkpoints are occurring too frequently (%d seconds apart)",
|
||||
elapsed_secs),
|
||||
errhint("Consider increasing CHECKPOINT_SEGMENTS.")));
|
||||
}
|
||||
LastSignalledCheckpoint = now;
|
||||
}
|
||||
@@ -2787,15 +2850,20 @@ SSDataBase(int xlop)
|
||||
switch (xlop)
|
||||
{
|
||||
case BS_XLOG_STARTUP:
|
||||
elog(LOG, "could not launch startup process (fork failure): %m");
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork startup process: %m")));
|
||||
break;
|
||||
case BS_XLOG_CHECKPOINT:
|
||||
elog(LOG, "could not launch checkpoint process (fork failure): %m");
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork checkpoint process: %m")));
|
||||
break;
|
||||
case BS_XLOG_SHUTDOWN:
|
||||
elog(LOG, "could not launch shutdown process (fork failure): %m");
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork shutdown process: %m")));
|
||||
break;
|
||||
default:
|
||||
ereport(LOG,
|
||||
(errmsg("could not fork process: %m")));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -2817,7 +2885,9 @@ SSDataBase(int xlop)
|
||||
{
|
||||
if (!(bn = (Backend *) malloc(sizeof(Backend))))
|
||||
{
|
||||
elog(LOG, "CheckPointDataBase: malloc failed");
|
||||
ereport(LOG,
|
||||
(errcode(ERRCODE_OUT_OF_MEMORY),
|
||||
errmsg("out of memory")));
|
||||
ExitPostmaster(1);
|
||||
}
|
||||
|
||||
@@ -2857,7 +2927,7 @@ CreateOptsFile(int argc, char *argv[])
|
||||
|
||||
if ((fp = fopen(filename, "w")) == NULL)
|
||||
{
|
||||
postmaster_error("cannot create file %s: %s",
|
||||
postmaster_error("cannot create file \"%s\": %s",
|
||||
filename, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
@@ -2880,7 +2950,7 @@ CreateOptsFile(int argc, char *argv[])
|
||||
|
||||
/*
|
||||
* This should be used only for reporting "interactive" errors (ie, errors
|
||||
* during startup. Once the postmaster is launched, use elog.
|
||||
* during startup). Once the postmaster is launched, use ereport.
|
||||
*/
|
||||
void
|
||||
postmaster_error(const char *fmt,...)
|
||||
|
||||
Reference in New Issue
Block a user