Skip to content

Commit 49ce6ff

Browse files
committed
Allow removal of system-named pg_* temp tables. Rename temp file/dir as
pgsql_tmp.
1 parent 0bba6bd commit 49ce6ff

File tree

5 files changed

+51
-47
lines changed

5 files changed

+51
-47
lines changed

src/backend/catalog/aclchk.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.50 2001/06/09 23:21:54 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.51 2001/06/18 16:13:21 momjian Exp $
1212
*
1313
* NOTES
1414
* See acl.h.
@@ -32,6 +32,7 @@
3232
#include "parser/parse_func.h"
3333
#include "utils/acl.h"
3434
#include "utils/syscache.h"
35+
#include "utils/temprel.h"
3536

3637
static int32 aclcheck(Acl *acl, AclId id, AclIdType idtype, AclMode mode);
3738

@@ -437,7 +438,7 @@ pg_aclcheck(char *relname, Oid userid, AclMode mode)
437438
*/
438439
if ((mode & (ACL_INSERT | ACL_UPDATE | ACL_DELETE)) &&
439440
!allowSystemTableMods && IsSystemRelationName(relname) &&
440-
strncmp(relname, "pg_temp.", strlen("pg_temp.")) != 0 &&
441+
!is_temp_relname(relname) &&
441442
!((Form_pg_shadow) GETSTRUCT(tuple))->usecatupd)
442443
{
443444
#ifdef ACLDEBUG

src/backend/catalog/heap.c

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.167 2001/06/12 05:55:49 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.168 2001/06/18 16:13:21 momjian Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -281,8 +281,8 @@ heap_create(char *relname,
281281
* replace relname of caller with a unique name for a temp
282282
* relation
283283
*/
284-
snprintf(relname, NAMEDATALEN, "pg_temp.%d.%u",
285-
(int) MyProcPid, uniqueId++);
284+
snprintf(relname, NAMEDATALEN, "%s_%d_%u",
285+
PG_TEMP_REL_PREFIX, (int) MyProcPid, uniqueId++);
286286
}
287287

288288
/*
@@ -874,37 +874,6 @@ heap_create_with_catalog(char *relname,
874874
}
875875

876876

877-
/* ----------------------------------------------------------------
878-
* heap_drop_with_catalog - removes all record of named relation from catalogs
879-
*
880-
* 1) open relation, check for existence, etc.
881-
* 2) remove inheritance information
882-
* 3) remove indexes
883-
* 4) remove pg_class tuple
884-
* 5) remove pg_attribute tuples and related descriptions
885-
* 6) remove pg_description tuples
886-
* 7) remove pg_type tuples
887-
* 8) RemoveConstraints ()
888-
* 9) unlink relation
889-
*
890-
* old comments
891-
* Except for vital relations, removes relation from
892-
* relation catalog, and related attributes from
893-
* attribute catalog (needed?). (Anything else?)
894-
*
895-
* get proper relation from relation catalog (if not arg)
896-
* scan attribute catalog deleting attributes of reldesc
897-
* (necessary?)
898-
* delete relation from relation catalog
899-
* (How are the tuples of the relation discarded?)
900-
*
901-
* XXX Must fix to work with indexes.
902-
* There may be a better order for doing things.
903-
* Problems with destroying a deleted database--cannot create
904-
* a struct reldesc without having an open file descriptor.
905-
* ----------------------------------------------------------------
906-
*/
907-
908877
/* --------------------------------
909878
* RelationRemoveInheritance
910879
*
@@ -1334,10 +1303,35 @@ DeleteTypeTuple(Relation rel)
13341303
heap_close(pg_type_desc, RowExclusiveLock);
13351304
}
13361305

1337-
/* --------------------------------
1338-
* heap_drop_with_catalog
1306+
/* ----------------------------------------------------------------
1307+
* heap_drop_with_catalog - removes all record of named relation from catalogs
13391308
*
1340-
* --------------------------------
1309+
* 1) open relation, check for existence, etc.
1310+
* 2) remove inheritance information
1311+
* 3) remove indexes
1312+
* 4) remove pg_class tuple
1313+
* 5) remove pg_attribute tuples and related descriptions
1314+
* 6) remove pg_description tuples
1315+
* 7) remove pg_type tuples
1316+
* 8) RemoveConstraints ()
1317+
* 9) unlink relation
1318+
*
1319+
* old comments
1320+
* Except for vital relations, removes relation from
1321+
* relation catalog, and related attributes from
1322+
* attribute catalog (needed?). (Anything else?)
1323+
*
1324+
* get proper relation from relation catalog (if not arg)
1325+
* scan attribute catalog deleting attributes of reldesc
1326+
* (necessary?)
1327+
* delete relation from relation catalog
1328+
* (How are the tuples of the relation discarded?)
1329+
*
1330+
* XXX Must fix to work with indexes.
1331+
* There may be a better order for doing things.
1332+
* Problems with destroying a deleted database--cannot create
1333+
* a struct reldesc without having an open file descriptor.
1334+
* ----------------------------------------------------------------
13411335
*/
13421336
void
13431337
heap_drop_with_catalog(const char *relname,
@@ -1360,8 +1354,10 @@ heap_drop_with_catalog(const char *relname,
13601354
* prevent deletion of system relations
13611355
*/
13621356
/* allow temp of pg_class? Guess so. */
1363-
if (!istemp && !allow_system_table_mods &&
1364-
IsSystemRelationName(RelationGetRelationName(rel)))
1357+
if (!istemp &&
1358+
!allow_system_table_mods &&
1359+
IsSystemRelationName(RelationGetRelationName(rel)) &&
1360+
!is_temp_relname(RelationGetRelationName(rel)))
13651361
elog(ERROR, "System relation \"%s\" may not be dropped",
13661362
RelationGetRelationName(rel));
13671363

src/backend/storage/file/fd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.81 2001/06/11 04:12:29 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.82 2001/06/18 16:13:21 momjian Exp $
1111
*
1212
* NOTES:
1313
*
@@ -54,8 +54,8 @@
5454

5555

5656
/* Filename components for OpenTemporaryFile */
57-
#define PG_TEMP_FILES_DIR "pg_tempfiles"
58-
#define PG_TEMP_FILE_PREFIX "pg_temp"
57+
#define PG_TEMP_FILES_DIR "pgsql_tmp"
58+
#define PG_TEMP_FILE_PREFIX "pgsql_tmp"
5959

6060

6161
/*

src/backend/tcop/utility.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.113 2001/06/09 23:21:54 petere Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.114 2001/06/18 16:13:21 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -46,6 +46,7 @@
4646
#include "utils/acl.h"
4747
#include "utils/ps_status.h"
4848
#include "utils/syscache.h"
49+
#include "utils/temprel.h"
4950
#include "access/xlog.h"
5051

5152
/*
@@ -120,7 +121,8 @@ CheckDropPermissions(char *name, char rightkind)
120121
elog(ERROR, "you do not own %s \"%s\"",
121122
rentry->name, name);
122123

123-
if (!allowSystemTableMods && IsSystemRelationName(name))
124+
if (!allowSystemTableMods && IsSystemRelationName(name) &&
125+
!is_temp_relname(name))
124126
elog(ERROR, "%s \"%s\" is a system %s",
125127
rentry->name, name, rentry->name);
126128

src/include/utils/temprel.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: temprel.h,v 1.15 2001/03/22 04:01:14 momjian Exp $
10+
* $Id: temprel.h,v 1.16 2001/06/18 16:13:21 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,6 +16,11 @@
1616

1717
#include "access/htup.h"
1818

19+
#define PG_TEMP_REL_PREFIX "pg_temp"
20+
21+
#define is_temp_relname(relname) \
22+
(strncmp(relname, PG_TEMP_REL_PREFIX, strlen(PG_TEMP_REL_PREFIX)) == 0)
23+
1924
extern void create_temp_relation(const char *relname,
2025
HeapTuple pg_class_tuple);
2126
extern void remove_temp_rel_by_relid(Oid relid);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy