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

Commit52667d5

Browse files
committed
Rethink the locking mechanisms used for CREATE/DROP/RENAME DATABASE.
The former approach used ExclusiveLock on pg_database, which being acluster-wide lock meant only one of these operations could proceed ata time; worse, it also blocked all incoming connections in ReverifyMyDatabase.Now that we have LockSharedObject(), we can use locks of different typesapplied to databases considered as objects. This allows much moreflexible management of the interlocking: two CREATE DATABASEs need notblock each other, and need not block connections except to the templatedatabase being used. Similarly DROP DATABASE doesn't block unrelatedoperations. The locking used in flatfiles.c is also much narrower inscope than before. Per recent proposal.
1 parentcb98e6f commit52667d5

File tree

9 files changed

+451
-405
lines changed

9 files changed

+451
-405
lines changed

‎doc/src/sgml/manage-ag.sgml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.45 2006/03/10 19:10:48 momjian Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/manage-ag.sgml,v 2.46 2006/05/04 16:07:28 tgl Exp $ -->
22

33
<chapter id="managing-databases">
44
<title>Managing Databases</title>
@@ -166,6 +166,7 @@ CREATE DATABASE <replaceable>dbname</> OWNER <replaceable>rolename</>;
166166
<programlisting>
167167
createdb -O <replaceable>rolename</> <replaceable>dbname</>
168168
</programlisting>
169+
from the shell.
169170
You must be a superuser to be allowed to create a database for
170171
someone else (that is, for a role you are not a member of).
171172
</para>
@@ -220,19 +221,15 @@ createdb -T template0 <replaceable>dbname</>
220221

221222
<para>
222223
It is possible to create additional template databases, and indeed
223-
onemight copy any database in a cluster by specifying its name
224+
onemay copy any database in a cluster by specifying its name
224225
as the template for <command>CREATE DATABASE</>. It is important to
225226
understand, however, that this is not (yet) intended as
226-
a general-purpose <quote><command>COPY DATABASE</command></quote> facility. In particular, it is
227-
essential that the source database be idle (no data-altering transactions
228-
in progress)
229-
for the duration of the copying operation. <command>CREATE DATABASE</>
230-
will check
231-
that no session (other than itself) is connected to
232-
the source database at the start of the operation, but this does not
233-
guarantee that changes cannot be made while the copy proceeds, which
234-
would result in an inconsistent copied database. Therefore,
235-
we recommend that databases used as templates be treated as read-only.
227+
a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
228+
The principal limitation is that no other sessions can be connected to
229+
the source database while it is being copied. <command>CREATE
230+
DATABASE</> will fail if any other connection exists when it starts;
231+
otherwise, new connections to the source database are locked out
232+
until <command>CREATE DATABASE</> completes.
236233
</para>
237234

238235
<para>

‎doc/src/sgml/ref/create_database.sgml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.44 2005/07/31 17:19:17 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_database.sgml,v 1.45 2006/05/04 16:07:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -45,7 +45,7 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
4545

4646
<para>
4747
Normally, the creator becomes the owner of the new database.
48-
Superusers can create databases owned by other users using the
48+
Superusers can create databases owned by other users, by using the
4949
<literal>OWNER</> clause. They can even create databases owned by
5050
users with no special privileges. Non-superusers with <literal>CREATEDB</>
5151
privilege can only create databases owned by themselves.
@@ -104,7 +104,8 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
104104
Character set encoding to use in the new database. Specify
105105
a string constant (e.g., <literal>'SQL_ASCII'</literal>),
106106
or an integer encoding number, or <literal>DEFAULT</literal>
107-
to use the default encoding. The character sets supported by the
107+
to use the default encoding (namely, the encoding of the
108+
template database). The character sets supported by the
108109
<productname>PostgreSQL</productname> server are described in
109110
<xref linkend="multibyte-charset-supported">.
110111
</para>
@@ -169,7 +170,11 @@ CREATE DATABASE <replaceable class="PARAMETER">name</replaceable>
169170
Although it is possible to copy a database other than <literal>template1</>
170171
by specifying its name as the template, this is not (yet) intended as
171172
a general-purpose <quote><command>COPY DATABASE</command></quote> facility.
172-
We recommend that databases used as templates be treated as read-only.
173+
The principal limitation is that no other sessions can be connected to
174+
the template database while it is being copied. <command>CREATE
175+
DATABASE</> will fail if any other connection exists when it starts;
176+
otherwise, new connections to the template database are locked out
177+
until <command>CREATE DATABASE</> completes.
173178
See <xref linkend="manage-ag-templatedbs"> for more information.
174179
</para>
175180

@@ -220,6 +225,16 @@ CREATE DATABASE music ENCODING 'LATIN1';
220225
implementation-defined.
221226
</para>
222227
</refsect1>
228+
229+
<refsect1>
230+
<title>See Also</title>
231+
232+
<simplelist type="inline">
233+
<member><xref linkend="sql-alterdatabase" endterm="sql-alterdatabase-title"></member>
234+
<member><xref linkend="sql-dropdatabase" endterm="sql-dropdatabase-title"></member>
235+
</simplelist>
236+
</refsect1>
237+
223238
</refentry>
224239

225240
<!-- Keep this comment at the end of the file

‎doc/src/sgml/ref/drop_database.sgml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_database.sgml,v 1.21 2005/11/22 15:24:17 adunstan Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/drop_database.sgml,v 1.22 2006/05/04 16:07:29 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -86,7 +86,7 @@ DROP DATABASE [ IF EXISTS ] <replaceable class="PARAMETER">name</replaceable>
8686
<title>Compatibility</title>
8787

8888
<para>
89-
The is no <command>DROP DATABASE</command> statement in the SQL standard.
89+
There is no <command>DROP DATABASE</command> statement in the SQL standard.
9090
</para>
9191
</refsect1>
9292

‎src/backend/catalog/pg_shdepend.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.8 2006/03/05 15:58:23 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.9 2006/05/04 16:07:29 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -37,7 +37,6 @@
3737
#include"lib/stringinfo.h"
3838
#include"miscadmin.h"
3939
#include"utils/fmgroids.h"
40-
#include"utils/inval.h"
4140
#include"utils/syscache.h"
4241

4342

@@ -911,12 +910,6 @@ shdepLockAndCheckObject(Oid classId, Oid objectId)
911910
/* AccessShareLock should be OK, since we are not modifying the object */
912911
LockSharedObject(classId,objectId,0,AccessShareLock);
913912

914-
/*
915-
* We have to recognize sinval updates here, else our local syscache may
916-
* still contain the object even if it was just dropped.
917-
*/
918-
AcceptInvalidationMessages();
919-
920913
switch (classId)
921914
{
922915
caseAuthIdRelationId:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp