diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 96d238c7242..622901a69d5 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.140 2007/08/21 01:11:13 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/aclchk.c,v 1.141 2007/10/12 18:55:11 tgl Exp $ * * NOTES * See acl.h. @@ -1905,14 +1905,7 @@ pg_tablespace_aclmask(Oid spc_oid, Oid roleid, Acl *acl; Oid ownerId; - /* - * Only shared relations can be stored in global space; don't let even - * superusers override this - */ - if (spc_oid == GLOBALTABLESPACE_OID && !IsBootstrapProcessingMode()) - return 0; - - /* Otherwise, superusers bypass all permission checking. */ + /* Superusers bypass all permission checking. */ if (superuser_arg(roleid)) return mask; diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index cbf05acfb83..ea985a635dd 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.323 2007/09/08 20:31:14 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.324 2007/10/12 18:55:11 tgl Exp $ * * * INTERFACE ROUTINES @@ -43,6 +43,7 @@ #include "catalog/pg_inherits.h" #include "catalog/pg_namespace.h" #include "catalog/pg_statistic.h" +#include "catalog/pg_tablespace.h" #include "catalog/pg_type.h" #include "commands/tablecmds.h" #include "commands/typecmds.h" @@ -833,6 +834,25 @@ heap_create_with_catalog(const char *relname, "with any existing type."))); } + /* + * Validate shared/non-shared tablespace (must check this before doing + * GetNewRelFileNode, to prevent Assert therein) + */ + if (shared_relation) + { + if (reltablespace != GLOBALTABLESPACE_OID) + /* elog since this is not a user-facing error */ + elog(ERROR, + "shared relations must be placed in pg_global tablespace"); + } + else + { + if (reltablespace == GLOBALTABLESPACE_OID) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("only shared relations can be placed in pg_global tablespace"))); + } + /* * Allocate an OID for the relation, unless we were told what to use. * diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 8137377e7a5..0e76bc9800d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.285 2007/09/20 17:56:30 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.286 2007/10/12 18:55:12 tgl Exp $ * * * INTERFACE ROUTINES @@ -36,6 +36,7 @@ #include "catalog/pg_constraint.h" #include "catalog/pg_operator.h" #include "catalog/pg_opclass.h" +#include "catalog/pg_tablespace.h" #include "catalog/pg_type.h" #include "executor/executor.h" #include "miscadmin.h" @@ -539,6 +540,25 @@ index_create(Oid heapRelationId, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("shared indexes cannot be created after initdb"))); + /* + * Validate shared/non-shared tablespace (must check this before doing + * GetNewRelFileNode, to prevent Assert therein) + */ + if (shared_relation) + { + if (tableSpaceId != GLOBALTABLESPACE_OID) + /* elog since this is not a user-facing error */ + elog(ERROR, + "shared relations must be placed in pg_global tablespace"); + } + else + { + if (tableSpaceId == GLOBALTABLESPACE_OID) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("only shared relations can be placed in pg_global tablespace"))); + } + if (get_relname_relid(indexRelationName, namespaceId)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 094f51b5cc9..434e9838947 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.199 2007/09/28 22:25:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.200 2007/10/12 18:55:12 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -302,6 +302,12 @@ createdb(const CreatedbStmt *stmt) aclcheck_error(aclresult, ACL_KIND_TABLESPACE, tablespacename); + /* pg_global must never be the default tablespace */ + if (dst_deftablespace == GLOBALTABLESPACE_OID) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("pg_global cannot be used as default tablespace"))); + /* * If we are trying to change the default tablespace of the template, * we require that the template not have any files in the new default diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index ea8d7f60898..0af90cb4ac6 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.233 2007/09/29 17:18:58 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.234 2007/10/12 18:55:12 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,7 @@ #include "catalog/pg_inherits.h" #include "catalog/pg_namespace.h" #include "catalog/pg_opclass.h" +#include "catalog/pg_tablespace.h" #include "catalog/pg_trigger.h" #include "catalog/pg_type.h" #include "catalog/toasting.h" @@ -5824,6 +5825,12 @@ ATExecSetTableSpace(Oid tableOid, Oid newTableSpace) errmsg("cannot move system relation \"%s\"", RelationGetRelationName(rel)))); + /* Can't move a non-shared relation into pg_global */ + if (newTableSpace == GLOBALTABLESPACE_OID) + ereport(ERROR, + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), + errmsg("only shared relations can be placed in pg_global tablespace"))); + /* * Don't allow moving temp tables of other backends ... their local buffer * manager is not going to cope.