Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite77b630

Browse files
committed
Allow maximum number of backends to be set at configure time
(--with-maxbackends). Add a postmaster switch (-N backends) that allowsthe limit to be reduced at postmaster start time. (You can't increase it,sorry to say, because there are still some fixed-size arrays.)Grab the number of semaphores indicated by min(MAXBACKENDS, -N) atpostmaster startup, so that this particular form of bogus configurationis exposed immediately rather than under heavy load.
1 parent612b843 commite77b630

File tree

14 files changed

+502
-392
lines changed

14 files changed

+502
-392
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.101 1999/02/13 23:17:40 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.102 1999/02/19 06:06:00 tgl Exp $
1414
*
1515
* NOTES
1616
*
@@ -162,8 +162,17 @@ static IpcMemoryKey ipc_key;
162162
* adding to this.
163163
*/
164164

165+
staticintMaxBackends=MAXBACKENDS;
165166

166-
staticintNextBackendId=MAXINT;/* XXX why? */
167+
/*
168+
* MaxBackends is the actual soft limit on the number of backends
169+
* we will start. It defaults to the hard limit established at compilation
170+
* time, but can be readjusted with postmaster's xxx switch.
171+
* One reason to reduce MaxBackends is to allow startup under a kernel
172+
* that won't let us get MAXBACKENDS semaphores!
173+
*/
174+
175+
staticintNextBackendTag=MAXINT;/* XXX why count down not up? */
167176
staticchar*progname= (char*)NULL;
168177
staticchar**real_argv;
169178
staticintreal_argc;
@@ -388,7 +397,7 @@ PostmasterMain(int argc, char *argv[])
388397
DataDir=getenv("PGDATA");/* default value */
389398

390399
opterr=0;
391-
while ((opt=getopt(nonblank_argc,argv,"A:a:B:b:D:dim:Mno:p:Ss"))!=EOF)
400+
while ((opt=getopt(nonblank_argc,argv,"A:a:B:b:D:dim:MN:no:p:Ss"))!=EOF)
392401
{
393402
switch (opt)
394403
{
@@ -463,6 +472,17 @@ PostmasterMain(int argc, char *argv[])
463472
* 'postmaster'
464473
*/
465474
break;
475+
case'N':
476+
/*
477+
* The max number of backends to start.
478+
* Can't set to less than 1 or more than compiled-in limit.
479+
*/
480+
MaxBackends=atoi(optarg);
481+
if (MaxBackends<1)
482+
MaxBackends=1;
483+
if (MaxBackends>MAXBACKENDS)
484+
MaxBackends=MAXBACKENDS;
485+
break;
466486
case'n':
467487
/* Don't reinit shared mem after abnormal exit */
468488
Reinit= false;
@@ -621,6 +641,8 @@ usage(const char *progname)
621641
fprintf(stderr,"\t-b backend\tuse a specific backend server executable\n");
622642
fprintf(stderr,"\t-d [1|2|3]\tset debugging level\n");
623643
fprintf(stderr,"\t-i \t\tlisten on TCP/IP sockets as well as Unix domain socket\n");
644+
fprintf(stderr,"\t-N nprocs\tset max number of backend servers (1..%d)\n",
645+
MAXBACKENDS);
624646
fprintf(stderr,"\t-n \t\tdon't reinitialize shared memory after abnormal exit\n");
625647
fprintf(stderr,"\t-o option\tpass 'option' to each backend servers\n");
626648
fprintf(stderr,"\t-p port\tspecify port for postmaster to listen on\n");
@@ -765,7 +787,7 @@ ServerLoop(void)
765787
if (status==STATUS_OK&&port->pktInfo.state==Idle)
766788
{
767789
/* Can't start backend if max backend count is exceeded. */
768-
if (CountChildren() >=MaxBackendId)
790+
if (CountChildren() >=MaxBackends)
769791
PacketSendError(&port->pktInfo,
770792
"Sorry, too many clients already");
771793
else
@@ -1009,7 +1031,7 @@ static void
10091031
reset_shared(shortport)
10101032
{
10111033
ipc_key=port*1000+shmem_seq*100;
1012-
CreateSharedMemoryAndSemaphores(ipc_key);
1034+
CreateSharedMemoryAndSemaphores(ipc_key,MaxBackends);
10131035
ActiveBackends= FALSE;
10141036
shmem_seq+=1;
10151037
if (shmem_seq >=10)
@@ -1272,7 +1294,7 @@ BackendStartup(Port *port)
12721294
*/
12731295
sprintf(envEntry[0],"POSTPORT=%d",PostPortName);
12741296
putenv(envEntry[0]);
1275-
sprintf(envEntry[1],"POSTID=%d",NextBackendId);
1297+
sprintf(envEntry[1],"POSTID=%d",NextBackendTag);
12761298
putenv(envEntry[1]);
12771299
sprintf(envEntry[2],"PG_USER=%s",port->user);
12781300
putenv(envEntry[2]);
@@ -1348,9 +1370,11 @@ BackendStartup(Port *port)
13481370
progname,pid,port->user,port->database,
13491371
port->sock);
13501372

1351-
/* adjust backend counter */
1352-
/* XXX Don't know why this is done, but for now backend needs it */
1353-
NextBackendId-=1;
1373+
/* Generate a new backend tag for every backend we start */
1374+
/* XXX theoretically this could wrap around, if you have the patience
1375+
* to start 2^31 backends ...
1376+
*/
1377+
NextBackendTag-=1;
13541378

13551379
/*
13561380
* Everything's been successful, it's safe to add this backend to our
@@ -1459,7 +1483,7 @@ DoBackend(Port *port)
14591483
/* OK, let's unblock our signals, all together now... */
14601484
sigprocmask(SIG_SETMASK,&oldsigmask,0);
14611485

1462-
/* Close thepostmater sockets */
1486+
/* Close thepostmaster sockets */
14631487
if (NetServer)
14641488
StreamClose(ServerSock_INET);
14651489
#ifndef__CYGWIN32__

‎src/backend/storage/ipc/ipci.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.18 1999/02/13 23:18:11 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.19 1999/02/19 06:06:04 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -44,17 +44,19 @@ SystemPortAddressCreateIPCKey(SystemPortAddress address)
4444
4545
CreateSharedMemoryAndSemaphores
4646
is called exactly *ONCE* by the postmaster.
47-
It is *NEVER* called by the postgres backend
47+
It is *NEVER* called by the postgres backend,
48+
except in the case of a standalone backend.
4849
4950
0) destroy any existing semaphores for both buffer
5051
and lock managers.
5152
1) create the appropriate *SHARED* memory segments
5253
for the two resource managers.
54+
2) create shared semaphores as needed.
5355
5456
**************************************************/
5557

5658
void
57-
CreateSharedMemoryAndSemaphores(IPCKeykey)
59+
CreateSharedMemoryAndSemaphores(IPCKeykey,intmaxBackends)
5860
{
5961
intsize;
6062

@@ -98,7 +100,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key)
98100
*do process table stuff
99101
* ----------------
100102
*/
101-
InitProcGlobal(key);
103+
InitProcGlobal(key,maxBackends);
102104
on_shmem_exit(ProcFreeAllSemaphores,NULL);
103105

104106
CreateSharedInvalidationState(key);
@@ -120,7 +122,7 @@ AttachSharedMemoryAndSemaphores(IPCKey key)
120122
*/
121123
if (key==PrivateIPCKey)
122124
{
123-
CreateSharedMemoryAndSemaphores(key);
125+
CreateSharedMemoryAndSemaphores(key,1);
124126
return;
125127
}
126128

‎src/backend/storage/ipc/sinvaladt.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.16 1999/02/13 23:18:16 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.17 1999/02/19 06:06:03 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -119,7 +119,7 @@ SIAssignBackendId(SISeg *segInOutP, BackendTag backendTag)
119119

120120
stateP=NULL;
121121

122-
for (index=0;index<MaxBackendId;index+=1)
122+
for (index=0;index<MAXBACKENDS;index++)
123123
{
124124
if (segInOutP->procState[index].tag==InvalidBackendTag||
125125
segInOutP->procState[index].tag==backendTag)
@@ -141,7 +141,7 @@ SIAssignBackendId(SISeg *segInOutP, BackendTag backendTag)
141141

142142
/* verify that all "procState" entries checked for matching tags */
143143

144-
for (index+=1;index<MaxBackendId;index+=1)
144+
for (index++;index<MAXBACKENDS;index++)
145145
{
146146
if (segInOutP->procState[index].tag==backendTag)
147147
{
@@ -565,7 +565,7 @@ SIDecProcLimit(SISeg *segP, int num)
565565
{
566566
inti;
567567

568-
for (i=0;i<MaxBackendId;i++)
568+
for (i=0;i<MAXBACKENDS;i++)
569569
{
570570
/* decrement only, if there is a limit > 0*/
571571
if (segP->procState[i].limit>0)
@@ -622,7 +622,7 @@ SISetProcStateInvalid(SISeg *segP)
622622
{
623623
inti;
624624

625-
for (i=0;i<MaxBackendId;i++)
625+
for (i=0;i<MAXBACKENDS;i++)
626626
{
627627
if (segP->procState[i].limit==0)
628628
{
@@ -696,7 +696,7 @@ SIDelExpiredDataEntries(SISeg *segP)
696696
h;
697697

698698
min=9999999;
699-
for (i=0;i<MaxBackendId;i++)
699+
for (i=0;i<MAXBACKENDS;i++)
700700
{
701701
h=SIGetProcStateLimit(segP,i);
702702
if (h >=0)
@@ -740,7 +740,7 @@ SISegInit(SISeg *segP)
740740
SISetEndEntryChain(segP,InvalidOffset);
741741
SISetNumEntries(segP,0);
742742
SISetMaxNumEntries(segP,MAXNUMMESSAGES);
743-
for (i=0;i<MaxBackendId;i++)
743+
for (i=0;i<MAXBACKENDS;i++)
744744
{
745745
segP->procState[i].limit=-1;/* no backend active !! */
746746
segP->procState[i].resetState= false;

‎src/backend/storage/lmgr/lock.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.41 1999/02/13 23:18:25 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.42 1999/02/19 06:06:06 tgl Exp $
1111
*
1212
* NOTES
1313
* Outside modules can create a lock table and acquire/release
@@ -1492,8 +1492,8 @@ LockShmemSize()
14921492
nXidBuckets=1 << (int)my_log2((NLOCKS_PER_XACT-1) /DEF_FFACTOR+1);
14931493
nXidSegs=1 << (int)my_log2((nLockBuckets-1) /DEF_SEGSIZE+1);
14941494

1495-
size+=MAXALIGN(NBACKENDS*sizeof(PROC));/* each MyProc */
1496-
size+=MAXALIGN(NBACKENDS*sizeof(LOCKMETHODCTL));/* each
1495+
size+=MAXALIGN(MAXBACKENDS*sizeof(PROC));/* each MyProc */
1496+
size+=MAXALIGN(MAXBACKENDS*sizeof(LOCKMETHODCTL));/* each
14971497
* lockMethodTable->ctl */
14981498
size+=MAXALIGN(sizeof(PROC_HDR));/* ProcGlobal */
14991499

@@ -1504,10 +1504,10 @@ LockShmemSize()
15041504
(MAXALIGN(sizeof(BUCKET_INDEX))+
15051505
MAXALIGN(sizeof(LOCK)));/* contains hash key */
15061506

1507-
size+=MAXALIGN(my_log2(NBACKENDS)*sizeof(void*));
1507+
size+=MAXALIGN(my_log2(MAXBACKENDS)*sizeof(void*));
15081508
size+=MAXALIGN(sizeof(HHDR));
15091509
size+=nXidSegs*MAXALIGN(DEF_SEGSIZE*sizeof(SEGMENT));
1510-
size+=NBACKENDS*/* XXX not multiple of BUCKET_ALLOC_INCR? */
1510+
size+=MAXBACKENDS*/* XXX not multiple of BUCKET_ALLOC_INCR? */
15111511
(MAXALIGN(sizeof(BUCKET_INDEX))+
15121512
MAXALIGN(sizeof(XIDLookupEnt)));/* contains hash key */
15131513

@@ -1552,7 +1552,7 @@ DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check)
15521552
HTAB*xidTable;
15531553
boolfound;
15541554

1555-
staticPROC*checked_procs[MaxBackendId];
1555+
staticPROC*checked_procs[MAXBACKENDS];
15561556
staticintnprocs;
15571557
staticboolMyNHolding;
15581558

@@ -1674,7 +1674,7 @@ DeadLockCheck(SHM_QUEUE *lockQueue, LOCK *findlock, bool skip_check)
16741674
if (j >=nprocs&&lock!=findlock)
16751675
{
16761676
checked_procs[nprocs++]=proc;
1677-
Assert(nprocs <=MaxBackendId);
1677+
Assert(nprocs <=MAXBACKENDS);
16781678

16791679
/*
16801680
* For non-MyProc entries, we are looking only

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp