diff --git a/src/backend/catalog/aclchk.c b/src/backend/catalog/aclchk.c
index 27479533844e1092fa5335df5a2b6b1f44543f50..35352be16b2d544ee167571463cd8d3133610b01 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 0a9d6ce6bb3c20bd8567138b81c1f4055d05b915..a7f22cd6cfe66f57fbb522807e36bba9ea0a4360 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 f37a9573df935b313d2f996783925803a54d559c..b831e6cc2416bc75927df42b5511090871da5d9b 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 bef1d6844a03be1e7865745443ef99e2ecc2c424..5be50e7aade280377293ff4d7b3ba9b8aa49e2a5 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 3fc0ed4b11ad8eb80cb3e64be5a34a383f70cd47..b185e3372e90c2def6d1a3b372dec6784edf499f 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);