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

Commitb66cbc1

Browse files
committed
Adjust rules for search_path so that pg_catalog is never implicitly
selected as the creation target namespace; to make that happen, youmust explicitly set search_path that way. This makes initdb a hairmore complex but seems like a good safety feature.
1 parentc2f1e93 commitb66cbc1

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 3 additions & 5 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.112 2002/04/03 05:39:29 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.113 2002/04/15 22:33:20 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1231,10 +1231,8 @@ dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
12311231
<para>
12321232
When objects are created without specifying a particular target
12331233
namespace, they will be placed in the first namespace listed
1234-
in the search path, or in <literal>pg_catalog</> if the search
1235-
path list is empty. (Note that users do not normally have
1236-
permission to write in <literal>pg_catalog</>, so an empty search
1237-
path is not a very useful setting.)
1234+
in the search path. An error is reported if the search path is
1235+
empty.
12381236
</para>
12391237

12401238
<para>

‎src/backend/catalog/namespace.c

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.8 2002/04/12 20:38:19 tgl Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.9 2002/04/15 22:33:21 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -54,21 +54,24 @@
5454
* thereby making it the default creation target namespace.)
5555
*
5656
* The default creation target namespace is kept equal to the first element
57-
* of the explicit list, or is thesystem namespace if the listisempty.
57+
* of the(explicit) list. If thelist is empty, thereisno default target.
5858
*
59-
* In bootstrap mode or a standalone backend, the default search path is
60-
* empty, so that the system namespace is the only one searched or inserted
61-
* into. In multiuser mode, the default search path contains the PG_PUBLIC
62-
* namespace, preceded by the user's own namespace if one exists.
59+
* In bootstrap mode, the search path is set equal to 'pg_catalog', so that
60+
* the system namespace is the only one searched or inserted into.
61+
* The initdb script is also careful to set search_path to 'pg_catalog' for
62+
* its post-bootstrap standalone backend runs. Otherwise the default search
63+
* path is determined by GUC. The factory default path contains the PUBLIC
64+
* namespace (if it exists), preceded by the user's personal namespace
65+
* (if one exists).
6366
*/
6467

6568
staticList*namespaceSearchPath=NIL;
6669

6770
/* this flag must be updated correctly when namespaceSearchPath is changed */
6871
staticboolpathContainsSystemNamespace= false;
6972

70-
/* default place to create stuff */
71-
staticOiddefaultCreationNamespace=PG_CATALOG_NAMESPACE;
73+
/* default place to create stuff; if InvalidOid, no default */
74+
staticOiddefaultCreationNamespace=InvalidOid;
7275

7376
/*
7477
* myTempNamespace is InvalidOid until and unless a TEMP namespace is set up
@@ -205,6 +208,8 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
205208
{
206209
/* use the default creation namespace */
207210
namespaceId=defaultCreationNamespace;
211+
if (!OidIsValid(namespaceId))
212+
elog(ERROR,"No namespace has been selected to create in");
208213
}
209214

210215
returnnamespaceId;
@@ -529,6 +534,8 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
529534
{
530535
/* use the default creation namespace */
531536
namespaceId=defaultCreationNamespace;
537+
if (!OidIsValid(namespaceId))
538+
elog(ERROR,"No namespace has been selected to create in");
532539
}
533540

534541
*objname_p=objname;
@@ -1063,7 +1070,7 @@ assign_search_path(const char *newval)
10631070
namespaceSearchPath);
10641071

10651072
if (namespaceSearchPath==NIL)
1066-
defaultCreationNamespace=PG_CATALOG_NAMESPACE;
1073+
defaultCreationNamespace=InvalidOid;
10671074
else
10681075
defaultCreationNamespace= (Oid)lfirsti(namespaceSearchPath);
10691076

@@ -1081,26 +1088,28 @@ assign_search_path(const char *newval)
10811088
void
10821089
InitializeSearchPath(void)
10831090
{
1084-
/*
1085-
* In normal multi-user mode, we want the default search path to be
1086-
* '$user,public' (or as much of that as exists, anyway; see the
1087-
* error handling in assign_search_path); which is what guc.c has as
1088-
* the wired-in default value. But in bootstrap or standalone-backend
1089-
* mode, the default search path must be empty so that initdb correctly
1090-
* creates everything in PG_CATALOG_NAMESPACE. Accordingly, adjust the
1091-
* default setting if we are not running under postmaster. (If a
1092-
* non-default setting has been supplied, this will not overwrite it.)
1093-
*/
1094-
if (!IsUnderPostmaster)
1091+
if (IsBootstrapProcessingMode())
1092+
{
1093+
/*
1094+
* In bootstrap mode, the search path must be 'pg_catalog' so that
1095+
* tables are created in the proper namespace; ignore the GUC setting.
1096+
*/
1097+
MemoryContextoldcxt;
1098+
1099+
oldcxt=MemoryContextSwitchTo(TopMemoryContext);
1100+
namespaceSearchPath=makeListi1(PG_CATALOG_NAMESPACE);
1101+
MemoryContextSwitchTo(oldcxt);
1102+
pathContainsSystemNamespace= true;
1103+
defaultCreationNamespace=PG_CATALOG_NAMESPACE;
1104+
}
1105+
else
10951106
{
1096-
SetConfigOption("search_path","",
1097-
PGC_POSTMASTER,PGC_S_DEFAULT);
1107+
/*
1108+
* If a search path setting was provided before we were able to
1109+
* execute lookups, establish the internal search path now.
1110+
*/
1111+
if (namespace_search_path&&*namespace_search_path&&
1112+
namespaceSearchPath==NIL)
1113+
assign_search_path(namespace_search_path);
10981114
}
1099-
/*
1100-
* If a search path setting was provided before we were able to execute
1101-
* lookups, establish the internal search path now.
1102-
*/
1103-
if (namespace_search_path&&*namespace_search_path&&
1104-
namespaceSearchPath==NIL)
1105-
assign_search_path(namespace_search_path);
11061115
}

‎src/bin/initdb/initdb.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
2828
# Portions Copyright (c) 1994, Regents of the University of California
2929
#
30-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.147 2002/04/04 04:25:50 momjian Exp $
30+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.148 2002/04/15 22:33:21 tgl Exp $
3131
#
3232
#-------------------------------------------------------------------------
3333

@@ -597,7 +597,7 @@ echo "ok"
597597
# To break an SQL command across lines in this script, backslash-escape all
598598
# internal newlines in the command.
599599

600-
PGSQL_OPT="$PGSQL_OPT -O"
600+
PGSQL_OPT="$PGSQL_OPT -O --search_path=pg_catalog"
601601

602602
$ECHO_N"initializing pg_shadow..."$ECHO_C
603603

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp