Allow removal of system-named pg_* temp tables. Rename temp file/dir as

pgsql_tmp.
This commit is contained in:
Bruce Momjian 2001-06-18 16:13:21 +00:00
parent 0bba6bdb8a
commit 49ce6fff1d
5 changed files with 51 additions and 47 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.50 2001/06/09 23:21:54 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.51 2001/06/18 16:13:21 momjian Exp $
*
* NOTES
* See acl.h.
@ -32,6 +32,7 @@
#include "parser/parse_func.h"
#include "utils/acl.h"
#include "utils/syscache.h"
#include "utils/temprel.h"
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
@ -437,7 +438,7 @@ pg_aclcheck(char *relname, Oid userid, AclMode mode)
*/
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
!allowSystemTableMods && IsSystemRelationName(relname) &&
strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
!is_temp_relname(relname) &&
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
{
#ifdef ACLDEBUG

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.167 2001/06/12 05:55:49 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.168 2001/06/18 16:13:21 momjian Exp $
*
*
* INTERFACE ROUTINES
@ -281,8 +281,8 @@ heap_create(char *relname,
* replace relname of caller with a unique name for a temp
* relation
*/
snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
(int) MyProcPid, uniqueId++);
snprintf(relname, NAMEDATALEN, "%s_%d_%u",
PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
}
/*
@ -874,37 +874,6 @@ heap_create_with_catalog(char *relname,
}
/* ----------------------------------------------------------------
* heap_drop_with_catalog - removes all record of named relation from catalogs
*
* 1) open relation, check for existence, etc.
* 2) remove inheritance information
* 3) remove indexes
* 4) remove pg_class tuple
* 5) remove pg_attribute tuples and related descriptions
* 6) remove pg_description tuples
* 7) remove pg_type tuples
* 8) RemoveConstraints ()
* 9) unlink relation
*
* old comments
* Except for vital relations, removes relation from
* relation catalog, and related attributes from
* attribute catalog (needed?). (Anything else?)
*
* get proper relation from relation catalog (if not arg)
* scan attribute catalog deleting attributes of reldesc
* (necessary?)
* delete relation from relation catalog
* (How are the tuples of the relation discarded?)
*
* XXX Must fix to work with indexes.
* There may be a better order for doing things.
* Problems with destroying a deleted database--cannot create
* a struct reldesc without having an open file descriptor.
* ----------------------------------------------------------------
*/
/* --------------------------------
* RelationRemoveInheritance
*
@ -1334,10 +1303,35 @@ DeleteTypeTuple(Relation rel)
heap_close(pg_type_desc, RowExclusiveLock);
}
/* --------------------------------
* heap_drop_with_catalog
/* ----------------------------------------------------------------
* heap_drop_with_catalog - removes all record of named relation from catalogs
*
* --------------------------------
* 1) open relation, check for existence, etc.
* 2) remove inheritance information
* 3) remove indexes
* 4) remove pg_class tuple
* 5) remove pg_attribute tuples and related descriptions
* 6) remove pg_description tuples
* 7) remove pg_type tuples
* 8) RemoveConstraints ()
* 9) unlink relation
*
* old comments
* Except for vital relations, removes relation from
* relation catalog, and related attributes from
* attribute catalog (needed?). (Anything else?)
*
* get proper relation from relation catalog (if not arg)
* scan attribute catalog deleting attributes of reldesc
* (necessary?)
* delete relation from relation catalog
* (How are the tuples of the relation discarded?)
*
* XXX Must fix to work with indexes.
* There may be a better order for doing things.
* Problems with destroying a deleted database--cannot create
* a struct reldesc without having an open file descriptor.
* ----------------------------------------------------------------
*/
void
heap_drop_with_catalog(const char *relname,
@ -1360,8 +1354,10 @@ heap_drop_with_catalog(const char *relname,
* prevent deletion of system relations
*/
/* allow temp of pg_class? Guess so. */
if (!istemp && !allow_system_table_mods &&
IsSystemRelationName(RelationGetRelationName(rel)))
if (!istemp &&
!allow_system_table_mods &&
IsSystemRelationName(RelationGetRelationName(rel)) &&
!is_temp_relname(RelationGetRelationName(rel)))
elog(ERROR, "System relation \"%s\" may not be dropped",
RelationGetRelationName(rel));

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.81 2001/06/11 04:12:29 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.82 2001/06/18 16:13:21 momjian Exp $
*
* NOTES:
*
@ -54,8 +54,8 @@
/* Filename components for OpenTemporaryFile */
#define PG_TEMP_FILES_DIR "pg_tempfiles"
#define PG_TEMP_FILE_PREFIX "pg_temp"
#define PG_TEMP_FILES_DIR "pgsql_tmp"
#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
/*

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.113 2001/06/09 23:21:54 petere Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.114 2001/06/18 16:13:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -46,6 +46,7 @@
#include "utils/acl.h"
#include "utils/ps_status.h"
#include "utils/syscache.h"
#include "utils/temprel.h"
#include "access/xlog.h"
/*
@ -120,7 +121,8 @@ CheckDropPermissions(char *name, char rightkind)
elog(ERROR, "you do not own %s \"%s\"",
rentry->name, name);
if (!allowSystemTableMods && IsSystemRelationName(name))
if (!allowSystemTableMods && IsSystemRelationName(name) &&
!is_temp_relname(name))
elog(ERROR, "%s \"%s\" is a system %s",
rentry->name, name, rentry->name);

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: temprel.h,v 1.15 2001/03/22 04:01:14 momjian Exp $
* $Id: temprel.h,v 1.16 2001/06/18 16:13:21 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -16,6 +16,11 @@
#include "access/htup.h"
#define PG_TEMP_REL_PREFIX "pg_temp"
#define is_temp_relname(relname) \
(strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)) == 0)
extern void create_temp_relation(const char *relname,
HeapTuple pg_class_tuple);
extern void remove_temp_rel_by_relid(Oid relid);