Fix postmaster to not try to start more than MaxBackendId children,
per patch from Tatsuo Ishii
This commit is contained in:
parent
bfa6d510b3
commit
36c1895533
|
@ -10,7 +10,7 @@
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.99 1999/01/17 06:18:34 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.100 1999/01/30 20:04:37 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTES
|
* NOTES
|
||||||
*
|
*
|
||||||
|
@ -244,6 +244,7 @@ static int initMasks(fd_set *rmask, fd_set *wmask);
|
||||||
static long PostmasterRandom(void);
|
static long PostmasterRandom(void);
|
||||||
static void RandomSalt(char *salt);
|
static void RandomSalt(char *salt);
|
||||||
static void SignalChildren(SIGNAL_ARGS);
|
static void SignalChildren(SIGNAL_ARGS);
|
||||||
|
static int CountChildren(void);
|
||||||
|
|
||||||
#ifdef CYR_RECODE
|
#ifdef CYR_RECODE
|
||||||
void GetCharSetByHost(char *, int, char *);
|
void GetCharSetByHost(char *, int, char *);
|
||||||
|
@ -667,8 +668,8 @@ ServerLoop(void)
|
||||||
{
|
{
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
fprintf(stderr, "%s: ServerLoop: select failed\n",
|
fprintf(stderr, "%s: ServerLoop: select failed: %s\n",
|
||||||
progname);
|
progname, strerror(errno));
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,19 +764,24 @@ ServerLoop(void)
|
||||||
|
|
||||||
if (status == STATUS_OK && port->pktInfo.state == Idle)
|
if (status == STATUS_OK && port->pktInfo.state == Idle)
|
||||||
{
|
{
|
||||||
|
/* Can't start backend if max backend count is exceeded. */
|
||||||
/*
|
if (CountChildren() >= MaxBackendId)
|
||||||
* If the backend start fails then keep the connection
|
|
||||||
* open to report it. Otherwise, pretend there is an
|
|
||||||
* error to close the connection which will now be managed
|
|
||||||
* by the backend.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (BackendStartup(port) != STATUS_OK)
|
|
||||||
PacketSendError(&port->pktInfo,
|
PacketSendError(&port->pktInfo,
|
||||||
"Backend startup failed");
|
"Sorry, too many clients already");
|
||||||
else
|
else
|
||||||
status = STATUS_ERROR;
|
{
|
||||||
|
/*
|
||||||
|
* If the backend start fails then keep the connection
|
||||||
|
* open to report it. Otherwise, pretend there is an
|
||||||
|
* error to close the connection which will now be managed
|
||||||
|
* by the backend.
|
||||||
|
*/
|
||||||
|
if (BackendStartup(port) != STATUS_OK)
|
||||||
|
PacketSendError(&port->pktInfo,
|
||||||
|
"Backend startup failed");
|
||||||
|
else
|
||||||
|
status = STATUS_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Close the connection if required. */
|
/* Close the connection if required. */
|
||||||
|
@ -1332,8 +1338,8 @@ BackendStartup(Port *port)
|
||||||
/* in parent */
|
/* in parent */
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s: BackendStartup: fork failed\n",
|
fprintf(stderr, "%s: BackendStartup: fork failed: %s\n",
|
||||||
progname);
|
progname, strerror(errno));
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1641,3 +1647,23 @@ PostmasterRandom(void)
|
||||||
|
|
||||||
return random() ^ random_seed;
|
return random() ^ random_seed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Count up number of child processes.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
CountChildren(void)
|
||||||
|
{
|
||||||
|
Dlelem *curr;
|
||||||
|
Backend *bp;
|
||||||
|
int mypid = getpid();
|
||||||
|
int cnt = 0;
|
||||||
|
|
||||||
|
for (curr = DLGetHead(BackendList); curr; curr = DLGetSucc(curr))
|
||||||
|
{
|
||||||
|
bp = (Backend *) DLE_VAL(curr);
|
||||||
|
if (bp->pid != mypid)
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue