]> granicus.if.org Git - postgresql/commitdiff
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 fc42ba83af3c6de9d40b90eed7584c5de1c62962..a3b2285ef5318bc5425585e7986249fac6433b37 100644 (file)
@@ -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,
index 5027fd1f92fa49204a45c8c24e21d51c1f40bf5f..f5f030695be51e603aee8b31cf0200f3cdeea162 100644 (file)
@@ -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);
        }
 
        /*
index b06079820ef9021958b399eca71e8e3f845d3433..3d543fa06c6a2268f9f9c959f61faaf2d403a9e3 100644 (file)
@@ -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;
index aab03ea4b3359f5e40a3b283f53abd7d24e56fc2..1d5a916c5447968588d824a9808b3ba591df4910 100644 (file)
@@ -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,
index 91f5eaecd9506ecb09de9e6c9a39df0c2797c284..7bf1d297a7a76b04021d2df5cb1218eb87df3ef4 100644 (file)
@@ -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,
index 9f5c008fa9f72e3d92fee9750e9b4c437dee736e..05b4a48be29adba98dbc2de483c01b71e686c274 100644 (file)
@@ -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,
index f7c8d46a23c6f81604c539622cc27521a80119da..0f3f3bcc8db14ddf3a90c0dab771febf062a1af7 100644 (file)
@@ -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
index d38bbd1ae0de65f0275d57fe9954908adebd0d33..02845920b951137eb61dac47fb952fd89e35a88c 100644 (file)
@@ -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,