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.
This commit is contained in:
Tom Lane 2005-08-26 03:08:15 +00:00
parent 09a6c90945
commit f26b91761b
8 changed files with 25 additions and 11 deletions

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

View 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);
}
/*

View 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;

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

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

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

View 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

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