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 */
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 list isempty .
57+ * of the( explicit) list. If thelist is empty, there isno 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
6568static List * namespaceSearchPath = NIL ;
6669
6770/* this flag must be updated correctly when namespaceSearchPath is changed */
6871static bool pathContainsSystemNamespace = false;
6972
70- /* default place to create stuff */
71- static Oid defaultCreationNamespace = PG_CATALOG_NAMESPACE ;
73+ /* default place to create stuff; if InvalidOid, no default */
74+ static Oid defaultCreationNamespace = 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 */
207210namespaceId = defaultCreationNamespace ;
211+ if (!OidIsValid (namespaceId ))
212+ elog (ERROR ,"No namespace has been selected to create in" );
208213}
209214
210215return namespaceId ;
@@ -529,6 +534,8 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
529534{
530535/* use the default creation namespace */
531536namespaceId = 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)
10631070namespaceSearchPath );
10641071
10651072if (namespaceSearchPath == NIL )
1066- defaultCreationNamespace = PG_CATALOG_NAMESPACE ;
1073+ defaultCreationNamespace = InvalidOid ;
10671074else
10681075defaultCreationNamespace = (Oid )lfirsti (namespaceSearchPath );
10691076
@@ -1081,26 +1088,28 @@ assign_search_path(const char *newval)
10811088void
10821089InitializeSearchPath (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+ MemoryContext oldcxt ;
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}