1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

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.
This commit is contained in:
Tom Lane
2002-04-12 20:38:31 +00:00
parent 79b60cb132
commit 9999f5a10e
22 changed files with 198 additions and 126 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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));

View File

@@ -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)

View File

@@ -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);

View File

@@ -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));

View File

@@ -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,