Arrange for indexes and toast tables to inherit their ownership from
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 26 Aug 2005 03:08:15 +0000 (03:08 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 26 Aug 2005 03:08:15 +0000 (03:08 +0000)
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
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/commands/cluster.c
src/backend/commands/tablecmds.c
src/backend/executor/execMain.c
src/backend/utils/cache/relcache.c
src/include/catalog/heap.h

index 6f68fb8dd011f10ca00f436318ae322a31bd014a..791441ee7ecb753b0c8af9116011e7509c033633 100644 (file)
@@ -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,
index 92a1f41070d88c4e907a1289ce603d1cf5b8454f..d19aae3f2a83281073d68a0007ed45167443ff48 100644 (file)
@@ -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);
        }
 
        /*
index 85581d54b071b1981e1a1623340514540f11f636..e86ff75f149faa0c21e23cf64d8a45d22029c7b7 100644 (file)
@@ -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;
index 9e31b4cba59302a5282f4a583c47e73fb4779766..147164f9116a9a562fbb30ca24824f9d4b8dd7b6 100644 (file)
@@ -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,
index 69c02442b4996e6fb1e12f2cd9a4ea67b67af7ae..469240ad55ed54fee44895367a817318860af357 100644 (file)
@@ -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,
index 9aa49595aae805c1080d2c793b3a887e67039246..fdfea23d706e6b8fa2f5bb159e212dd0532f54d0 100644 (file)
@@ -759,6 +759,7 @@ InitPlan(QueryDesc *queryDesc, bool explainOnly)
                                                                                                  namespaceId,
                                                                                                  InvalidOid,
                                                                                                  InvalidOid,
+                                                                                                 GetUserId(),
                                                                                                  tupdesc,
                                                                                                  RELKIND_RELATION,
                                                                                                  false,
index 28b56cb7c5d211a0d8322124f7f3caf252d235cf..85c29f76057c500a657a3f79318fe8cf6746757d 100644 (file)
@@ -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
index 52ea118f43a462a4bec10b9ca788e1df7e3e9c9a..4ef8c00afff292e17f004725e268b7f852a0fad8 100644 (file)
@@ -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,