From 49ce6fff1d3415257404899e30733aefdfee2a06 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Mon, 18 Jun 2001 16:13:21 +0000 Subject: [PATCH] Allow removal of system-named pg_* temp tables. Rename temp file/dir as pgsql_tmp. --- src/backend/catalog/aclchk.c | 5 ++- src/backend/catalog/heap.c | 74 +++++++++++++++++------------------ src/backend/storage/file/fd.c | 6 +-- src/backend/tcop/utility.c | 6 ++- src/include/utils/temprel.h | 7 +++- 5 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c index 2747953384..35352be16b 100644 --- a/src/backend/catalog/aclchk.c +++ b/src/backend/catalog/aclchk.c @@ -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 diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 0a9d6ce6bb..a7f22cd6cf 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -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)); diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c index f37a9573df..b831e6cc24 100644 --- a/src/backend/storage/file/fd.c +++ b/src/backend/storage/file/fd.c @@ -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" /* diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c index bef1d6844a..5be50e7aad 100644 --- a/src/backend/tcop/utility.c +++ b/src/backend/tcop/utility.c @@ -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); diff --git a/src/include/utils/temprel.h b/src/include/utils/temprel.h index 3fc0ed4b11..b185e3372e 100644 --- a/src/include/utils/temprel.h +++ b/src/include/utils/temprel.h @@ -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); -- GitLab