diff --git a/src/backend/commands/rename.c b/src/backend/commands/rename.c
index 4f3d300dae34fcfc1fb9d1431ce442094a5e805c..5760cbe30042278220cbd5ba6ab9fe1fd8673760 100644
--- a/src/backend/commands/rename.c
+++ b/src/backend/commands/rename.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.68 2002/03/31 07:49:30 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.69 2002/04/05 11:58:24 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -248,6 +248,12 @@ renameatt(Oid relid,
 
 /*
  *		renamerel		- change the name of a relation
+ *
+ *		XXX - When renaming sequences, we don't bother to modify the
+ *			  sequence name that is stored within the sequence itself
+ *			  (this would cause problems with MVCC). In the future,
+ *			  the sequence name should probably be removed from the
+ *			  sequence, AFAIK there's no need for it to be there.
  */
 void
 renamerel(Oid relid, const char *newrelname)
@@ -312,6 +318,7 @@ renamerel(Oid relid, const char *newrelname)
 	CatalogCloseIndices(Num_pg_class_indices, irelations);
 
 	heap_close(relrelation, NoLock);
+	heap_freetuple(reltup);
 
 	/*
 	 * Also rename the associated type, if any.
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out
index 6e83edd65c9ea508444b0fad286e0802c4fd95c7..5d7934fa91c00434b8fff25f8b94d4aa299fc522 100644
--- a/src/test/regress/expected/alter_table.out
+++ b/src/test/regress/expected/alter_table.out
@@ -267,6 +267,35 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
        4
 (5 rows)
 
+-- ALTER TABLE ... RENAME on non-table relations
+-- renaming indexes (FIXME: this should probably test the index's functionality)
+ALTER TABLE onek_unique1 RENAME TO tmp_onek_unique1;
+ALTER TABLE tmp_onek_unique1 RENAME TO onek_unique1;
+-- renaming views
+CREATE VIEW tmp_view (unique1) AS SELECT unique1 FROM tenk1;
+ALTER TABLE tmp_view RENAME TO tmp_view_new;
+-- 5 values, sorted 
+SELECT unique1 FROM tenk1 WHERE unique1 < 5;
+ unique1 
+---------
+       0
+       1
+       2
+       3
+       4
+(5 rows)
+
+DROP VIEW tmp_view_new;
+-- renaming sequences
+CREATE SEQUENCE foo_seq;
+ALTER TABLE foo_seq RENAME TO foo_seq_new;
+SELECT * FROM foo_seq_new;
+ sequence_name | last_value | increment_by |      max_value      | min_value | cache_value | log_cnt | is_cycled | is_called 
+---------------+------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------
+  foo_seq       |          1 |            1 | 9223372036854775807 |         1 |     1 |       1 | f         | f
+  (1 row)
+
+DROP SEQUENCE foo_seq_new;
 -- FOREIGN KEY CONSTRAINT adding TEST
 CREATE TABLE tmp2 (a int primary key);
 NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2'
diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql
index 2319372b596b54faa273b29f7d9cc49e01816594..e23a75cebbec117056c2b0b38af0522b831af34d 100644
--- a/src/test/regress/sql/alter_table.sql
+++ b/src/test/regress/sql/alter_table.sql
@@ -163,6 +163,22 @@ ALTER TABLE ten_k RENAME TO tenk1;
 -- 5 values, sorted 
 SELECT unique1 FROM tenk1 WHERE unique1 < 5;
 
+-- ALTER TABLE ... RENAME on non-table relations
+-- renaming indexes (FIXME: this should probably test the index's functionality)
+ALTER TABLE onek_unique1 RENAME TO tmp_onek_unique1;
+ALTER TABLE tmp_onek_unique1 RENAME TO onek_unique1;
+-- renaming views
+CREATE VIEW tmp_view (unique1) AS SELECT unique1 FROM tenk1;
+ALTER TABLE tmp_view RENAME TO tmp_view_new;
+-- 5 values, sorted 
+SELECT unique1 FROM tenk1 WHERE unique1 < 5;
+DROP VIEW tmp_view_new;
+-- renaming sequences
+CREATE SEQUENCE foo_seq;
+ALTER TABLE foo_seq RENAME TO foo_seq_new;
+SELECT * FROM foo_seq_new;
+DROP SEQUENCE foo_seq_new;
+
 -- FOREIGN KEY CONSTRAINT adding TEST
 
 CREATE TABLE tmp2 (a int primary key);