 src/backend/commands/aggregatecmds.c        |   25 +---
 src/backend/commands/alter.c                |  209 ++++++++++++++++++++++-----
 src/backend/commands/collationcmds.c        |   20 +--
 src/backend/commands/conversioncmds.c       |   51 -------
 src/backend/commands/event_trigger.c        |   41 ------
 src/backend/commands/foreigncmds.c          |   77 ----------
 src/backend/commands/functioncmds.c         |   26 +---
 src/backend/commands/opclasscmds.c          |   78 ++++------
 src/backend/commands/proclang.c             |   37 -----
 src/backend/commands/tablespace.c           |   18 +--
 src/backend/commands/tsearchcmds.c          |  188 ------------------------
 src/backend/parser/gram.y                   |    8 +-
 src/include/commands/alter.h                |    2 +
 src/include/commands/conversioncmds.h       |    1 -
 src/include/commands/defrem.h               |    2 -
 src/include/commands/event_trigger.h        |    1 -
 src/include/commands/proclang.h             |    1 -
 src/test/regress/expected/alter_generic.out |   16 +-
 src/test/regress/expected/event_trigger.out |    2 +-
 19 files changed, 229 insertions(+), 574 deletions(-)

diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c
index b9f8711..62d364e 100644
--- a/src/backend/commands/aggregatecmds.c
+++ b/src/backend/commands/aggregatecmds.c
@@ -29,6 +29,7 @@
 #include "catalog/pg_aggregate.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
+#include "commands/alter.h"
 #include "commands/defrem.h"
 #include "miscadmin.h"
 #include "parser/parse_func.h"
@@ -240,15 +241,14 @@ RenameAggregate(List *name, List *args, const char *newname)
 	HeapTuple	tup;
 	Form_pg_proc procForm;
 	Relation	rel;
-	AclResult	aclresult;
 
 	rel = heap_open(ProcedureRelationId, RowExclusiveLock);
 
 	/* Look up function and make sure it's an aggregate */
 	procOid = LookupAggNameTypeNames(name, args, false);
 
-	tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
-	if (!HeapTupleIsValid(tup)) /* should not happen */
+	tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procOid));
+	if (!HeapTupleIsValid(tup))	/* should not happen */
 		elog(ERROR, "cache lookup failed for function %u", procOid);
 	procForm = (Form_pg_proc) GETSTRUCT(tup);
 
@@ -268,22 +268,9 @@ RenameAggregate(List *name, List *args, const char *newname)
 											   procForm->proargtypes.values),
 						get_namespace_name(namespaceOid))));
 
-	/* must be owner */
-	if (!pg_proc_ownercheck(procOid, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
-					   NameListToString(name));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	/* rename */
-	namestrcpy(&(((Form_pg_proc) GETSTRUCT(tup))->proname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
+	/* OK, do the work */
+	AlterObjectRename_internal(rel, procOid, newname);
 
+	ReleaseSysCache(tup);
 	heap_close(rel, NoLock);
-	heap_freetuple(tup);
 }
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index 9e271c3..6f08210 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -36,6 +36,7 @@
 #include "commands/trigger.h"
 #include "commands/typecmds.h"
 #include "commands/user.h"
+#include "parser/parse_func.h"
 #include "miscadmin.h"
 #include "tcop/utility.h"
 #include "utils/builtins.h"
@@ -45,6 +46,145 @@
 #include "utils/syscache.h"
 #include "utils/tqual.h"
 
+/*
+ * AlterObjectRename_internal
+ *
+ * Generic function to rename the given object, for simple cases (won't
+ * work for tables, nor other cases where we need to do more than change
+ * the name column of a single catalog entry).
+ * It checks name duplication only when catalog cache by name as key is
+ * available. Otherwise, the caller should ensure here is no object with
+ * identical name.
+ *
+ * rel: catalog relation containing object (RowExclusiveLock'd by caller)
+ * objectId: OID of object to be renamed
+ * new_name: CString representation of new name
+ */
+void
+AlterObjectRename_internal(Relation rel, Oid objectId, const char *new_name)
+{
+	Oid			classId = RelationGetRelid(rel);
+	int			oidCacheId = get_object_catcache_oid(classId);
+	int			nameCacheId = get_object_catcache_name(classId);
+	AttrNumber	Anum_name = get_object_attnum_name(classId);
+	AttrNumber	Anum_namespace = get_object_attnum_namespace(classId);
+	AttrNumber	Anum_owner = get_object_attnum_owner(classId);
+	AclObjectKind acl_kind = get_object_aclkind(classId);
+	HeapTuple	oldtup;
+	HeapTuple	newtup;
+	Datum		datum;
+	bool		isnull;
+	Oid			namespaceId;
+	Oid			ownerId;
+	char	   *old_name;
+	AclResult	aclresult;
+	Datum	   *values;
+	bool	   *nulls;
+	bool	   *replaces;
+
+	oldtup = SearchSysCache1(oidCacheId, ObjectIdGetDatum(objectId));
+	if (!HeapTupleIsValid(oldtup))
+		elog(ERROR, "cache lookup failed for object %u of catalog \"%s\"",
+			 objectId, RelationGetRelationName(rel));
+
+	datum = heap_getattr(oldtup, Anum_name,
+						 RelationGetDescr(rel), &isnull);
+	Assert(!isnull);
+	old_name = NameStr(*(DatumGetName(datum)));
+
+	/* Get OID of namespace */
+	if (Anum_namespace > 0)
+	{
+		datum = heap_getattr(oldtup, Anum_namespace,
+							 RelationGetDescr(rel), &isnull);
+		Assert(!isnull);
+		namespaceId = DatumGetObjectId(datum);
+	}
+	else
+		namespaceId = InvalidOid;
+
+	/* Permission checks ... superusers can always do it */
+	if (!superuser())
+	{
+		/* Fail if object does not have an explicit owner */
+		if (Anum_owner <= 0)
+			ereport(ERROR,
+					(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+					 (errmsg("must be superuser to set schema of %s",
+							 getObjectDescriptionOids(classId, objectId)))));
+
+		/* Otherwise, must be owner of the existing object */
+		datum = heap_getattr(oldtup, Anum_owner,
+							 RelationGetDescr(rel), &isnull);
+		Assert(!isnull);
+		ownerId = DatumGetObjectId(datum);
+
+		if (!has_privs_of_role(GetUserId(), DatumGetObjectId(ownerId)))
+			aclcheck_error(ACLCHECK_NOT_OWNER, acl_kind, old_name);
+
+		/* User must have CREATE privilege on the namespace */
+		if (OidIsValid(namespaceId))
+		{
+			aclresult = pg_namespace_aclcheck(namespaceId, GetUserId(),
+											  ACL_CREATE);
+			if (aclresult != ACLCHECK_OK)
+				aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
+							   get_namespace_name(namespaceId));
+		}
+	}
+
+	/*
+     * Check for duplicate name (more friendly than unique-index failure).
+     * Since this is just a friendliness check, we can just skip it in cases
+     * where there isn't a suitable syscache available.
+     */
+    if (nameCacheId >= 0)
+	{
+		HeapTuple	tup;
+
+		tup = SearchSysCache2(nameCacheId,
+							  CStringGetDatum(new_name),
+							  ObjectIdGetDatum(namespaceId));
+		if (HeapTupleIsValid(tup))
+		{
+			Oid		exists = HeapTupleGetOid(tup);
+
+			if (OidIsValid(namespaceId))
+				ereport(ERROR,
+						(errcode(ERRCODE_DUPLICATE_OBJECT),
+						 errmsg("%s already exists in schema \"%s\"",
+								getObjectDescriptionOids(classId, exists),
+								get_namespace_name(namespaceId))));
+			else
+				ereport(ERROR,
+                        (errcode(ERRCODE_DUPLICATE_OBJECT),
+                         errmsg("%s already exists",
+								getObjectDescriptionOids(classId, exists))));
+			ReleaseSysCache(tup);
+		}
+	}
+
+	/* Build modified tuple */
+	values = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(Datum));
+	nulls = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
+	replaces = palloc0(RelationGetNumberOfAttributes(rel) * sizeof(bool));
+	values[Anum_name - 1] = PointerGetDatum(new_name);
+	replaces[Anum_name - 1] = true;
+	newtup = heap_modify_tuple(oldtup, RelationGetDescr(rel),
+							   values, nulls, replaces);
+
+	/* Perform actual update */
+	simple_heap_update(rel, &oldtup->t_self, newtup);
+	CatalogUpdateIndexes(rel, newtup);
+
+	/* Release memory */
+	pfree(values);
+	pfree(nulls);
+	pfree(replaces);
+	heap_freetuple(newtup);
+
+	ReleaseSysCache(oldtup);
+}
 
 /*
  * Executes an ALTER OBJECT / RENAME TO statement.	Based on the object
@@ -67,34 +207,10 @@ ExecRenameStmt(RenameStmt *stmt)
 			RenameConstraint(stmt);
 			break;
 
-		case OBJECT_CONVERSION:
-			RenameConversion(stmt->object, stmt->newname);
-			break;
-
 		case OBJECT_DATABASE:
 			RenameDatabase(stmt->subname, stmt->newname);
 			break;
 
-		case OBJECT_FDW:
-			RenameForeignDataWrapper(stmt->subname, stmt->newname);
-			break;
-
-		case OBJECT_FOREIGN_SERVER:
-			RenameForeignServer(stmt->subname, stmt->newname);
-			break;
-
-		case OBJECT_EVENT_TRIGGER:
-			RenameEventTrigger(stmt->subname, stmt->newname);
-			break;
-
-		case OBJECT_FUNCTION:
-			RenameFunction(stmt->object, stmt->objarg, stmt->newname);
-			break;
-
-		case OBJECT_LANGUAGE:
-			RenameLanguage(stmt->subname, stmt->newname);
-			break;
-
 		case OBJECT_OPCLASS:
 			RenameOpClass(stmt->object, stmt->subname, stmt->newname);
 			break;
@@ -103,6 +219,10 @@ ExecRenameStmt(RenameStmt *stmt)
 			RenameOpFamily(stmt->object, stmt->subname, stmt->newname);
 			break;
 
+		case OBJECT_FUNCTION:
+			RenameFunction(stmt->object, stmt->objarg, stmt->newname);
+			break;
+
 		case OBJECT_ROLE:
 			RenameRole(stmt->subname, stmt->newname);
 			break;
@@ -132,25 +252,38 @@ ExecRenameStmt(RenameStmt *stmt)
 			renametrig(stmt);
 			break;
 
-		case OBJECT_TSPARSER:
-			RenameTSParser(stmt->object, stmt->newname);
+		case OBJECT_DOMAIN:
+		case OBJECT_TYPE:
+			RenameType(stmt);
 			break;
 
+		case OBJECT_CONVERSION:
+		case OBJECT_EVENT_TRIGGER:
+		case OBJECT_FDW:
+		case OBJECT_FOREIGN_SERVER:
+		case OBJECT_LANGUAGE:
+		case OBJECT_TSCONFIGURATION:
 		case OBJECT_TSDICTIONARY:
-			RenameTSDictionary(stmt->object, stmt->newname);
-			break;
-
+		case OBJECT_TSPARSER:
 		case OBJECT_TSTEMPLATE:
-			RenameTSTemplate(stmt->object, stmt->newname);
-			break;
-
-		case OBJECT_TSCONFIGURATION:
-			RenameTSConfiguration(stmt->object, stmt->newname);
-			break;
+			{
+				ObjectAddress	address;
+				Relation		catalog;
+				Relation		relation;
 
-		case OBJECT_DOMAIN:
-		case OBJECT_TYPE:
-			RenameType(stmt);
+				address = get_object_address(stmt->renameType,
+											 stmt->object, stmt->objarg,
+											 &relation,
+											 AccessExclusiveLock, false);
+				catalog = heap_open(address.classId, RowExclusiveLock);
+
+				AlterObjectRename_internal(catalog,
+										   address.objectId,
+										   stmt->newname);
+				if (relation)
+					heap_close(relation, NoLock);
+				heap_close(catalog, RowExclusiveLock);
+			}
 			break;
 
 		default:
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index ec22d11..458b573 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -152,7 +152,6 @@ RenameCollation(List *name, const char *newname)
 	Oid			namespaceOid;
 	HeapTuple	tup;
 	Relation	rel;
-	AclResult	aclresult;
 
 	rel = heap_open(CollationRelationId, RowExclusiveLock);
 
@@ -187,23 +186,8 @@ RenameCollation(List *name, const char *newname)
 						newname,
 						get_namespace_name(namespaceOid))));
 
-	/* must be owner */
-	if (!pg_collation_ownercheck(collationOid, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_COLLATION,
-					   NameListToString(name));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	/* rename */
-	namestrcpy(&(((Form_pg_collation) GETSTRUCT(tup))->collname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_freetuple(tup);
+	/* ok, do the task */
+	AlterObjectRename_internal(rel, collationOid, newname);
 
 	heap_close(rel, RowExclusiveLock);
 }
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c
index 3a71e33..a5485e4 100644
--- a/src/backend/commands/conversioncmds.c
+++ b/src/backend/commands/conversioncmds.c
@@ -114,54 +114,3 @@ CreateConversionCommand(CreateConversionStmt *stmt)
 	ConversionCreate(conversion_name, namespaceId, GetUserId(),
 					 from_encoding, to_encoding, funcoid, stmt->def);
 }
-
-/*
- * Rename conversion
- */
-void
-RenameConversion(List *name, const char *newname)
-{
-	Oid			conversionOid;
-	Oid			namespaceOid;
-	HeapTuple	tup;
-	Relation	rel;
-	AclResult	aclresult;
-
-	rel = heap_open(ConversionRelationId, RowExclusiveLock);
-
-	conversionOid = get_conversion_oid(name, false);
-
-	tup = SearchSysCacheCopy1(CONVOID, ObjectIdGetDatum(conversionOid));
-	if (!HeapTupleIsValid(tup)) /* should not happen */
-		elog(ERROR, "cache lookup failed for conversion %u", conversionOid);
-
-	namespaceOid = ((Form_pg_conversion) GETSTRUCT(tup))->connamespace;
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists2(CONNAMENSP,
-							  CStringGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("conversion \"%s\" already exists in schema \"%s\"",
-						newname, get_namespace_name(namespaceOid))));
-
-	/* must be owner */
-	if (!pg_conversion_ownercheck(conversionOid, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CONVERSION,
-					   NameListToString(name));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	/* rename */
-	namestrcpy(&(((Form_pg_conversion) GETSTRUCT(tup))->conname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
diff --git a/src/backend/commands/event_trigger.c b/src/backend/commands/event_trigger.c
index cb4e658..2e24e0d 100644
--- a/src/backend/commands/event_trigger.c
+++ b/src/backend/commands/event_trigger.c
@@ -409,47 +409,6 @@ AlterEventTrigger(AlterEventTrigStmt *stmt)
 	heap_close(tgrel, RowExclusiveLock);
 }
 
-
-/*
- * Rename event trigger
- */
-void
-RenameEventTrigger(const char *trigname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-	Form_pg_event_trigger evtForm;
-
-	rel = heap_open(EventTriggerRelationId, RowExclusiveLock);
-
-	/* newname must be available */
-	if (SearchSysCacheExists1(EVENTTRIGGERNAME, CStringGetDatum(newname)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("event trigger \"%s\" already exists", newname)));
-
-	/* trigname must exists */
-	tup = SearchSysCacheCopy1(EVENTTRIGGERNAME, CStringGetDatum(trigname));
-	if (!HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_OBJECT),
-				 errmsg("event trigger \"%s\" does not exist", trigname)));
-	if (!pg_event_trigger_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_EVENT_TRIGGER,
-					   trigname);
-
-	evtForm = (Form_pg_event_trigger) GETSTRUCT(tup);
-
-	/* tuple is a copy, so we can rename it now */
-	namestrcpy(&(evtForm->evtname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_freetuple(tup);
-	heap_close(rel, RowExclusiveLock);
-}
-
-
 /*
  * Change event trigger's owner -- by name
  */
diff --git a/src/backend/commands/foreigncmds.c b/src/backend/commands/foreigncmds.c
index f10cb52..2d73d2d 100644
--- a/src/backend/commands/foreigncmds.c
+++ b/src/backend/commands/foreigncmds.c
@@ -200,83 +200,6 @@ GetUserOidFromMapping(const char *username, bool missing_ok)
 	return get_role_oid(username, missing_ok);
 }
 
-
-/*
- * Rename foreign-data wrapper
- */
-void
-RenameForeignDataWrapper(const char *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-
-	rel = heap_open(ForeignDataWrapperRelationId, RowExclusiveLock);
-
-	tup = SearchSysCacheCopy1(FOREIGNDATAWRAPPERNAME, CStringGetDatum(oldname));
-	if (!HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_OBJECT),
-			 errmsg("foreign-data wrapper \"%s\" does not exist", oldname)));
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists1(FOREIGNDATAWRAPPERNAME, CStringGetDatum(newname)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-			 errmsg("foreign-data wrapper \"%s\" already exists", newname)));
-
-	/* must be owner of FDW */
-	if (!pg_foreign_data_wrapper_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_FDW,
-					   oldname);
-
-	/* rename */
-	namestrcpy(&(((Form_pg_foreign_data_wrapper) GETSTRUCT(tup))->fdwname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-
-/*
- * Rename foreign server
- */
-void
-RenameForeignServer(const char *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-
-	rel = heap_open(ForeignServerRelationId, RowExclusiveLock);
-
-	tup = SearchSysCacheCopy1(FOREIGNSERVERNAME, CStringGetDatum(oldname));
-	if (!HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_OBJECT),
-				 errmsg("server \"%s\" does not exist", oldname)));
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists1(FOREIGNSERVERNAME, CStringGetDatum(newname)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("server \"%s\" already exists", newname)));
-
-	/* must be owner of server */
-	if (!pg_foreign_server_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_FOREIGN_SERVER,
-					   oldname);
-
-	/* rename */
-	namestrcpy(&(((Form_pg_foreign_server) GETSTRUCT(tup))->srvname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-
 /*
  * Internal workhorse for changing a data wrapper's owner.
  *
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 453e33a..cf0613f 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1048,14 +1048,13 @@ RenameFunction(List *name, List *argtypes, const char *newname)
 	HeapTuple	tup;
 	Form_pg_proc procForm;
 	Relation	rel;
-	AclResult	aclresult;
 
 	rel = heap_open(ProcedureRelationId, RowExclusiveLock);
 
 	procOid = LookupFuncNameTypeNames(name, argtypes, false);
 
-	tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(procOid));
-	if (!HeapTupleIsValid(tup)) /* should not happen */
+	tup = SearchSysCache1(PROCOID, ObjectIdGetDatum(procOid));
+	if (!HeapTupleIsValid(tup))	/* should not happen */
 		elog(ERROR, "cache lookup failed for function %u", procOid);
 	procForm = (Form_pg_proc) GETSTRUCT(tup);
 
@@ -1080,28 +1079,15 @@ RenameFunction(List *name, List *argtypes, const char *newname)
 						funcname_signature_string(newname,
 												  procForm->pronargs,
 												  NIL,
-											   procForm->proargtypes.values),
+												procForm->proargtypes.values),
 						get_namespace_name(namespaceOid))));
 	}
 
-	/* must be owner */
-	if (!pg_proc_ownercheck(procOid, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC,
-					   NameListToString(name));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	/* rename */
-	namestrcpy(&(procForm->proname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
+	/* ok, do the work */
+	AlterObjectRename_internal(rel, procOid, newname);
 
+	ReleaseSysCache(tup);
 	heap_close(rel, NoLock);
-	heap_freetuple(tup);
 }
 
 /*
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index 099bb39..044ddd3 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -1666,19 +1666,16 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
 	Oid			opcOid;
 	Oid			amOid;
 	Oid			namespaceOid;
-	HeapTuple	origtup;
 	HeapTuple	tup;
 	Relation	rel;
-	AclResult	aclresult;
 
 	amOid = get_am_oid(access_method, false);
 
 	rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
 
 	/* Look up the opclass. */
-	origtup = OpClassCacheLookup(amOid, name, false);
-	tup = heap_copytuple(origtup);
-	ReleaseSysCache(origtup);
+	tup = OpClassCacheLookup(amOid, name, false);
+
 	opcOid = HeapTupleGetOid(tup);
 	namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
 
@@ -1694,25 +1691,11 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
 						newname, access_method,
 						get_namespace_name(namespaceOid))));
 	}
-
-	/* must be owner */
-	if (!pg_opclass_ownercheck(opcOid, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPCLASS,
-					   NameListToString(name));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	/* rename */
-	namestrcpy(&(((Form_pg_opclass) GETSTRUCT(tup))->opcname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
+	/* ok, do the work */
+	AlterObjectRename_internal(rel, opcOid, newname);
 
 	heap_close(rel, NoLock);
-	heap_freetuple(tup);
+	ReleaseSysCache(tup);
 }
 
 /*
@@ -1721,14 +1704,13 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
 void
 RenameOpFamily(List *name, const char *access_method, const char *newname)
 {
-	Oid			opfOid;
-	Oid			amOid;
-	Oid			namespaceOid;
-	char	   *schemaname;
-	char	   *opfname;
-	HeapTuple	tup;
-	Relation	rel;
-	AclResult	aclresult;
+	Oid         opfOid;
+	Oid         amOid;
+	Oid         namespaceOid;
+	char       *schemaname;
+	char       *opfname;
+	HeapTuple   tup;
+	Relation    rel;
 
 	amOid = get_am_oid(access_method, false);
 
@@ -1743,10 +1725,10 @@ RenameOpFamily(List *name, const char *access_method, const char *newname)
 	{
 		namespaceOid = LookupExplicitNamespace(schemaname);
 
-		tup = SearchSysCacheCopy3(OPFAMILYAMNAMENSP,
-								  ObjectIdGetDatum(amOid),
-								  PointerGetDatum(opfname),
-								  ObjectIdGetDatum(namespaceOid));
+		tup = SearchSysCache3(OPFAMILYAMNAMENSP,
+							  ObjectIdGetDatum(amOid),
+							  PointerGetDatum(opfname),
+							  ObjectIdGetDatum(namespaceOid));
 		if (!HeapTupleIsValid(tup))
 			ereport(ERROR,
 					(errcode(ERRCODE_UNDEFINED_OBJECT),
@@ -1754,6 +1736,8 @@ RenameOpFamily(List *name, const char *access_method, const char *newname)
 							opfname, access_method)));
 
 		opfOid = HeapTupleGetOid(tup);
+
+		ReleaseSysCache(tup);
 	}
 	else
 	{
@@ -1764,11 +1748,13 @@ RenameOpFamily(List *name, const char *access_method, const char *newname)
 					 errmsg("operator family \"%s\" does not exist for access method \"%s\"",
 							opfname, access_method)));
 
-		tup = SearchSysCacheCopy1(OPFAMILYOID, ObjectIdGetDatum(opfOid));
-		if (!HeapTupleIsValid(tup))		/* should not happen */
-			elog(ERROR, "cache lookup failed for opfamily %u", opfOid);
+		tup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfOid));
+		if (!HeapTupleIsValid(tup))     /* should not happen */
+	        elog(ERROR, "cache lookup failed for opfamily %u", opfOid);
 
 		namespaceOid = ((Form_pg_opfamily) GETSTRUCT(tup))->opfnamespace;
+
+		ReleaseSysCache(tup);
 	}
 
 	/* make sure the new name doesn't exist */
@@ -1784,24 +1770,10 @@ RenameOpFamily(List *name, const char *access_method, const char *newname)
 						get_namespace_name(namespaceOid))));
 	}
 
-	/* must be owner */
-	if (!pg_opfamily_ownercheck(opfOid, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPFAMILY,
-					   NameListToString(name));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	/* rename */
-	namestrcpy(&(((Form_pg_opfamily) GETSTRUCT(tup))->opfname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
+	/* ok, do the work */
+	AlterObjectRename_internal(rel, opfOid, newname);
 
 	heap_close(rel, NoLock);
-	heap_freetuple(tup);
 }
 
 /*
diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c
index ee860c0..6526b7e 100644
--- a/src/backend/commands/proclang.c
+++ b/src/backend/commands/proclang.c
@@ -535,43 +535,6 @@ DropProceduralLanguageById(Oid langOid)
 }
 
 /*
- * Rename language
- */
-void
-RenameLanguage(const char *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-
-	rel = heap_open(LanguageRelationId, RowExclusiveLock);
-
-	tup = SearchSysCacheCopy1(LANGNAME, CStringGetDatum(oldname));
-	if (!HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_OBJECT),
-				 errmsg("language \"%s\" does not exist", oldname)));
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists1(LANGNAME, CStringGetDatum(newname)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("language \"%s\" already exists", newname)));
-
-	/* must be owner of PL */
-	if (!pg_language_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_LANGUAGE,
-					   oldname);
-
-	/* rename */
-	namestrcpy(&(((Form_pg_language) GETSTRUCT(tup))->lanname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-/*
  * get_language_oid - given a language name, look up the OID
  *
  * If missing_ok is false, throw an error if language name not found.  If
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 5081d84..d80b3a6 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -61,6 +61,7 @@
 #include "catalog/indexing.h"
 #include "catalog/objectaccess.h"
 #include "catalog/pg_tablespace.h"
+#include "commands/alter.h"
 #include "commands/comment.h"
 #include "commands/seclabel.h"
 #include "commands/tablespace.h"
@@ -825,8 +826,7 @@ RenameTableSpace(const char *oldname, const char *newname)
 	ScanKeyData entry[1];
 	HeapScanDesc scan;
 	HeapTuple	tup;
-	HeapTuple	newtuple;
-	Form_pg_tablespace newform;
+	Oid			tableSpaceId;
 
 	/* Search pg_tablespace */
 	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
@@ -842,16 +842,9 @@ RenameTableSpace(const char *oldname, const char *newname)
 				(errcode(ERRCODE_UNDEFINED_OBJECT),
 				 errmsg("tablespace \"%s\" does not exist",
 						oldname)));
-
-	newtuple = heap_copytuple(tup);
-	newform = (Form_pg_tablespace) GETSTRUCT(newtuple);
-
+	tableSpaceId = HeapTupleGetOid(tup);
 	heap_endscan(scan);
 
-	/* Must be owner */
-	if (!pg_tablespace_ownercheck(HeapTupleGetOid(newtuple), GetUserId()))
-		aclcheck_error(ACLCHECK_NO_PRIV, ACL_KIND_TABLESPACE, oldname);
-
 	/* Validate new name */
 	if (!allowSystemTableMods && IsReservedName(newname))
 		ereport(ERROR,
@@ -875,10 +868,7 @@ RenameTableSpace(const char *oldname, const char *newname)
 	heap_endscan(scan);
 
 	/* OK, update the entry */
-	namestrcpy(&(newform->spcname), newname);
-
-	simple_heap_update(rel, &newtuple->t_self, newtuple);
-	CatalogUpdateIndexes(rel, newtuple);
+	AlterObjectRename_internal(rel, tableSpaceId, newname);
 
 	heap_close(rel, NoLock);
 }
diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index e545e95..9dbfa0c 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -303,49 +303,6 @@ RemoveTSParserById(Oid prsId)
 	heap_close(relation, RowExclusiveLock);
 }
 
-/*
- * ALTER TEXT SEARCH PARSER RENAME
- */
-void
-RenameTSParser(List *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-	Oid			prsId;
-	Oid			namespaceOid;
-
-	if (!superuser())
-		ereport(ERROR,
-				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-				 errmsg("must be superuser to rename text search parsers")));
-
-	rel = heap_open(TSParserRelationId, RowExclusiveLock);
-
-	prsId = get_ts_parser_oid(oldname, false);
-
-	tup = SearchSysCacheCopy1(TSPARSEROID, ObjectIdGetDatum(prsId));
-
-	if (!HeapTupleIsValid(tup)) /* should not happen */
-		elog(ERROR, "cache lookup failed for text search parser %u", prsId);
-
-	namespaceOid = ((Form_pg_ts_parser) GETSTRUCT(tup))->prsnamespace;
-
-	if (SearchSysCacheExists2(TSPARSERNAMENSP,
-							  PointerGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("text search parser \"%s\" already exists",
-						newname)));
-
-	namestrcpy(&(((Form_pg_ts_parser) GETSTRUCT(tup))->prsname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
 /* ---------------------- TS Dictionary commands -----------------------*/
 
 /*
@@ -529,57 +486,6 @@ DefineTSDictionary(List *names, List *parameters)
 }
 
 /*
- * ALTER TEXT SEARCH DICTIONARY RENAME
- */
-void
-RenameTSDictionary(List *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-	Oid			dictId;
-	Oid			namespaceOid;
-	AclResult	aclresult;
-
-	rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
-
-	dictId = get_ts_dict_oid(oldname, false);
-
-	tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
-
-	if (!HeapTupleIsValid(tup)) /* should not happen */
-		elog(ERROR, "cache lookup failed for text search dictionary %u",
-			 dictId);
-
-	namespaceOid = ((Form_pg_ts_dict) GETSTRUCT(tup))->dictnamespace;
-
-	if (SearchSysCacheExists2(TSDICTNAMENSP,
-							  PointerGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("text search dictionary \"%s\" already exists",
-						newname)));
-
-	/* must be owner */
-	if (!pg_ts_dict_ownercheck(dictId, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY,
-					   NameListToString(oldname));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-					   get_namespace_name(namespaceOid));
-
-	namestrcpy(&(((Form_pg_ts_dict) GETSTRUCT(tup))->dictname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-/*
  * Guts of TS dictionary deletion.
  */
 void
@@ -893,50 +799,6 @@ DefineTSTemplate(List *names, List *parameters)
 }
 
 /*
- * ALTER TEXT SEARCH TEMPLATE RENAME
- */
-void
-RenameTSTemplate(List *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-	Oid			tmplId;
-	Oid			namespaceOid;
-
-	if (!superuser())
-		ereport(ERROR,
-				(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-			   errmsg("must be superuser to rename text search templates")));
-
-	rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
-
-	tmplId = get_ts_template_oid(oldname, false);
-
-	tup = SearchSysCacheCopy1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId));
-
-	if (!HeapTupleIsValid(tup)) /* should not happen */
-		elog(ERROR, "cache lookup failed for text search template %u",
-			 tmplId);
-
-	namespaceOid = ((Form_pg_ts_template) GETSTRUCT(tup))->tmplnamespace;
-
-	if (SearchSysCacheExists2(TSTEMPLATENAMENSP,
-							  PointerGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("text search template \"%s\" already exists",
-						newname)));
-
-	namestrcpy(&(((Form_pg_ts_template) GETSTRUCT(tup))->tmplname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-/*
  * Guts of TS template deletion.
  */
 void
@@ -1233,56 +1095,6 @@ DefineTSConfiguration(List *names, List *parameters)
 }
 
 /*
- * ALTER TEXT SEARCH CONFIGURATION RENAME
- */
-void
-RenameTSConfiguration(List *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-	Oid			cfgId;
-	AclResult	aclresult;
-	Oid			namespaceOid;
-
-	rel = heap_open(TSConfigRelationId, RowExclusiveLock);
-
-	cfgId = get_ts_config_oid(oldname, false);
-
-	tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
-
-	if (!HeapTupleIsValid(tup)) /* should not happen */
-		elog(ERROR, "cache lookup failed for text search configuration %u",
-			 cfgId);
-
-	namespaceOid = ((Form_pg_ts_config) GETSTRUCT(tup))->cfgnamespace;
-
-	if (SearchSysCacheExists2(TSCONFIGNAMENSP,
-							  PointerGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("text search configuration \"%s\" already exists",
-						newname)));
-
-	/* must be owner */
-	if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
-					   NameListToString(oldname));
-
-	/* must have CREATE privilege on namespace */
-	aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
-	aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-				   get_namespace_name(namespaceOid));
-
-	namestrcpy(&(((Form_pg_ts_config) GETSTRUCT(tup))->cfgname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-/*
  * Guts of TS configuration deletion.
  */
 void
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e4ff76e..525e690 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -6772,7 +6772,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 				{
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_FDW;
-					n->subname = $5;
+					n->object = list_make1(makeString($5));
 					n->newname = $8;
 					n->missing_ok = false;
 					$$ = (Node *)n;
@@ -6800,7 +6800,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 				{
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_LANGUAGE;
-					n->subname = $4;
+					n->object = list_make1(makeString($4));
 					n->newname = $7;
 					n->missing_ok = false;
 					$$ = (Node *)n;
@@ -6838,7 +6838,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 				{
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_FOREIGN_SERVER;
-					n->subname = $3;
+					n->object = list_make1(makeString($3));
 					n->newname = $6;
 					n->missing_ok = false;
 					$$ = (Node *)n;
@@ -7011,7 +7011,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 				{
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_EVENT_TRIGGER;
-					n->subname = $4;
+					n->object = list_make1(makeString($4));
 					n->newname = $7;
 					$$ = (Node *)n;
 				}
diff --git a/src/include/commands/alter.h b/src/include/commands/alter.h
index 4493985..4d0ed8a 100644
--- a/src/include/commands/alter.h
+++ b/src/include/commands/alter.h
@@ -18,6 +18,8 @@
 #include "nodes/parsenodes.h"
 #include "utils/relcache.h"
 
+extern void AlterObjectRename_internal(Relation rel, Oid objid,
+									   const char *newname);
 extern void ExecRenameStmt(RenameStmt *stmt);
 
 extern void ExecAlterObjectSchemaStmt(AlterObjectSchemaStmt *stmt);
diff --git a/src/include/commands/conversioncmds.h b/src/include/commands/conversioncmds.h
index 2f9abad..27048cb 100644
--- a/src/include/commands/conversioncmds.h
+++ b/src/include/commands/conversioncmds.h
@@ -18,6 +18,5 @@
 #include "nodes/parsenodes.h"
 
 extern void CreateConversionCommand(CreateConversionStmt *parsetree);
-extern void RenameConversion(List *name, const char *newname);
 
 #endif   /* CONVERSIONCMDS_H */
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index 2c81b78..d5d4b98 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -102,8 +102,6 @@ extern text *serialize_deflist(List *deflist);
 extern List *deserialize_deflist(Datum txt);
 
 /* commands/foreigncmds.c */
-extern void RenameForeignServer(const char *oldname, const char *newname);
-extern void RenameForeignDataWrapper(const char *oldname, const char *newname);
 extern void AlterForeignServerOwner(const char *name, Oid newOwnerId);
 extern void AlterForeignServerOwner_oid(Oid, Oid newOwnerId);
 extern void AlterForeignDataWrapperOwner(const char *name, Oid newOwnerId);
diff --git a/src/include/commands/event_trigger.h b/src/include/commands/event_trigger.h
index 459d27f..9d2123f 100644
--- a/src/include/commands/event_trigger.h
+++ b/src/include/commands/event_trigger.h
@@ -36,7 +36,6 @@ extern void RemoveEventTriggerById(Oid ctrigOid);
 extern Oid	get_event_trigger_oid(const char *trigname, bool missing_ok);
 
 extern void AlterEventTrigger(AlterEventTrigStmt *stmt);
-extern void RenameEventTrigger(const char* trigname, const char *newname);
 extern void AlterEventTriggerOwner(const char *name, Oid newOwnerId);
 extern void AlterEventTriggerOwner_oid(Oid, Oid newOwnerId);
 
diff --git a/src/include/commands/proclang.h b/src/include/commands/proclang.h
index faf1f1c..3349d4e 100644
--- a/src/include/commands/proclang.h
+++ b/src/include/commands/proclang.h
@@ -16,7 +16,6 @@
 
 extern void CreateProceduralLanguage(CreatePLangStmt *stmt);
 extern void DropProceduralLanguageById(Oid langOid);
-extern void RenameLanguage(const char *oldname, const char *newname);
 extern bool PLTemplateExists(const char *languageName);
 extern Oid	get_language_oid(const char *langname, bool missing_ok);
 
diff --git a/src/test/regress/expected/alter_generic.out b/src/test/regress/expected/alter_generic.out
index 3beddd7..43fcc55 100644
--- a/src/test/regress/expected/alter_generic.out
+++ b/src/test/regress/expected/alter_generic.out
@@ -110,7 +110,7 @@ SET SESSION AUTHORIZATION regtest_alter_user1;
 CREATE CONVERSION alt_conv1 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
 CREATE CONVERSION alt_conv2 FOR 'LATIN1' TO 'UTF8' FROM iso8859_1_to_utf8;
 ALTER CONVERSION alt_conv1 RENAME TO alt_conv2;  -- failed (name conflict)
-ERROR:  conversion "alt_conv2" already exists in schema "alt_nsp1"
+ERROR:  conversion alt_conv2 already exists in schema "alt_nsp1"
 ALTER CONVERSION alt_conv1 RENAME TO alt_conv3;  -- OK
 ALTER CONVERSION alt_conv2 OWNER TO regtest_alter_user2;  -- failed (no role membership)
 ERROR:  must be member of role "regtest_alter_user2"
@@ -152,10 +152,10 @@ CREATE FOREIGN DATA WRAPPER alt_fdw2;
 CREATE SERVER alt_fserv1 FOREIGN DATA WRAPPER alt_fdw1;
 CREATE SERVER alt_fserv2 FOREIGN DATA WRAPPER alt_fdw2;
 ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw2;  -- failed (name conflict)
-ERROR:  foreign-data wrapper "alt_fdw2" already exists
+ERROR:  foreign-data wrapper alt_fdw2 already exists
 ALTER FOREIGN DATA WRAPPER alt_fdw1 RENAME TO alt_fdw3;  -- OK
 ALTER SERVER alt_fserv1 RENAME TO alt_fserv2;   -- failed (name conflict)
-ERROR:  server "alt_fserv2" already exists
+ERROR:  server alt_fserv2 already exists
 ALTER SERVER alt_fserv1 RENAME TO alt_fserv3;   -- OK
 SELECT fdwname FROM pg_foreign_data_wrapper WHERE fdwname like 'alt_fdw%';
  fdwname  
@@ -180,7 +180,7 @@ ALTER LANGUAGE alt_lang1 OWNER TO regtest_alter_user1;  -- OK
 ALTER LANGUAGE alt_lang2 OWNER TO regtest_alter_user2;  -- OK
 SET SESSION AUTHORIZATION regtest_alter_user1;
 ALTER LANGUAGE alt_lang1 RENAME TO alt_lang2;   -- failed (name conflict)
-ERROR:  language "alt_lang2" already exists
+ERROR:  language alt_lang2 already exists
 ALTER LANGUAGE alt_lang2 RENAME TO alt_lang3;   -- failed (not owner)
 ERROR:  must be owner of language alt_lang2
 ALTER LANGUAGE alt_lang1 RENAME TO alt_lang3;   -- OK
@@ -327,7 +327,7 @@ SET SESSION AUTHORIZATION regtest_alter_user1;
 CREATE TEXT SEARCH DICTIONARY alt_ts_dict1 (template=simple);
 CREATE TEXT SEARCH DICTIONARY alt_ts_dict2 (template=simple);
 ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict2;  -- failed (name conflict)
-ERROR:  text search dictionary "alt_ts_dict2" already exists
+ERROR:  text search dictionary alt_ts_dict2 already exists in schema "alt_nsp1"
 ALTER TEXT SEARCH DICTIONARY alt_ts_dict1 RENAME TO alt_ts_dict3;  -- OK
 ALTER TEXT SEARCH DICTIONARY alt_ts_dict2 OWNER TO regtest_alter_user2;  -- failed (no role membership)
 ERROR:  must be member of role "regtest_alter_user2"
@@ -368,7 +368,7 @@ SET SESSION AUTHORIZATION regtest_alter_user1;
 CREATE TEXT SEARCH CONFIGURATION alt_ts_conf1 (copy=english);
 CREATE TEXT SEARCH CONFIGURATION alt_ts_conf2 (copy=english);
 ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf2;  -- failed (name conflict)
-ERROR:  text search configuration "alt_ts_conf2" already exists
+ERROR:  text search configuration alt_ts_conf2 already exists in schema "alt_nsp1"
 ALTER TEXT SEARCH CONFIGURATION alt_ts_conf1 RENAME TO alt_ts_conf3;  -- OK
 ALTER TEXT SEARCH CONFIGURATION alt_ts_conf2 OWNER TO regtest_alter_user2;  -- failed (no role membership)
 ERROR:  must be member of role "regtest_alter_user2"
@@ -408,7 +408,7 @@ SELECT nspname, cfgname, rolname
 CREATE TEXT SEARCH TEMPLATE alt_ts_temp1 (lexize=dsimple_lexize);
 CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
 ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp2; -- failed (name conflict)
-ERROR:  text search template "alt_ts_temp2" already exists
+ERROR:  text search template alt_ts_temp2 already exists in schema "alt_nsp1"
 ALTER TEXT SEARCH TEMPLATE alt_ts_temp1 RENAME TO alt_ts_temp3; -- OK
 ALTER TEXT SEARCH TEMPLATE alt_ts_temp2 SET SCHEMA alt_nsp2;    -- OK
 CREATE TEXT SEARCH TEMPLATE alt_ts_temp2 (lexize=dsimple_lexize);
@@ -433,7 +433,7 @@ CREATE TEXT SEARCH PARSER alt_ts_prs1
 CREATE TEXT SEARCH PARSER alt_ts_prs2
     (start = prsd_start, gettoken = prsd_nexttoken, end = prsd_end, lextypes = prsd_lextype);
 ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs2; -- failed (name conflict)
-ERROR:  text search parser "alt_ts_prs2" already exists
+ERROR:  text search parser alt_ts_prs2 already exists in schema "alt_nsp1"
 ALTER TEXT SEARCH PARSER alt_ts_prs1 RENAME TO alt_ts_prs3; -- OK
 ALTER TEXT SEARCH PARSER alt_ts_prs2 SET SCHEMA alt_nsp2;   -- OK
 CREATE TEXT SEARCH PARSER alt_ts_prs2
diff --git a/src/test/regress/expected/event_trigger.out b/src/test/regress/expected/event_trigger.out
index 5c8f323..67997bd 100644
--- a/src/test/regress/expected/event_trigger.out
+++ b/src/test/regress/expected/event_trigger.out
@@ -77,7 +77,7 @@ alter role regression_bob superuser;
 alter event trigger regress_event_trigger owner to regression_bob;
 -- should fail, name collision
 alter event trigger regress_event_trigger rename to regress_event_trigger2;
-ERROR:  event trigger "regress_event_trigger2" already exists
+ERROR:  event trigger regress_event_trigger2 already exists
 -- OK
 alter event trigger regress_event_trigger rename to regress_event_trigger3;
 -- should fail, doesn't exist any more
