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

Commit8362be3

Browse files
committed
Code review for superuser_reserved_connections patch. Don't try to do
database access outside a transaction; revert bogus performance improvementin SIBackendInit(); improve comments; add documentation (this part courtesyNeil Conway).
1 parent02d83d7 commit8362be3

File tree

5 files changed

+90
-63
lines changed

5 files changed

+90
-63
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.157 2002/11/2100:42:18 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.158 2002/11/2106:36:08 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1902,6 +1902,28 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
19021902
</listitem>
19031903
</varlistentry>
19041904

1905+
<varlistentry>
1906+
<term><varname>SUPERUSER_RESERVED_CONNECTIONS</varname>
1907+
(<type>integer</type>)</term>
1908+
<listitem>
1909+
<para>
1910+
Determines the number of <quote>connection slots</quote> that
1911+
are reserved for connections by <productname>PostgreSQL</>
1912+
superusers. At most <varname>max_connections</> connections can
1913+
ever be active simultaneously. Whenever the number of active
1914+
concurrent connections is at least <varname>max_connections</> minus
1915+
<varname>superuser_reserved_connections</varname>, new connections
1916+
will be accepted only from superuser accounts.
1917+
</para>
1918+
1919+
<para>
1920+
The default value is 2. The value must be less than the value of
1921+
<varname>max_connections</varname>. This parameter can only be
1922+
set at server start.
1923+
</para>
1924+
</listitem>
1925+
</varlistentry>
1926+
19051927
<varlistentry>
19061928
<term><varname>TCPIP_SOCKET</varname> (<type>boolean</type>)</term>
19071929
<listitem>
@@ -2952,24 +2974,25 @@ $ <userinput>kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`</userinput
29522974
</para>
29532975

29542976
<para>
2955-
With SSL support compiled in, the <productname>PostgreSQL</> server
2956-
can be started with SSL support by setting the parameter
2957-
<varname>ssl</varname> to on in
2958-
<filename>postgresql.conf</filename>. When starting in SSL mode,
2959-
the server will look for the files <filename>server.key</> and
2960-
<filename>server.crt</>in the data directory. These files should
2961-
contain the server private key and certificate respectively. These
2962-
files must be set up correctly before an SSL-enabled server can
2963-
start. If the private key is protected with a passphrase, the
2964-
server will prompt for thepassphrase andwillnot start until it
2965-
has been entered.
2977+
With<acronym>SSL</> support compiled in, the
2978+
<productname>PostgreSQL</> servercan be started with
2979+
<acronym>SSL</> support by setting the parameter
2980+
<varname>ssl</varname> to on in <filename>postgresql.conf</>. When
2981+
starting in <acronym>SSL</> mode,the server will look for the
2982+
files<filename>server.key</>and <filename>server.crt</> in the
2983+
data directory. These files shouldcontain the server private key
2984+
and certificate respectively. Thesefiles must be set up correctly
2985+
before an <acronym>SSL</>-enabled server canstart. If the private key is
2986+
protected with a passphrase, theserverwillprompt for the
2987+
passphrase and will not start until ithas been entered.
29662988
</para>
29672989

29682990
<para>
2969-
The server will listen for both standard and SSL connections on the
2970-
same TCP/IP port, and will negotiate with any connecting client on
2971-
whether to use SSL. See <xref linkend="client-authentication"> about
2972-
how to force the server to only use of SSL for certain connections.
2991+
The server will listen for both standard and <acronym>SSL</>
2992+
connections on the same TCP/IP port, and will negotiate with any
2993+
connecting client on whether to use <acronym>SSL</>. See <xref
2994+
linkend="client-authentication"> about how to force the server to
2995+
require use of <acronym>SSL</> for certain connections.
29732996
</para>
29742997

29752998
<para>

‎src/backend/postmaster/postmaster.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.298 2002/11/18 00:40:46 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.299 2002/11/21 06:36:08 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -154,12 +154,11 @@ intMaxBackends = DEF_MAXBACKENDS;
154154
/*
155155
* ReservedBackends is the number of backends reserved for superuser use.
156156
* This number is taken out of the pool size given by MaxBackends so
157-
* number of backend slots available to none super users is
158-
* (MaxBackends - ReservedBackends). Note, existing super user
159-
* connections are not taken into account once this lower limit has
160-
* been reached, i.e. superuser connections made before the lower limit
161-
* is reached always count towards that limit and are not taken from
162-
* ReservedBackends.
157+
* number of backend slots available to non-superusers is
158+
* (MaxBackends - ReservedBackends). Note what this really means is
159+
* "if there are <= ReservedBackends connections available, only superusers
160+
* can make new connections" --- pre-existing superuser connections don't
161+
* count against the limit.
163162
*/
164163
intReservedBackends=2;
165164

@@ -568,7 +567,15 @@ PostmasterMain(int argc, char *argv[])
568567
}
569568

570569
/*
571-
* Check for invalid combinations of switches
570+
* Now we can set the data directory, and then read postgresql.conf.
571+
*/
572+
checkDataDir(potential_DataDir);/* issues error messages */
573+
SetDataDir(potential_DataDir);
574+
575+
ProcessConfigFile(PGC_POSTMASTER);
576+
577+
/*
578+
* Check for invalid combinations of GUC settings.
572579
*/
573580
if (NBuffers<2*MaxBackends||NBuffers<16)
574581
{
@@ -581,16 +588,11 @@ PostmasterMain(int argc, char *argv[])
581588
ExitPostmaster(1);
582589
}
583590

584-
checkDataDir(potential_DataDir);/* issues error messages */
585-
SetDataDir(potential_DataDir);
586-
587-
ProcessConfigFile(PGC_POSTMASTER);
588-
589-
/*
590-
* Force an exit if ReservedBackends is not less than MaxBackends.
591-
*/
592591
if (ReservedBackends >=MaxBackends)
593-
elog(FATAL,"superuser_reserved_connections must be less than max_connections.");
592+
{
593+
postmaster_error("superuser_reserved_connections must be less than max_connections.");
594+
ExitPostmaster(1);
595+
}
594596

595597
/*
596598
* Now that we are done processing the postmaster arguments, reset

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.52 2002/09/04 20:31:25 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.53 2002/11/21 06:36:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -542,12 +542,11 @@ BackendIdGetProc(BackendId procId)
542542
/*
543543
* CountEmptyBackendSlots - count empty slots in backend process table
544544
*
545-
* Doesn't count since the procState array could be large and we've already
546-
* allowed for that by running a freeBackends counter in the SI segment.
547-
* Unlike CountActiveBackends() we do not need to interrogate the
548-
* backends to determine the free slot count.
549-
* Goes for a lock despite being a trival look up in case other backends
550-
* are busy starting or exiting since there is scope for confusion.
545+
* We don't actually need to count, since sinvaladt.c maintains a
546+
* freeBackends counter in the SI segment.
547+
*
548+
* Acquiring the lock here is almost certainly overkill, but just in
549+
* case fetching an int is not atomic on your machine ...
551550
*/
552551
int
553552
CountEmptyBackendSlots(void)

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

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.48 2002/08/29 21:02:12 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinvaladt.c,v 1.49 2002/11/21 06:36:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -92,13 +92,6 @@ SIBackendInit(SISeg *segP)
9292
intindex;
9393
ProcState*stateP=NULL;
9494

95-
if (segP->freeBackends==0)
96-
{
97-
/* out of procState slots */
98-
MyBackendId=InvalidBackendId;
99-
return0;
100-
}
101-
10295
/* Look for a free entry in the procState array */
10396
for (index=0;index<segP->lastBackend;index++)
10497
{
@@ -111,9 +104,18 @@ SIBackendInit(SISeg *segP)
111104

112105
if (stateP==NULL)
113106
{
114-
stateP=&segP->procState[segP->lastBackend];
115-
Assert(stateP->nextMsgNum<0);
116-
segP->lastBackend++;
107+
if (segP->lastBackend<segP->maxBackends)
108+
{
109+
stateP=&segP->procState[segP->lastBackend];
110+
Assert(stateP->nextMsgNum<0);
111+
segP->lastBackend++;
112+
}
113+
else
114+
{
115+
/* out of procState slots */
116+
MyBackendId=InvalidBackendId;
117+
return0;
118+
}
117119
}
118120

119121
MyBackendId= (stateP-&segP->procState[0])+1;

‎src/backend/utils/init/postinit.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.117 2002/10/03 19:19:09 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.118 2002/11/21 06:36:08 tgl Exp $
1212
*
1313
*
1414
*-------------------------------------------------------------------------
@@ -377,6 +377,18 @@ InitPostgres(const char *dbname, const char *username)
377377
*/
378378
RelationCacheInitializePhase3();
379379

380+
/*
381+
* Check a normal user hasn't connected to a superuser reserved slot.
382+
* We can't do this till after we've read the user information, and
383+
* we must do it inside a transaction since checking superuserness
384+
* may require database access. The superuser check is probably the
385+
* most expensive part; don't do it until necessary.
386+
*/
387+
if (ReservedBackends>0&&
388+
CountEmptyBackendSlots()<ReservedBackends&&
389+
!superuser())
390+
elog(FATAL,"Non-superuser connection limit exceeded");
391+
380392
/*
381393
* Initialize various default states that can't be set up until we've
382394
* selected the active user and done ReverifyMyDatabase.
@@ -397,17 +409,6 @@ InitPostgres(const char *dbname, const char *username)
397409
/* close the transaction we started above */
398410
if (!bootstrap)
399411
CommitTransactionCommand(true);
400-
401-
/*
402-
* Check a normal user hasn't connected to a superuser reserved slot.
403-
* Do this here since we need the user information and that only
404-
* happens after we've started bringing the shared memory online. So
405-
* we wait until we've registered exit handlers and potentially shut
406-
* an open transaction down for an as safety conscious rejection as
407-
* possible.
408-
*/
409-
if (CountEmptyBackendSlots()<ReservedBackends&& !superuser())
410-
elog(ERROR,"Non-superuser connection limit exceeded");
411412
}
412413

413414
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp