From f26b91761bd25f9da2f97d818f60ae68588888c2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 26 Aug 2005 03:08:15 +0000 Subject: [PATCH] Arrange for indexes and toast tables to inherit their ownership from the parent table, even if the command that creates them is executed by someone else (such as a superuser or a member of the owning role). Per gripe from Michael Fuhr. --- src/backend/bootstrap/bootparse.y | 4 +++- src/backend/catalog/heap.c | 10 +++++++--- src/backend/catalog/index.c | 4 ++-- src/backend/commands/cluster.c | 3 ++- src/backend/commands/tablecmds.c | 4 +++- src/backend/executor/execMain.c | 3 ++- src/backend/utils/cache/relcache.c | 5 ++++- src/include/catalog/heap.h | 3 ++- 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/backend/bootstrap/bootparse.y b/src/backend/bootstrap/bootparse.y index fc42ba83af..a3b2285ef5 100644 --- a/src/backend/bootstrap/bootparse.y +++ b/src/backend/bootstrap/bootparse.y @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.77 2005/06/29 22:51:54 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/bootstrap/bootparse.y,v 1.78 2005/08/26 03:07:00 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,7 @@ #include "catalog/heap.h" #include "catalog/pg_am.h" #include "catalog/pg_attribute.h" +#include "catalog/pg_authid.h" #include "catalog/pg_class.h" #include "catalog/pg_namespace.h" #include "catalog/pg_tablespace.h" @@ -199,6 +200,7 @@ Boot_CreateStmt: PG_CATALOG_NAMESPACE, $3 ? GLOBALTABLESPACE_OID : 0, $6, + BOOTSTRAP_SUPERUSERID, tupdesc, RELKIND_RELATION, $3, diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 5027fd1f92..f5f030695b 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.289 2005/08/12 01:35:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/heap.c,v 1.290 2005/08/26 03:07:12 tgl Exp $ * * * INTERFACE ROUTINES @@ -65,6 +65,7 @@ static void AddNewRelationTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Oid new_type_oid, + Oid relowner, char relkind); static Oid AddNewRelationType(const char *typeName, Oid typeNamespace, @@ -555,6 +556,7 @@ AddNewRelationTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Oid new_type_oid, + Oid relowner, char relkind) { Form_pg_class new_rel_reltup; @@ -587,7 +589,7 @@ AddNewRelationTuple(Relation pg_class_desc, break; } - new_rel_reltup->relowner = GetUserId(); + new_rel_reltup->relowner = relowner; new_rel_reltup->reltype = new_type_oid; new_rel_reltup->relkind = relkind; @@ -665,6 +667,7 @@ heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, + Oid ownerid, TupleDesc tupdesc, char relkind, bool shared_relation, @@ -740,6 +743,7 @@ heap_create_with_catalog(const char *relname, new_rel_desc, relid, new_type_oid, + ownerid, relkind); /* @@ -769,7 +773,7 @@ heap_create_with_catalog(const char *relname, referenced.objectSubId = 0; recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); - recordDependencyOnOwner(RelationRelationId, relid, GetUserId()); + recordDependencyOnOwner(RelationRelationId, relid, ownerid); } /* diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index b06079820e..3d543fa06c 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.259 2005/08/12 01:35:56 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/catalog/index.c,v 1.260 2005/08/26 03:07:12 tgl Exp $ * * * INTERFACE ROUTINES @@ -562,7 +562,7 @@ index_create(Oid heapRelationId, * * XXX should have a cleaner way to create cataloged indexes */ - indexRelation->rd_rel->relowner = GetUserId(); + indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relkind = RELKIND_INDEX; indexRelation->rd_rel->relhasoids = false; diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index aab03ea4b3..1d5a916c54 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.138 2005/05/10 13:16:26 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.139 2005/08/26 03:07:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -577,6 +577,7 @@ make_new_heap(Oid OIDOldHeap, const char *NewName, Oid NewTableSpace) RelationGetNamespace(OldHeap), NewTableSpace, InvalidOid, + OldHeap->rd_rel->relowner, tupdesc, OldHeap->rd_rel->relkind, OldHeap->rd_rel->relisshared, diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 91f5eaecd9..7bf1d297a7 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.169 2005/08/23 22:40:07 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.170 2005/08/26 03:07:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -427,6 +427,7 @@ DefineRelation(CreateStmt *stmt, char relkind) namespaceId, tablespaceId, InvalidOid, + GetUserId(), descriptor, relkind, false, @@ -5946,6 +5947,7 @@ AlterTableCreateToastTable(Oid relOid, bool silent) PG_TOAST_NAMESPACE, rel->rd_rel->reltablespace, InvalidOid, + rel->rd_rel->relowner, tupdesc, RELKIND_TOASTVALUE, shared_relation, diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 9f5c008fa9..05b4a48be2 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -26,7 +26,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.254 2005/08/20 00:39:55 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/execMain.c,v 1.255 2005/08/26 03:07:25 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -759,6 +759,7 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly) namespaceId, InvalidOid, InvalidOid, + GetUserId(), tupdesc, RELKIND_RELATION, false, diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index f7c8d46a23..0f3f3bcc8d 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.227 2005/08/12 01:35:59 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.228 2005/08/26 03:07:48 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -39,6 +39,7 @@ #include "catalog/pg_amproc.h" #include "catalog/pg_attrdef.h" #include "catalog/pg_attribute.h" +#include "catalog/pg_authid.h" #include "catalog/pg_constraint.h" #include "catalog/pg_index.h" #include "catalog/pg_namespace.h" @@ -2074,6 +2075,8 @@ RelationBuildLocalRelation(const char *relname, rel->rd_rel->relhasoids = rel->rd_att->tdhasoid; rel->rd_rel->relnatts = natts; rel->rd_rel->reltype = InvalidOid; + /* needed when bootstrapping: */ + rel->rd_rel->relowner = BOOTSTRAP_SUPERUSERID; /* * Insert relation physical and logical identifiers (OIDs) into the diff --git a/src/include/catalog/heap.h b/src/include/catalog/heap.h index d38bbd1ae0..02845920b9 100644 --- a/src/include/catalog/heap.h +++ b/src/include/catalog/heap.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/heap.h,v 1.74 2005/04/14 01:38:20 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/heap.h,v 1.75 2005/08/26 03:08:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,6 +48,7 @@ extern Oid heap_create_with_catalog(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, + Oid ownerid, TupleDesc tupdesc, char relkind, bool shared_relation, -- 2.40.0