aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-04-12 20:38:31 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-04-12 20:38:31 +0000
commit9999f5a10e722c052006886b678995695001958a (patch)
treeee8b463a3369b5b4283ebb5aa893549de7c3fc45 /src/backend/commands
parent79b60cb132824a4939178b3ce9ded5c220a0f179 (diff)
downloadpostgresql-9999f5a10e722c052006886b678995695001958a.tar.gz
postgresql-9999f5a10e722c052006886b678995695001958a.zip
Checking to decide whether relations are system relations now depends
on the namespace not the name; pg_ is not a reserved prefix for table names anymore. From Fernando Nasser.
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/analyze.c6
-rw-r--r--src/backend/commands/command.c26
-rw-r--r--src/backend/commands/creatinh.c5
-rw-r--r--src/backend/commands/indexcmds.c29
-rw-r--r--src/backend/commands/rename.c10
-rw-r--r--src/backend/commands/trigger.c6
-rw-r--r--src/backend/commands/vacuum.c4
7 files changed, 47 insertions, 39 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c
index ea778de3360..e36f21273d5 100644
--- a/src/backend/commands/analyze.c
+++ b/src/backend/commands/analyze.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.30 2002/04/02 01:03:05 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.31 2002/04/12 20:38:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -18,9 +18,9 @@
#include "access/heapam.h"
#include "access/tuptoaster.h"
+#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/indexing.h"
-#include "catalog/pg_namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_statistic.h"
#include "catalog/pg_type.h"
@@ -218,7 +218,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt)
/*
* We can ANALYZE any table except pg_statistic. See update_attstats
*/
- if (RelationGetNamespace(onerel) == PG_CATALOG_NAMESPACE &&
+ if (IsSystemNamespace(RelationGetNamespace(onerel)) &&
strcmp(RelationGetRelationName(onerel), StatisticRelationName) == 0)
{
relation_close(onerel, AccessShareLock);
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c
index c74d24cf7a5..c13b2aa67d4 100644
--- a/src/backend/commands/command.c
+++ b/src/backend/commands/command.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.173 2002/04/11 23:20:04 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.174 2002/04/12 20:38:20 tgl Exp $
*
* NOTES
* The PerformAddAttribute() code, like most of the relation
@@ -346,7 +346,7 @@ AlterTableAddColumn(Oid myrelid,
* normally, only the owner of a class can change its schema.
*/
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
if (!pg_class_ownercheck(myrelid, GetUserId()))
@@ -548,7 +548,7 @@ AlterTableAlterColumnDropNotNull(Oid myrelid,
RelationGetRelationName(rel));
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
@@ -699,7 +699,7 @@ AlterTableAlterColumnSetNotNull(Oid myrelid,
RelationGetRelationName(rel));
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
@@ -829,7 +829,7 @@ AlterTableAlterColumnDefault(Oid myrelid,
RelationGetRelationName(rel));
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
@@ -970,8 +970,8 @@ drop_default(Oid relid, int16 attnum)
*/
void
AlterTableAlterColumnFlags(Oid myrelid,
- bool inh, const char *colName,
- Node *flagValue, const char *flagType)
+ bool inh, const char *colName,
+ Node *flagValue, const char *flagType)
{
Relation rel;
int newtarget = 1;
@@ -989,9 +989,7 @@ AlterTableAlterColumnFlags(Oid myrelid,
/*
* we allow statistics case for system tables
*/
- if (*flagType != 'S' &&
- !allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ if (*flagType != 'S' && !allowSystemTableMods && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
@@ -1150,7 +1148,7 @@ AlterTableAddConstraint(Oid myrelid,
RelationGetRelationName(rel));
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
@@ -1476,7 +1474,7 @@ AlterTableDropConstraint(Oid myrelid,
RelationGetRelationName(rel));
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(rel)))
+ && IsSystemRelation(rel))
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
RelationGetRelationName(rel));
@@ -1952,6 +1950,10 @@ CreateSchemaCommand(CreateSchemaStmt *stmt)
owner_name, authId);
}
+ if (!allowSystemTableMods && IsReservedName(schemaName))
+ elog(ERROR, "CREATE SCHEMA: Illegal schema name: \"%s\" -- pg_ is reserved for system schemas",
+ schemaName);
+
/* Create the schema's namespace */
NamespaceCreate(schemaName, owner_userid);
diff --git a/src/backend/commands/creatinh.c b/src/backend/commands/creatinh.c
index 4a76e0c11ec..6a0cf811473 100644
--- a/src/backend/commands/creatinh.c
+++ b/src/backend/commands/creatinh.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.95 2002/03/31 06:26:30 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.96 2002/04/12 20:38:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -22,7 +22,6 @@
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_inherits.h"
-#include "catalog/pg_namespace.h"
#include "catalog/pg_type.h"
#include "commands/creatinh.h"
#include "miscadmin.h"
@@ -275,7 +274,7 @@ TruncateRelation(const RangeVar *relation)
elog(ERROR, "TRUNCATE cannot be used on views. '%s' is a view",
RelationGetRelationName(rel));
- if (!allowSystemTableMods && IsSystemRelationName(RelationGetRelationName(rel)))
+ if (!allowSystemTableMods && IsSystemRelation(rel))
elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table",
RelationGetRelationName(rel));
diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 0a8ddc1807c..297d5e72663 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.69 2002/04/11 19:59:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.70 2002/04/12 20:38:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -104,13 +104,13 @@ DefineIndex(RangeVar *heapRelation,
relationId = RelationGetRelid(rel);
- heap_close(rel, NoLock);
-
if (!IsBootstrapProcessingMode() &&
- IsSystemRelationName(heapRelation->relname) &&
+ IsSystemRelation(rel) &&
!IndexesAreActive(relationId, false))
elog(ERROR, "Existing indexes are inactive. REINDEX first");
+ heap_close(rel, NoLock);
+
/*
* look up the access method, verify it can handle the requested
* features
@@ -560,6 +560,16 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
indexRelation->relname,
((Form_pg_class) GETSTRUCT(tuple))->relkind);
+ if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
+ {
+ if (!allowSystemTableMods)
+ elog(ERROR, "\"%s\" is a system index. call REINDEX under standalone postgres with -O -P options",
+ indexRelation->relname);
+ if (!IsIgnoringSystemIndexes())
+ elog(ERROR, "\"%s\" is a system index. call REINDEX under standalone postgres with -P -O options",
+ indexRelation->relname);
+ }
+
ReleaseSysCache(tuple);
if (IsIgnoringSystemIndexes())
@@ -611,10 +621,6 @@ ReindexTable(RangeVar *relation, bool force)
/*
* ReindexDatabase
* Recreate indexes of a database.
- *
- * Exceptions:
- * "ERROR" if table nonexistent.
- * ...
*/
void
ReindexDatabase(const char *dbname, bool force, bool all)
@@ -638,6 +644,11 @@ ReindexDatabase(const char *dbname, bool force, bool all)
if (!(superuser() || is_dbadmin(MyDatabaseId)))
elog(ERROR, "REINDEX DATABASE: Permission denied.");
+ if (!allowSystemTableMods)
+ elog(ERROR, "must be called under standalone postgres with -O -P options");
+ if (!IsIgnoringSystemIndexes())
+ elog(ERROR, "must be called under standalone postgres with -P -O options");
+
/*
* We cannot run inside a user transaction block; if we were inside a
* transaction, then our commit- and start-transaction-command calls
@@ -668,7 +679,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
{
if (!all)
{
- if (!IsSystemRelationName(NameStr(((Form_pg_class) GETSTRUCT(tuple))->relname)))
+ if (!IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
continue;
}
if (((Form_pg_class) GETSTRUCT(tuple))->relkind == RELKIND_RELATION)
diff --git a/src/backend/commands/rename.c b/src/backend/commands/rename.c
index 5760cbe3004..21db59b7f6b 100644
--- a/src/backend/commands/rename.c
+++ b/src/backend/commands/rename.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.69 2002/04/05 11:58:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.70 2002/04/12 20:38:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -92,7 +92,7 @@ renameatt(Oid relid,
* normally, only the owner of a class can change its schema.
*/
if (!allowSystemTableMods
- && IsSystemRelationName(RelationGetRelationName(targetrelation)))
+ && IsSystemRelation(targetrelation))
elog(ERROR, "renameatt: class \"%s\" is a system catalog",
RelationGetRelationName(targetrelation));
if (!pg_class_ownercheck(relid, GetUserId()))
@@ -276,14 +276,10 @@ renamerel(Oid relid, const char *newrelname)
/* Validity checks */
if (!allowSystemTableMods &&
- IsSystemRelationName(RelationGetRelationName(targetrelation)))
+ IsSystemRelation(targetrelation))
elog(ERROR, "renamerel: system relation \"%s\" may not be renamed",
RelationGetRelationName(targetrelation));
- if (!allowSystemTableMods && IsSystemRelationName(newrelname))
- elog(ERROR, "renamerel: Illegal class name: \"%s\" -- pg_ is reserved for system catalogs",
- newrelname);
-
relkind = targetrelation->rd_rel->relkind;
relhastriggers = (targetrelation->rd_rel->reltriggers > 0);
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 72f13d3db49..891b9f3cfba 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.112 2002/04/09 20:35:48 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/trigger.c,v 1.113 2002/04/12 20:38:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -80,7 +80,7 @@ CreateTrigger(CreateTrigStmt *stmt)
elog(ERROR, "CreateTrigger: relation \"%s\" is not a table",
stmt->relation->relname);
- if (!allowSystemTableMods && IsSystemRelationName(stmt->relation->relname))
+ if (!allowSystemTableMods && IsSystemRelation(rel))
elog(ERROR, "CreateTrigger: can't create trigger for system relation %s",
stmt->relation->relname);
@@ -326,7 +326,7 @@ DropTrigger(Oid relid, const char *trigname)
elog(ERROR, "DropTrigger: relation \"%s\" is not a table",
RelationGetRelationName(rel));
- if (!allowSystemTableMods && IsSystemRelationName(RelationGetRelationName(rel)))
+ if (!allowSystemTableMods && IsSystemRelation(rel))
elog(ERROR, "DropTrigger: can't drop trigger for system relation %s",
RelationGetRelationName(rel));
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index ed3effab651..20a366d02ab 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -13,7 +13,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.222 2002/04/02 05:11:55 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.223 2002/04/12 20:38:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -806,7 +806,7 @@ full_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
bool reindex = false;
if (IsIgnoringSystemIndexes() &&
- IsSystemRelationName(RelationGetRelationName(onerel)))
+ IsSystemRelation(onerel))
reindex = true;
vacuum_set_xid_limits(vacstmt, onerel->rd_rel->relisshared,