 src/backend/catalog/objectaddress.c        |   14 ++
 src/backend/commands/aggregatecmds.c       |   61 ------
 src/backend/commands/alter.c               |  315 +++++++++++++++++++---------
 src/backend/commands/collationcmds.c       |   66 ------
 src/backend/commands/conversioncmds.c      |   51 -----
 src/backend/commands/functioncmds.c        |   68 ------
 src/backend/commands/opclasscmds.c         |  148 -------------
 src/backend/commands/proclang.c            |   41 ----
 src/backend/commands/schemacmds.c          |   51 -----
 src/backend/commands/tablespace.c          |   69 ------
 src/backend/commands/tsearchcmds.c         |  188 -----------------
 src/backend/parser/gram.y                  |   12 +-
 src/include/catalog/objectaddress.h        |    2 +-
 src/include/commands/collationcmds.h       |    1 -
 src/include/commands/conversioncmds.h      |    1 -
 src/include/commands/defrem.h              |    8 -
 src/test/regress/expected/alter_rename.out |   14 +-
 17 files changed, 249 insertions(+), 861 deletions(-)

diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 9162c26..e295fa3 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -1485,6 +1485,20 @@ get_object_tuple(ObjectAddress address)
 }
 
 /*
+ * get_object_name_attnum
+ *
+ * It returns attribute number of name of the given object type,
+ * or InvalidAttrNumber if it does not have name column.
+ */
+AttrNumber
+get_object_name_attnum(const ObjectAddress *address)
+{
+	ObjectPropertyType *property
+		= get_object_property_data(address->classId);
+	return property->attnum_name;
+}
+
+/*
  * get_object_namespace_attnum
  *
  * It returns attribute number of namespace of the given object type,
diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c
index 085a205..c50761f 100644
--- a/src/backend/commands/aggregatecmds.c
+++ b/src/backend/commands/aggregatecmds.c
@@ -206,67 +206,6 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
 					initval);	/* initial condition */
 }
 
-
-/*
- * RenameAggregate
- *		Rename an aggregate.
- */
-void
-RenameAggregate(List *name, List *args, const char *newname)
-{
-	Oid			procOid;
-	Oid			namespaceOid;
-	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 */
-		elog(ERROR, "cache lookup failed for function %u", procOid);
-	procForm = (Form_pg_proc) GETSTRUCT(tup);
-
-	namespaceOid = procForm->pronamespace;
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists3(PROCNAMEARGSNSP,
-							  CStringGetDatum(newname),
-							  PointerGetDatum(&procForm->proargtypes),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_FUNCTION),
-				 errmsg("function %s already exists in schema \"%s\"",
-						funcname_signature_string(newname,
-												  procForm->pronargs,
-												  NIL,
-											   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);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
 /*
  * Change aggregate owner
  */
diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c
index 2d60a99..9218edf 100644
--- a/src/backend/commands/alter.c
+++ b/src/backend/commands/alter.c
@@ -14,6 +14,7 @@
  */
 #include "postgres.h"
 
+#include "catalog/catalog.h"
 #include "catalog/dependency.h"
 #include "catalog/indexing.h"
 #include "catalog/namespace.h"
@@ -39,58 +40,216 @@
 #include "utils/rel.h"
 #include "utils/syscache.h"
 
+static void
+error_already_exist(ObjectType objtype,
+					const char *new_name, const char *nsp_name)
+{
+	const char *msg;
+	int			code = ERRCODE_DUPLICATE_OBJECT;
+
+	switch (objtype)
+	{
+        case OBJECT_FUNCTION:
+		case OBJECT_AGGREGATE:
+			code = ERRCODE_DUPLICATE_FUNCTION;
+			msg = gettext_noop("function %s already exists in schema \"%s\"");
+			break;
+        case OBJECT_COLLATION:
+			msg = gettext_noop("collation \"%s\" already exists in schema \"%s\"");
+			break;
+        case OBJECT_CONVERSION:
+			msg = gettext_noop("conversion \"%s\" already exists in schema \"%s\"");
+			break;
+        case OBJECT_LANGUAGE:
+			msg = gettext_noop("language \"%s\" already exists");
+			break;
+        case OBJECT_OPCLASS:
+			msg = gettext_noop("operator class \"%s\" already exists in schema \"%s\"");
+			break;
+        case OBJECT_OPFAMILY:
+			msg = gettext_noop("operator family \"%s\" already exists in schema \"%s\"");
+			break;
+        case OBJECT_TSPARSER:
+			msg = gettext_noop("text search parser \"%s\" already exists in shcema \"%s\"");
+			break;
+        case OBJECT_TSDICTIONARY:
+			msg = gettext_noop("text search dictionary \"%s\" already exists in shema \"%s\"");
+			break;
+        case OBJECT_TSTEMPLATE:
+			msg = gettext_noop("text search template \"%s\" already exists in schema \"%s\"");
+			break;
+        case OBJECT_TSCONFIGURATION:
+			msg = gettext_noop("text search configuration \"%s\" already exists in schema \"%s\"");
+			break;
+        case OBJECT_SCHEMA:
+			msg = gettext_noop("schema \"%s\" already exists");
+			break;
+        case OBJECT_TABLESPACE:
+			msg = gettext_noop("tablespace \"%s\" already exists");
+			break;
+		default:
+			elog(ERROR, "unexpected object type (%d)", (int)objtype);
+			return;
+	}
+	if (nsp_name)
+		ereport(ERROR, (errcode(code), errmsg(msg, new_name, nsp_name)));
+	else
+		ereport(ERROR, (errcode(code), errmsg(msg, new_name)));
+}
 
 /*
- * Executes an ALTER OBJECT / RENAME TO statement.	Based on the object
- * type, the function appropriate to that type is executed.
+ * AltereObjectRenameInternal
+ *
+ * Generic function to change the name of a 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).
  */
-void
-ExecRenameStmt(RenameStmt *stmt)
+static void
+AltereObjectRenameInternal(ObjectType objtype, ObjectAddress address,
+						   const char *new_name, Relation relation)
 {
-	switch (stmt->renameType)
+	Relation	catalog;
+	AttrNumber	Anum_name;
+	Oid			namespaceId = InvalidOid;
+	HeapTuple	oldtup;
+	HeapTuple	newtup;
+	NameData	namebuf;
+	AclResult	aclresult;
+	Datum	   *values;
+	bool	   *nulls;
+	bool	   *replaces;
+
+	catalog = heap_open(address.classId, RowExclusiveLock);
+
+	Anum_name = get_object_name_attnum(&address);
+	namespaceId = get_object_namespace(&address);
+
+	/* must have ownership of the obejct being renamed */
+	check_object_ownership(GetUserId(), address, relation);
+
+	switch (objtype)
 	{
-		case OBJECT_AGGREGATE:
-			RenameAggregate(stmt->object, stmt->objarg, stmt->newname);
+		case OBJECT_LANGUAGE:
+			/* nothing to check more than ownership */
 			break;
 
-		case OBJECT_COLLATION:
-			RenameCollation(stmt->object, stmt->newname);
-			break;
+		case OBJECT_SCHEMA:
+			/* must have CREATE privilege on database */
+			aclresult = pg_database_aclcheck(MyDatabaseId,
+											 GetUserId(), ACL_CREATE);
+			if (aclresult != ACLCHECK_OK)
+				aclcheck_error(aclresult, ACL_KIND_DATABASE,
+							   get_database_name(MyDatabaseId));
 
-		case OBJECT_CONVERSION:
-			RenameConversion(stmt->object, stmt->newname);
+			if (!allowSystemTableMods && IsReservedName(new_name))
+				ereport(ERROR,
+						(errcode(ERRCODE_RESERVED_NAME),
+						 errmsg("unacceptable schema name \"%s\"", new_name),
+				errdetail("The prefix \"pg_\" is reserved for system schemas.")));
 			break;
 
-		case OBJECT_DATABASE:
-			RenameDatabase(stmt->subname, stmt->newname);
+		case OBJECT_TABLESPACE:
+			if (!allowSystemTableMods && IsReservedName(new_name))
+				ereport(ERROR,
+						(errcode(ERRCODE_RESERVED_NAME),
+						 errmsg("unacceptable tablespace name \"%s\"", new_name),
+				errdetail("The prefix \"pg_\" is reserved for system tablespaces.")));
 			break;
 
-		case OBJECT_FUNCTION:
-			RenameFunction(stmt->object, stmt->objarg, stmt->newname);
+		default:
+			/* must have CREATE privilege on namespace */
+			namespaceId = get_object_namespace(&address);
+			Assert(OidIsValid(namespaceId));
+			aclresult = pg_namespace_aclcheck(namespaceId,
+											  GetUserId(), ACL_CREATE);
+			if (aclresult != ACLCHECK_OK)
+				aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
+							   get_namespace_name(namespaceId));
 			break;
+	}
 
-		case OBJECT_LANGUAGE:
-			RenameLanguage(stmt->subname, stmt->newname);
-			break;
+	/*
+	 * Check for duplicate names
+	 */
+	if (object_exists_namespace(address, InvalidOid, new_name))
+		error_already_exist(objtype, new_name,
+							!OidIsValid(namespaceId) ? NULL
+							: get_namespace_name(namespaceId));
+
+	/*
+	 * Build modified tuple
+	 */
+	oldtup = get_object_tuple(address);
 
-		case OBJECT_OPCLASS:
-			RenameOpClass(stmt->object, stmt->subname, stmt->newname);
-			break;
+	values = palloc0(RelationGetNumberOfAttributes(catalog) * sizeof(Datum));
+	nulls = palloc0(RelationGetNumberOfAttributes(catalog) * sizeof(bool));
+	replaces = palloc0(RelationGetNumberOfAttributes(catalog) * sizeof(bool));
+
+	namestrcpy(&namebuf, new_name);
+	values[Anum_name - 1] = NameGetDatum(&namebuf);
+	replaces[Anum_name - 1] = true;
+	newtup = heap_modify_tuple(oldtup, RelationGetDescr(catalog),
+							   values, nulls, replaces);
+
+	/* Perform actual update */
+	simple_heap_update(catalog, &oldtup->t_self, newtup);
+	CatalogUpdateIndexes(catalog, newtup);
+
+	/* Release memory */
+	pfree(values);
+	pfree(nulls);
+	pfree(replaces);
+
+	heap_close(catalog, NoLock);
+}
+
+/*
+ * Executes an ALTER OBJECT / RENAME TO statement.	Based on the object
+ * type, the function appropriate to that type is executed.
+ */
+void
+ExecRenameStmt(RenameStmt *stmt)
+{
+	ObjectAddress	address;
+	Relation		relation;
+	Oid				relid;
 
+	switch (stmt->renameType)
+	{
+		case OBJECT_AGGREGATE:
+		case OBJECT_COLLATION:
+		case OBJECT_CONVERSION:
+		case OBJECT_FUNCTION:
+		case OBJECT_LANGUAGE:
+		case OBJECT_OPCLASS:
 		case OBJECT_OPFAMILY:
-			RenameOpFamily(stmt->object, stmt->subname, stmt->newname);
+		case OBJECT_TSPARSER:
+		case OBJECT_TSDICTIONARY:
+		case OBJECT_TSTEMPLATE:
+		case OBJECT_TSCONFIGURATION:
+		case OBJECT_SCHEMA:
+		case OBJECT_TABLESPACE:
+			address = get_object_address(stmt->renameType,
+										 stmt->object,
+										 stmt->objarg,
+										 &relation,
+										 AccessExclusiveLock,
+										 false);
+			AltereObjectRenameInternal(stmt->renameType, address,
+									   stmt->newname, relation);
+			if (relation)
+				heap_close(relation, NoLock);
 			break;
 
+		case OBJECT_DATABASE:
+			RenameDatabase(stmt->subname, stmt->newname);
+			break;
 		case OBJECT_ROLE:
 			RenameRole(stmt->subname, stmt->newname);
 			break;
 
-		case OBJECT_SCHEMA:
-			RenameSchema(stmt->subname, stmt->newname);
-			break;
-
-		case OBJECT_TABLESPACE:
-			RenameTableSpace(stmt->subname, stmt->newname);
+		case OBJECT_TYPE:
+			RenameType(stmt->object, stmt->newname);
 			break;
 
 		case OBJECT_TABLE:
@@ -101,77 +260,43 @@ ExecRenameStmt(RenameStmt *stmt)
 		case OBJECT_ATTRIBUTE:
 		case OBJECT_TRIGGER:
 		case OBJECT_FOREIGN_TABLE:
+			CheckRelationOwnership(stmt->relation, true);
+			/*
+			 * Lock level used here should match what will be taken later,
+			 * in RenameRelation, renameatt, or renametrig.
+			 */
+			relid = RangeVarGetRelid(stmt->relation, AccessExclusiveLock,
+									 false, false);
+			if (stmt->renameType == OBJECT_COLUMN ||
+				stmt->renameType == OBJECT_ATTRIBUTE)
+			{
+				renameatt(relid, stmt);
+			}
+			else if (stmt->renameType == OBJECT_TRIGGER)
+			{
+				renametrig(relid,
+						   stmt->subname,		/* old att name */
+						   stmt->newname);		/* new att name */
+			}
+			else
 			{
-				Oid			relid;
-
-				CheckRelationOwnership(stmt->relation, true);
-
 				/*
-				 * Lock level used here should match what will be taken later,
-				 * in RenameRelation, renameatt, or renametrig.
+				 * RENAME TABLE requires that we (still) hold
+				 * CREATE rights on the containing namespace, as
+				 * well as ownership of the table.
 				 */
-				relid = RangeVarGetRelid(stmt->relation, AccessExclusiveLock,
-										 false, false);
-
-				switch (stmt->renameType)
-				{
-					case OBJECT_TABLE:
-					case OBJECT_SEQUENCE:
-					case OBJECT_VIEW:
-					case OBJECT_INDEX:
-					case OBJECT_FOREIGN_TABLE:
-						{
-							/*
-							 * RENAME TABLE requires that we (still) hold
-							 * CREATE rights on the containing namespace, as
-							 * well as ownership of the table.
-							 */
-							Oid			namespaceId = get_rel_namespace(relid);
-							AclResult	aclresult;
-
-							aclresult = pg_namespace_aclcheck(namespaceId,
-															  GetUserId(),
-															  ACL_CREATE);
-							if (aclresult != ACLCHECK_OK)
-								aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
-											get_namespace_name(namespaceId));
-
-							RenameRelation(relid, stmt->newname, stmt->renameType);
-							break;
-						}
-					case OBJECT_COLUMN:
-					case OBJECT_ATTRIBUTE:
-						renameatt(relid, stmt);
-						break;
-					case OBJECT_TRIGGER:
-						renametrig(relid,
-								   stmt->subname,		/* old att name */
-								   stmt->newname);		/* new att name */
-						break;
-					default:
-						 /* can't happen */ ;
-				}
-				break;
-			}
-
-		case OBJECT_TSPARSER:
-			RenameTSParser(stmt->object, stmt->newname);
-			break;
+				Oid			namespaceId = get_rel_namespace(relid);
+				AclResult	aclresult;
 
-		case OBJECT_TSDICTIONARY:
-			RenameTSDictionary(stmt->object, stmt->newname);
-			break;
+				aclresult = pg_namespace_aclcheck(namespaceId,
+												  GetUserId(),
+												  ACL_CREATE);
+				if (aclresult != ACLCHECK_OK)
+					aclcheck_error(aclresult, ACL_KIND_NAMESPACE,
+								   get_namespace_name(namespaceId));
 
-		case OBJECT_TSTEMPLATE:
-			RenameTSTemplate(stmt->object, stmt->newname);
-			break;
-
-		case OBJECT_TSCONFIGURATION:
-			RenameTSConfiguration(stmt->object, stmt->newname);
-			break;
-
-		case OBJECT_TYPE:
-			RenameType(stmt->object, stmt->newname);
+				RenameRelation(relid, stmt->newname, stmt->renameType);
+			}
 			break;
 
 		default:
diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c
index 09020d1..f219d6e 100644
--- a/src/backend/commands/collationcmds.c
+++ b/src/backend/commands/collationcmds.c
@@ -145,72 +145,6 @@ DefineCollation(List *names, List *parameters)
 }
 
 /*
- * Rename collation
- */
-void
-RenameCollation(List *name, const char *newname)
-{
-	Oid			collationOid;
-	Oid			namespaceOid;
-	HeapTuple	tup;
-	Relation	rel;
-	AclResult	aclresult;
-
-	rel = heap_open(CollationRelationId, RowExclusiveLock);
-
-	collationOid = get_collation_oid(name, false);
-
-	tup = SearchSysCacheCopy1(COLLOID, ObjectIdGetDatum(collationOid));
-	if (!HeapTupleIsValid(tup)) /* should not happen */
-		elog(ERROR, "cache lookup failed for collation %u", collationOid);
-
-	namespaceOid = ((Form_pg_collation) GETSTRUCT(tup))->collnamespace;
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists3(COLLNAMEENCNSP,
-							  CStringGetDatum(newname),
-							  Int32GetDatum(GetDatabaseEncoding()),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("collation \"%s\" for encoding \"%s\" already exists in schema \"%s\"",
-						newname,
-						GetDatabaseEncodingName(),
-						get_namespace_name(namespaceOid))));
-
-	/* mustn't match an any-encoding entry, either */
-	if (SearchSysCacheExists3(COLLNAMEENCNSP,
-							  CStringGetDatum(newname),
-							  Int32GetDatum(-1),
-							  ObjectIdGetDatum(namespaceOid)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("collation \"%s\" already exists in schema \"%s\"",
-						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);
-
-	heap_close(rel, RowExclusiveLock);
-}
-
-/*
  * Change collation owner, by name
  */
 void
diff --git a/src/backend/commands/conversioncmds.c b/src/backend/commands/conversioncmds.c
index 950f870..5b61cf0 100644
--- a/src/backend/commands/conversioncmds.c
+++ b/src/backend/commands/conversioncmds.c
@@ -118,57 +118,6 @@ CreateConversionCommand(CreateConversionStmt *stmt)
 }
 
 /*
- * 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);
-}
-
-/*
  * Change conversion owner, by name
  */
 void
diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 5102d87..1821c61 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1013,74 +1013,6 @@ RemoveFunctionById(Oid funcOid)
 	}
 }
 
-
-/*
- * Rename function
- */
-void
-RenameFunction(List *name, List *argtypes, const char *newname)
-{
-	Oid			procOid;
-	Oid			namespaceOid;
-	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 */
-		elog(ERROR, "cache lookup failed for function %u", procOid);
-	procForm = (Form_pg_proc) GETSTRUCT(tup);
-
-	if (procForm->proisagg)
-		ereport(ERROR,
-				(errcode(ERRCODE_WRONG_OBJECT_TYPE),
-				 errmsg("\"%s\" is an aggregate function",
-						NameListToString(name)),
-			 errhint("Use ALTER AGGREGATE to rename aggregate functions.")));
-
-	namespaceOid = procForm->pronamespace;
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists3(PROCNAMEARGSNSP,
-							  CStringGetDatum(newname),
-							  PointerGetDatum(&procForm->proargtypes),
-							  ObjectIdGetDatum(namespaceOid)))
-	{
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_FUNCTION),
-				 errmsg("function %s already exists in schema \"%s\"",
-						funcname_signature_string(newname,
-												  procForm->pronargs,
-												  NIL,
-											   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);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
 /*
  * Change function owner by name and args
  */
diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c
index 7598561..1e16d32 100644
--- a/src/backend/commands/opclasscmds.c
+++ b/src/backend/commands/opclasscmds.c
@@ -1642,154 +1642,6 @@ RemoveAmProcEntryById(Oid entryOid)
 	heap_close(rel, RowExclusiveLock);
 }
 
-
-/*
- * Rename opclass
- */
-void
-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);
-	opcOid = HeapTupleGetOid(tup);
-	namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists3(CLAAMNAMENSP,
-							  ObjectIdGetDatum(amOid),
-							  CStringGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-	{
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("operator class \"%s\" for access method \"%s\" already exists in schema \"%s\"",
-						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);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
-/*
- * Rename opfamily
- */
-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;
-
-	amOid = get_am_oid(access_method, false);
-
-	rel = heap_open(OperatorFamilyRelationId, RowExclusiveLock);
-
-	/*
-	 * Look up the opfamily
-	 */
-	DeconstructQualifiedName(name, &schemaname, &opfname);
-
-	if (schemaname)
-	{
-		namespaceOid = LookupExplicitNamespace(schemaname);
-
-		tup = SearchSysCacheCopy3(OPFAMILYAMNAMENSP,
-								  ObjectIdGetDatum(amOid),
-								  PointerGetDatum(opfname),
-								  ObjectIdGetDatum(namespaceOid));
-		if (!HeapTupleIsValid(tup))
-			ereport(ERROR,
-					(errcode(ERRCODE_UNDEFINED_OBJECT),
-					 errmsg("operator family \"%s\" does not exist for access method \"%s\"",
-							opfname, access_method)));
-
-		opfOid = HeapTupleGetOid(tup);
-	}
-	else
-	{
-		opfOid = OpfamilynameGetOpfid(amOid, opfname);
-		if (!OidIsValid(opfOid))
-			ereport(ERROR,
-					(errcode(ERRCODE_UNDEFINED_OBJECT),
-					 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);
-
-		namespaceOid = ((Form_pg_opfamily) GETSTRUCT(tup))->opfnamespace;
-	}
-
-	/* make sure the new name doesn't exist */
-	if (SearchSysCacheExists3(OPFAMILYAMNAMENSP,
-							  ObjectIdGetDatum(amOid),
-							  CStringGetDatum(newname),
-							  ObjectIdGetDatum(namespaceOid)))
-	{
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("operator family \"%s\" for access method \"%s\" already exists in schema \"%s\"",
-						newname, access_method,
-						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);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
 /*
  * Change opclass owner by name
  */
diff --git a/src/backend/commands/proclang.c b/src/backend/commands/proclang.c
index b7ed1a4..370b2a7 100644
--- a/src/backend/commands/proclang.c
+++ b/src/backend/commands/proclang.c
@@ -536,47 +536,6 @@ DropProceduralLanguageById(Oid langOid)
 }
 
 /*
- * Rename language
- */
-void
-RenameLanguage(const char *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-
-	/* Translate both names for consistency with CREATE */
-	oldname = case_translate_language_name(oldname);
-	newname = case_translate_language_name(newname);
-
-	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);
-}
-
-/*
  * Change language owner
  */
 void
diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c
index 8daa9d0..a22fbcd 100644
--- a/src/backend/commands/schemacmds.c
+++ b/src/backend/commands/schemacmds.c
@@ -169,57 +169,6 @@ RemoveSchemaById(Oid schemaOid)
 	heap_close(relation, RowExclusiveLock);
 }
 
-
-/*
- * Rename schema
- */
-void
-RenameSchema(const char *oldname, const char *newname)
-{
-	HeapTuple	tup;
-	Relation	rel;
-	AclResult	aclresult;
-
-	rel = heap_open(NamespaceRelationId, RowExclusiveLock);
-
-	tup = SearchSysCacheCopy1(NAMESPACENAME, CStringGetDatum(oldname));
-	if (!HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_SCHEMA),
-				 errmsg("schema \"%s\" does not exist", oldname)));
-
-	/* make sure the new name doesn't exist */
-	if (OidIsValid(get_namespace_oid(newname, true)))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_SCHEMA),
-				 errmsg("schema \"%s\" already exists", newname)));
-
-	/* must be owner */
-	if (!pg_namespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
-		aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_NAMESPACE,
-					   oldname);
-
-	/* must have CREATE privilege on database */
-	aclresult = pg_database_aclcheck(MyDatabaseId, GetUserId(), ACL_CREATE);
-	if (aclresult != ACLCHECK_OK)
-		aclcheck_error(aclresult, ACL_KIND_DATABASE,
-					   get_database_name(MyDatabaseId));
-
-	if (!allowSystemTableMods && IsReservedName(newname))
-		ereport(ERROR,
-				(errcode(ERRCODE_RESERVED_NAME),
-				 errmsg("unacceptable schema name \"%s\"", newname),
-		   errdetail("The prefix \"pg_\" is reserved for system schemas.")));
-
-	/* rename */
-	namestrcpy(&(((Form_pg_namespace) GETSTRUCT(tup))->nspname), newname);
-	simple_heap_update(rel, &tup->t_self, tup);
-	CatalogUpdateIndexes(rel, tup);
-
-	heap_close(rel, NoLock);
-	heap_freetuple(tup);
-}
-
 void
 AlterSchemaOwner_oid(Oid oid, Oid newOwnerId)
 {
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index d223f8c..37a6b5e 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -781,75 +781,6 @@ directory_is_empty(const char *path)
 	return true;
 }
 
-
-/*
- * Rename a tablespace
- */
-void
-RenameTableSpace(const char *oldname, const char *newname)
-{
-	Relation	rel;
-	ScanKeyData entry[1];
-	HeapScanDesc scan;
-	HeapTuple	tup;
-	HeapTuple	newtuple;
-	Form_pg_tablespace newform;
-
-	/* Search pg_tablespace */
-	rel = heap_open(TableSpaceRelationId, RowExclusiveLock);
-
-	ScanKeyInit(&entry[0],
-				Anum_pg_tablespace_spcname,
-				BTEqualStrategyNumber, F_NAMEEQ,
-				CStringGetDatum(oldname));
-	scan = heap_beginscan(rel, SnapshotNow, 1, entry);
-	tup = heap_getnext(scan, ForwardScanDirection);
-	if (!HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_UNDEFINED_OBJECT),
-				 errmsg("tablespace \"%s\" does not exist",
-						oldname)));
-
-	newtuple = heap_copytuple(tup);
-	newform = (Form_pg_tablespace) GETSTRUCT(newtuple);
-
-	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,
-				(errcode(ERRCODE_RESERVED_NAME),
-				 errmsg("unacceptable tablespace name \"%s\"", newname),
-		errdetail("The prefix \"pg_\" is reserved for system tablespaces.")));
-
-	/* Make sure the new name doesn't exist */
-	ScanKeyInit(&entry[0],
-				Anum_pg_tablespace_spcname,
-				BTEqualStrategyNumber, F_NAMEEQ,
-				CStringGetDatum(newname));
-	scan = heap_beginscan(rel, SnapshotNow, 1, entry);
-	tup = heap_getnext(scan, ForwardScanDirection);
-	if (HeapTupleIsValid(tup))
-		ereport(ERROR,
-				(errcode(ERRCODE_DUPLICATE_OBJECT),
-				 errmsg("tablespace \"%s\" already exists",
-						newname)));
-
-	heap_endscan(scan);
-
-	/* OK, update the entry */
-	namestrcpy(&(newform->spcname), newname);
-
-	simple_heap_update(rel, &newtuple->t_self, newtuple);
-	CatalogUpdateIndexes(rel, newtuple);
-
-	heap_close(rel, NoLock);
-}
-
 /*
  * Change tablespace owner
  */
diff --git a/src/backend/commands/tsearchcmds.c b/src/backend/commands/tsearchcmds.c
index 471d6d1..73b8c0d 100644
--- a/src/backend/commands/tsearchcmds.c
+++ b/src/backend/commands/tsearchcmds.c
@@ -301,49 +301,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 -----------------------*/
 
 /*
@@ -527,57 +484,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
@@ -950,50 +856,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
@@ -1289,56 +1151,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 7940121..b79b654 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -6487,7 +6487,8 @@ 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->objarg = NIL;
 					n->newname = $7;
 					$$ = (Node *)n;
 				}
@@ -6496,7 +6497,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_OPCLASS;
 					n->object = $4;
-					n->subname = $6;
+					n->objarg = list_make1(makeString($6));
 					n->newname = $9;
 					$$ = (Node *)n;
 				}
@@ -6505,7 +6506,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_OPFAMILY;
 					n->object = $4;
-					n->subname = $6;
+					n->objarg = list_make1(makeString($6));
 					n->newname = $9;
 					$$ = (Node *)n;
 				}
@@ -6513,7 +6514,8 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 				{
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_SCHEMA;
-					n->subname = $3;
+					n->object = list_make1(makeString($3));
+					n->objarg = NIL;
 					n->newname = $6;
 					$$ = (Node *)n;
 				}
@@ -6611,7 +6613,7 @@ RenameStmt: ALTER AGGREGATE func_name aggr_args RENAME TO name
 				{
 					RenameStmt *n = makeNode(RenameStmt);
 					n->renameType = OBJECT_TABLESPACE;
-					n->subname = $3;
+					n->object = list_make1(makeString($3));
 					n->newname = $6;
 					$$ = (Node *)n;
 				}
diff --git a/src/include/catalog/objectaddress.h b/src/include/catalog/objectaddress.h
index a5d3325..bc46a80 100644
--- a/src/include/catalog/objectaddress.h
+++ b/src/include/catalog/objectaddress.h
@@ -41,7 +41,7 @@ extern bool object_exists_namespace(ObjectAddress address,
 									const char *new_name);
 
 extern HeapTuple get_object_tuple(ObjectAddress address);
-
+extern AttrNumber get_object_name_attnum(const ObjectAddress *address);
 extern AttrNumber get_object_namespace_attnum(const ObjectAddress *address);
 extern Oid	get_object_namespace(const ObjectAddress *address);
 
diff --git a/src/include/commands/collationcmds.h b/src/include/commands/collationcmds.h
index d161d74..a2b7879 100644
--- a/src/include/commands/collationcmds.h
+++ b/src/include/commands/collationcmds.h
@@ -18,7 +18,6 @@
 #include "nodes/parsenodes.h"
 
 extern void DefineCollation(List *names, List *parameters);
-extern void RenameCollation(List *name, const char *newname);
 extern void AlterCollationOwner(List *name, Oid newOwnerId);
 extern void AlterCollationOwner_oid(Oid collationOid, Oid newOwnerId);
 
diff --git a/src/include/commands/conversioncmds.h b/src/include/commands/conversioncmds.h
index 6a8a02f..b592131 100644
--- a/src/include/commands/conversioncmds.h
+++ b/src/include/commands/conversioncmds.h
@@ -18,7 +18,6 @@
 #include "nodes/parsenodes.h"
 
 extern void CreateConversionCommand(CreateConversionStmt *parsetree);
-extern void RenameConversion(List *name, const char *newname);
 extern void AlterConversionOwner(List *name, Oid newOwnerId);
 extern void AlterConversionOwner_oid(Oid conversionOid, Oid newOwnerId);
 
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index b4c0c91..6e38ebf 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -64,7 +64,6 @@ extern void CreateFunction(CreateFunctionStmt *stmt, const char *queryString);
 extern void RemoveFunctionById(Oid funcOid);
 extern void SetFunctionReturnType(Oid funcOid, Oid newRetType);
 extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
-extern void RenameFunction(List *name, List *argtypes, const char *newname);
 extern void AlterFunctionOwner(List *name, List *argtypes, Oid newOwnerId);
 extern void AlterFunctionOwner_oid(Oid procOid, Oid newOwnerId);
 extern void AlterFunction(AlterFunctionStmt *stmt);
@@ -83,7 +82,6 @@ extern void AlterOperatorOwner_oid(Oid operOid, Oid newOwnerId);
 /* commands/aggregatecmds.c */
 extern void DefineAggregate(List *name, List *args, bool oldstyle,
 				List *parameters);
-extern void RenameAggregate(List *name, List *args, const char *newname);
 extern void AlterAggregateOwner(List *name, List *args, Oid newOwnerId);
 
 /* commands/opclasscmds.c */
@@ -94,8 +92,6 @@ extern void RemoveOpClassById(Oid opclassOid);
 extern void RemoveOpFamilyById(Oid opfamilyOid);
 extern void RemoveAmOpEntryById(Oid entryOid);
 extern void RemoveAmProcEntryById(Oid entryOid);
-extern void RenameOpClass(List *name, const char *access_method, const char *newname);
-extern void RenameOpFamily(List *name, const char *access_method, const char *newname);
 extern void AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId);
 extern void AlterOpClassOwner_oid(Oid opclassOid, Oid newOwnerId);
 extern void AlterOpFamilyOwner(List *name, const char *access_method, Oid newOwnerId);
@@ -106,21 +102,17 @@ extern Oid	get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
 
 /* commands/tsearchcmds.c */
 extern void DefineTSParser(List *names, List *parameters);
-extern void RenameTSParser(List *oldname, const char *newname);
 extern void RemoveTSParserById(Oid prsId);
 
 extern void DefineTSDictionary(List *names, List *parameters);
-extern void RenameTSDictionary(List *oldname, const char *newname);
 extern void RemoveTSDictionaryById(Oid dictId);
 extern void AlterTSDictionary(AlterTSDictionaryStmt *stmt);
 extern void AlterTSDictionaryOwner(List *name, Oid newOwnerId);
 
 extern void DefineTSTemplate(List *names, List *parameters);
-extern void RenameTSTemplate(List *oldname, const char *newname);
 extern void RemoveTSTemplateById(Oid tmplId);
 
 extern void DefineTSConfiguration(List *names, List *parameters);
-extern void RenameTSConfiguration(List *oldname, const char *newname);
 extern void RemoveTSConfigurationById(Oid cfgId);
 extern void AlterTSConfiguration(AlterTSConfigurationStmt *stmt);
 extern void AlterTSConfigurationOwner(List *name, Oid newOwnerId);
diff --git a/src/test/regress/expected/alter_rename.out b/src/test/regress/expected/alter_rename.out
index 7248b49..38ba86f 100644
--- a/src/test/regress/expected/alter_rename.out
+++ b/src/test/regress/expected/alter_rename.out
@@ -124,7 +124,7 @@ CREATE FUNCTION testfunc_b(int)
 	   RETURNS int LANGUAGE sql
 	   AS 'SELECT $1 + $1';
 ALTER FUNCTION testfunc_a(int) RENAME TO testfunc_b;	-- fail
-ERROR:  function testfunc_b(integer) already exists in schema "testschema_1"
+ERROR:  function testfunc_b already exists in schema "testschema_1"
 ALTER FUNCTION testfunc_b(int) SET SCHEMA testschema_2;	-- OK
 ALTER FUNCTION testfunc_a(int) RENAME TO testfunc_b;	-- OK
 ALTER FUNCTION testfunc_b(int) SET SCHEMA testschema_2;	-- fail
@@ -138,7 +138,7 @@ CREATE AGGREGATE testagg_b(
 	   initcond1 = '0'
 );
 ALTER AGGREGATE testagg_a(int) RENAME TO testagg_b;		-- fail
-ERROR:  function testagg_b(integer) already exists in schema "testschema_1"
+ERROR:  function testagg_b already exists in schema "testschema_1"
 ALTER AGGREGATE testagg_b(int) SET SCHEMA testschema_2;	-- OK
 ALTER AGGREGATE testagg_a(int) RENAME TO testagg_b;		-- OK
 ALTER AGGREGATE testagg_b(int) SET SCHEMA testschema_2;	-- fail
@@ -177,7 +177,7 @@ ERROR:  operator @#@(bigint,bigint) already exists in schema "testschema_2"
 CREATE OPERATOR FAMILY testopfamily_a USING btree;
 CREATE OPERATOR FAMILY testopfamily_b USING btree;
 ALTER OPERATOR FAMILY testopfamily_a USING btree RENAME TO testopfamily_b;	-- fail
-ERROR:  operator family "testopfamily_b" for access method "btree" already exists in schema "testschema_1"
+ERROR:  operator family "testopfamily_b" already exists in schema "testschema_1"
 ALTER OPERATOR FAMILY testopfamily_b USING btree SET SCHEMA testschema_2;	-- OK
 ALTER OPERATOR FAMILY testopfamily_a USING btree RENAME TO testopfamily_b;	-- OK
 ALTER OPERATOR FAMILY testopfamily_b USING btree SET SCHEMA testschema_2;	-- fail
@@ -187,7 +187,7 @@ CREATE OPERATOR CLASS testopclass_a
 CREATE OPERATOR CLASS testopclass_b
 	   FOR TYPE circle USING btree FAMILY testopfamily_b AS OPERATOR 1 =;
 ALTER OPERATOR CLASS testopclass_a USING btree RENAME TO testopclass_b;		-- fail
-ERROR:  operator class "testopclass_b" for access method "btree" already exists in schema "testschema_1"
+ERROR:  operator class "testopclass_b" already exists in schema "testschema_1"
 ALTER OPERATOR CLASS testopclass_b USING btree SET SCHEMA testschema_2;		-- OK
 ALTER OPERATOR CLASS testopclass_a USING btree RENAME TO testopclass_b;		-- OK
 ALTER OPERATOR CLASS testopclass_b USING btree SET SCHEMA testschema_2;		-- fail
@@ -206,7 +206,7 @@ CREATE TEXT SEARCH DICTIONARY testtsdict_b (
         AffFile=ispell_sample
 );
 ALTER TEXT SEARCH DICTIONARY testtsdict_a RENAME TO testtsdict_b;	-- fail
-ERROR:  text search dictionary "testtsdict_b" already exists
+ERROR:  text search dictionary "testtsdict_b" already exists in shema "testschema_1"
 ALTER TEXT SEARCH DICTIONARY testtsdict_b SET SCHEMA testschema_2;	-- OK
 ALTER TEXT SEARCH DICTIONARY testtsdict_a RENAME TO testtsdict_b;	-- OK
 ALTER TEXT SEARCH DICTIONARY testtsdict_b SET SCHEMA testschema_2;	-- fail
@@ -214,7 +214,7 @@ ERROR:  text search dictionary testtsdict_b already exists in schema "testschema
 CREATE TEXT SEARCH CONFIGURATION testtsconf_a (COPY=english);
 CREATE TEXT SEARCH CONFIGURATION testtsconf_b (COPY=english);
 ALTER TEXT SEARCH CONFIGURATION testtsconf_a RENAME TO testtsconf_b;	-- fail
-ERROR:  text search configuration "testtsconf_b" already exists
+ERROR:  text search configuration "testtsconf_b" already exists in schema "testschema_1"
 ALTER TEXT SEARCH CONFIGURATION testtsconf_b SET SCHEMA testschema_2;	-- OK
 ALTER TEXT SEARCH CONFIGURATION testtsconf_a RENAME TO testtsconf_b;	-- OK
 ALTER TEXT SEARCH CONFIGURATION testtsconf_b SET SCHEMA testschema_2;	-- fail
@@ -225,7 +225,7 @@ ERROR:  text search configuration testtsconf_b already exists in schema "testsch
 CREATE COLLATION testcollation_a FROM "C";
 CREATE COLLATION testcollation_b FROM "C";
 ALTER COLLATION testcollation_a RENAME TO testcollation_b;	-- fail
-ERROR:  collation "testcollation_b" for encoding "UTF8" already exists in schema "testschema_1"
+ERROR:  collation "testcollation_b" already exists in schema "testschema_1"
 ALTER COLLATION testcollation_b SET SCHEMA testschema_2;	-- OK
 ALTER COLLATION testcollation_a RENAME TO testcollation_b;	-- OK
 ALTER COLLATION testcollation_b SET SCHEMA testschema_2;	-- fail