"LANGUAGE C STRICT;"));
        PQclear(executeQueryOrDie(conn,
                                  "CREATE OR REPLACE FUNCTION "
-              "        binary_upgrade.set_next_pg_type_array_oid(OID) "
+              "        binary_upgrade.set_next_array_pg_type_oid(OID) "
                                  "RETURNS VOID "
                                  "AS '$libdir/pg_upgrade_support' "
                                  "LANGUAGE C STRICT;"));
        PQclear(executeQueryOrDie(conn,
                                  "CREATE OR REPLACE FUNCTION "
-              "        binary_upgrade.set_next_pg_type_toast_oid(OID) "
+              "        binary_upgrade.set_next_toast_pg_type_oid(OID) "
                                  "RETURNS VOID "
                                  "AS '$libdir/pg_upgrade_support' "
                                  "LANGUAGE C STRICT;"));
        PQclear(executeQueryOrDie(conn,
                                  "CREATE OR REPLACE FUNCTION "
-               "       binary_upgrade.set_next_heap_relfilenode(OID) "
+               "       binary_upgrade.set_next_heap_pg_class_oid(OID) "
                                  "RETURNS VOID "
                                  "AS '$libdir/pg_upgrade_support' "
                                  "LANGUAGE C STRICT;"));
        PQclear(executeQueryOrDie(conn,
                                  "CREATE OR REPLACE FUNCTION "
-              "        binary_upgrade.set_next_toast_relfilenode(OID) "
+              "        binary_upgrade.set_next_index_pg_class_oid(OID) "
                                  "RETURNS VOID "
                                  "AS '$libdir/pg_upgrade_support' "
                                  "LANGUAGE C STRICT;"));
        PQclear(executeQueryOrDie(conn,
                                  "CREATE OR REPLACE FUNCTION "
-              "        binary_upgrade.set_next_index_relfilenode(OID) "
+              "        binary_upgrade.set_next_toast_pg_class_oid(OID) "
                                  "RETURNS VOID "
                                  "AS '$libdir/pg_upgrade_support' "
                                  "LANGUAGE C STRICT;"));
 
 
    /*
     * pg_largeobject contains user data that does not appear the pg_dumpall
-    * --schema-only output, so we have to upgrade that system table heap and
+    * --schema-only output, so we have to copy that system table heap and
     * index.  Ideally we could just get the relfilenode from template1 but
     * pg_largeobject_loid_pn_index's relfilenode can change if the table was
     * reindexed so we get the relfilenode for each database and upgrade it as
 
  */
 
 /*
- * To simplify the upgrade process, we force certain system items to be
- * consistent between old and new clusters:
+ * To simplify the upgrade process, we force certain system values to be
+ * identical between old and new clusters:
  *
- * We control all assignments of pg_class.relfilenode so we can keep the
- * same relfilenodes for old and new files.  The only exception is
- * pg_largeobject, pg_largeobject_metadata, and its indexes, which can
- * change due to a cluster, reindex, or vacuum full.  (We don't create
- * those so have no control over their oid/relfilenode values.)
+ * We control all assignments of pg_class.oid (and relfilenode) so toast
+ * oids are the same between old and new clusters.  This is important
+ * because toast oids are stored as toast pointers in user tables.
  *
- * While pg_class.oid and pg_class.relfilenode are intially the same, they
- * can diverge due to cluster, reindex, or vacuum full.  The new cluster
- * will again have matching pg_class.relfilenode and pg_class.oid values,
- * but based on the new relfilenode value, so the old/new oids might
- * differ.
+ * The only place where old/new relfilenode might not match is
+ * pg_largeobject, pg_largeobject_metadata, and its indexes,
+ * which can change their relfilenode values due to a cluster, reindex,
+ * or vacuum full.  (We don't create those so have no control over their
+ * new relfilenode values.)
  *
- * We control all assignments of pg_type.oid because these are stored
- * in composite types.
+ * FYI, while pg_class.oid and pg_class.relfilenode are intially the same
+ * in a cluster, but they can diverge due to cluster, reindex, or vacuum
+ * full.  The new cluster will again have matching pg_class.relfilenode
+ * and pg_class.oid values, but based on the old relfilenode value, so the
+ * old/new oids might differ.
+ *
+ * We control all assignments of pg_type.oid because these oid are stored
+ * in user composite type values.
+ *
+ * We control all assignments of pg_enum.oid because these oid are stored
+ * in user tables as enum values.
  */
 
 
 
 {
    char        nspname[NAMEDATALEN];   /* namespace name */
    char        relname[NAMEDATALEN];   /* relation name */
-   Oid         reloid;         /* relation oid              */
-   Oid         relfilenode;    /* relation relfile node     */
+   Oid         reloid;         /* relation oid */
+   Oid         relfilenode;    /* relation relfile node */
    Oid         toastrelid;     /* oid of the toast relation */
    char        tablespace[MAXPGPATH];  /* relations tablespace path */
 } RelInfo;
 
 #endif
 
 extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_oid;
-extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_array_oid;
-extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_toast_oid;
-extern PGDLLIMPORT Oid binary_upgrade_next_heap_relfilenode;
-extern PGDLLIMPORT Oid binary_upgrade_next_toast_relfilenode;
-extern PGDLLIMPORT Oid binary_upgrade_next_index_relfilenode;
+extern PGDLLIMPORT Oid binary_upgrade_next_array_pg_type_oid;
+extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_type_oid;
+
+extern PGDLLIMPORT Oid binary_upgrade_next_heap_pg_class_oid;
+extern PGDLLIMPORT Oid binary_upgrade_next_index_pg_class_oid;
+extern PGDLLIMPORT Oid binary_upgrade_next_toast_pg_class_oid;
+
 extern PGDLLIMPORT Oid binary_upgrade_next_pg_enum_oid;
 
 Datum      set_next_pg_type_oid(PG_FUNCTION_ARGS);
-Datum      set_next_pg_type_array_oid(PG_FUNCTION_ARGS);
-Datum      set_next_pg_type_toast_oid(PG_FUNCTION_ARGS);
-Datum      set_next_heap_relfilenode(PG_FUNCTION_ARGS);
-Datum      set_next_toast_relfilenode(PG_FUNCTION_ARGS);
-Datum      set_next_index_relfilenode(PG_FUNCTION_ARGS);
+Datum      set_next_array_pg_type_oid(PG_FUNCTION_ARGS);
+Datum      set_next_toast_pg_type_oid(PG_FUNCTION_ARGS);
+
+Datum      set_next_heap_pg_class_oid(PG_FUNCTION_ARGS);
+Datum      set_next_index_pg_class_oid(PG_FUNCTION_ARGS);
+Datum      set_next_toast_pg_class_oid(PG_FUNCTION_ARGS);
+
 Datum      set_next_pg_enum_oid(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(set_next_pg_type_oid);
-PG_FUNCTION_INFO_V1(set_next_pg_type_array_oid);
-PG_FUNCTION_INFO_V1(set_next_pg_type_toast_oid);
-PG_FUNCTION_INFO_V1(set_next_heap_relfilenode);
-PG_FUNCTION_INFO_V1(set_next_toast_relfilenode);
-PG_FUNCTION_INFO_V1(set_next_index_relfilenode);
+PG_FUNCTION_INFO_V1(set_next_array_pg_type_oid);
+PG_FUNCTION_INFO_V1(set_next_toast_pg_type_oid);
+
+PG_FUNCTION_INFO_V1(set_next_heap_pg_class_oid);
+PG_FUNCTION_INFO_V1(set_next_index_pg_class_oid);
+PG_FUNCTION_INFO_V1(set_next_toast_pg_class_oid);
+
 PG_FUNCTION_INFO_V1(set_next_pg_enum_oid);
 
+
 Datum
 set_next_pg_type_oid(PG_FUNCTION_ARGS)
 {
 }
 
 Datum
-set_next_pg_type_array_oid(PG_FUNCTION_ARGS)
+set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
 {
    Oid         typoid = PG_GETARG_OID(0);
 
-   binary_upgrade_next_pg_type_array_oid = typoid;
+   binary_upgrade_next_array_pg_type_oid = typoid;
 
    PG_RETURN_VOID();
 }
 
 Datum
-set_next_pg_type_toast_oid(PG_FUNCTION_ARGS)
+set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
 {
    Oid         typoid = PG_GETARG_OID(0);
 
-   binary_upgrade_next_pg_type_toast_oid = typoid;
+   binary_upgrade_next_toast_pg_type_oid = typoid;
 
    PG_RETURN_VOID();
 }
 
 Datum
-set_next_heap_relfilenode(PG_FUNCTION_ARGS)
+set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
 {
-   Oid         relfilenode = PG_GETARG_OID(0);
+   Oid         reloid = PG_GETARG_OID(0);
 
-   binary_upgrade_next_heap_relfilenode = relfilenode;
+   binary_upgrade_next_heap_pg_class_oid = reloid;
 
    PG_RETURN_VOID();
 }
 
 Datum
-set_next_toast_relfilenode(PG_FUNCTION_ARGS)
+set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
 {
-   Oid         relfilenode = PG_GETARG_OID(0);
+   Oid         reloid = PG_GETARG_OID(0);
 
-   binary_upgrade_next_toast_relfilenode = relfilenode;
+   binary_upgrade_next_index_pg_class_oid = reloid;
 
    PG_RETURN_VOID();
 }
 
 Datum
-set_next_index_relfilenode(PG_FUNCTION_ARGS)
+set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
 {
-   Oid         relfilenode = PG_GETARG_OID(0);
+   Oid         reloid = PG_GETARG_OID(0);
 
-   binary_upgrade_next_index_relfilenode = relfilenode;
+   binary_upgrade_next_toast_pg_class_oid = reloid;
 
    PG_RETURN_VOID();
 }
 
 
 
 /* Potentially set by contrib/pg_upgrade_support functions */
-Oid            binary_upgrade_next_heap_relfilenode = InvalidOid;
-Oid            binary_upgrade_next_toast_relfilenode = InvalidOid;
+Oid            binary_upgrade_next_heap_pg_class_oid = InvalidOid;
+Oid            binary_upgrade_next_toast_pg_class_oid = InvalidOid;
 
 static void AddNewRelationTuple(Relation pg_class_desc,
                    Relation new_rel_desc,
    if (!OidIsValid(relid))
    {
        /*
-        *  Use binary-upgrade override for pg_class.relfilenode/oid,
+        *  Use binary-upgrade override for pg_class.oid/relfilenode,
         *  if supplied.
         */
-       if (OidIsValid(binary_upgrade_next_heap_relfilenode) &&
+       if (OidIsValid(binary_upgrade_next_heap_pg_class_oid) &&
            (relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
             relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
             relkind == RELKIND_FOREIGN_TABLE))
        {
-           relid = binary_upgrade_next_heap_relfilenode;
-           binary_upgrade_next_heap_relfilenode = InvalidOid;
+           relid = binary_upgrade_next_heap_pg_class_oid;
+           binary_upgrade_next_heap_pg_class_oid = InvalidOid;
        }
-       else if (OidIsValid(binary_upgrade_next_toast_relfilenode) &&
+       else if (OidIsValid(binary_upgrade_next_toast_pg_class_oid) &&
                 relkind == RELKIND_TOASTVALUE)
        {
-           relid = binary_upgrade_next_toast_relfilenode;
-           binary_upgrade_next_toast_relfilenode = InvalidOid;
+           relid = binary_upgrade_next_toast_pg_class_oid;
+           binary_upgrade_next_toast_pg_class_oid = InvalidOid;
        }
        else
            relid = GetNewRelFileNode(reltablespace, pg_class_desc,
 
 
 
 /* Potentially set by contrib/pg_upgrade_support functions */
-Oid            binary_upgrade_next_index_relfilenode = InvalidOid;
+Oid            binary_upgrade_next_index_pg_class_oid = InvalidOid;
 
 /* state info for validate_index bulkdelete callback */
 typedef struct
    if (!OidIsValid(indexRelationId))
    {
        /*
-        *  Use binary-upgrade override for pg_class.relfilenode/oid,
+        *  Use binary-upgrade override for pg_class.oid/relfilenode,
         *  if supplied.
         */
-       if (OidIsValid(binary_upgrade_next_index_relfilenode))
+       if (OidIsValid(binary_upgrade_next_index_pg_class_oid))
        {
-           indexRelationId = binary_upgrade_next_index_relfilenode;
-           binary_upgrade_next_index_relfilenode = InvalidOid;
+           indexRelationId = binary_upgrade_next_index_pg_class_oid;
+           binary_upgrade_next_index_pg_class_oid = InvalidOid;
        }
        else
        {
 
 #include "utils/syscache.h"
 
 /* Potentially set by contrib/pg_upgrade_support functions */
-extern Oid binary_upgrade_next_toast_relfilenode;
+extern Oid binary_upgrade_next_toast_pg_class_oid;
 
-Oid            binary_upgrade_next_pg_type_toast_oid = InvalidOid;
+Oid            binary_upgrade_next_toast_pg_type_oid = InvalidOid;
 
 static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
                   Datum reloptions);
     * creation even if it seems not to need one.
     */
    if (!needs_toast_table(rel) &&
-       !OidIsValid(binary_upgrade_next_toast_relfilenode))
+       !OidIsValid(binary_upgrade_next_toast_pg_class_oid))
        return false;
 
    /*
        namespaceid = PG_TOAST_NAMESPACE;
 
    /* Use binary-upgrade override for pg_type.oid, if supplied. */
-   if (OidIsValid(binary_upgrade_next_pg_type_toast_oid))
+   if (OidIsValid(binary_upgrade_next_toast_pg_type_oid))
    {
-       toast_typid = binary_upgrade_next_pg_type_toast_oid;
-       binary_upgrade_next_pg_type_toast_oid = InvalidOid;
+       toast_typid = binary_upgrade_next_toast_pg_type_oid;
+       binary_upgrade_next_toast_pg_type_oid = InvalidOid;
    }
 
    toast_relid = heap_create_with_catalog(toast_relname,
 
 } RelToCheck;
 
 /* Potentially set by contrib/pg_upgrade_support functions */
-Oid            binary_upgrade_next_pg_type_array_oid = InvalidOid;
+Oid            binary_upgrade_next_array_pg_type_oid = InvalidOid;
 
 static Oid findTypeInputFunction(List *procname, Oid typeOid);
 static Oid findTypeOutputFunction(List *procname, Oid typeOid);
    Oid         type_array_oid;
 
    /* Use binary-upgrade override for pg_type.typarray, if supplied. */
-   if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
+   if (OidIsValid(binary_upgrade_next_array_pg_type_oid))
    {
-       type_array_oid = binary_upgrade_next_pg_type_array_oid;
-       binary_upgrade_next_pg_type_array_oid = InvalidOid;
+       type_array_oid = binary_upgrade_next_array_pg_type_oid;
+       binary_upgrade_next_array_pg_type_oid = InvalidOid;
    }
    else
    {
 
                                PQExpBuffer upgrade_buffer, Oid pg_type_oid);
 static bool binary_upgrade_set_type_oids_by_rel_oid(
                                 PQExpBuffer upgrade_buffer, Oid pg_rel_oid);
-static void binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer,
+static void binary_upgrade_set_pg_class_oids(PQExpBuffer upgrade_buffer,
                                Oid pg_class_oid, bool is_index);
 static const char *getAttrName(int attrnum, TableInfo *tblInfo);
 static const char *fmtCopyColumnList(const TableInfo *ti);
        appendPQExpBuffer(upgrade_buffer,
               "\n-- For binary upgrade, must preserve pg_type array oid\n");
        appendPQExpBuffer(upgrade_buffer,
-                         "SELECT binary_upgrade.set_next_pg_type_array_oid('%u'::pg_catalog.oid);\n\n",
+                         "SELECT binary_upgrade.set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
                          pg_type_array_oid);
    }
 
 
        appendPQExpBuffer(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
        appendPQExpBuffer(upgrade_buffer,
-                         "SELECT binary_upgrade.set_next_pg_type_toast_oid('%u'::pg_catalog.oid);\n\n",
+                         "SELECT binary_upgrade.set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
                          pg_type_toast_oid);
 
        toast_set = true;
 }
 
 static void
-binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
+binary_upgrade_set_pg_class_oids(PQExpBuffer upgrade_buffer, Oid pg_class_oid,
                                bool is_index)
 {
    PQExpBuffer upgrade_query = createPQExpBuffer();
    int         ntups;
    PGresult   *upgrade_res;
-   Oid         pg_class_relfilenode;
    Oid         pg_class_reltoastrelid;
    Oid         pg_class_reltoastidxid;
 
-   /*
-    * Note: we don't need to use pg_relation_filenode() here because this
-    * function is not intended to be used against system catalogs. Otherwise
-    * we'd have to worry about which versions pg_relation_filenode is
-    * available in.
-    */
    appendPQExpBuffer(upgrade_query,
-                   "SELECT c.relfilenode, c.reltoastrelid, t.reltoastidxid "
+                   "SELECT c.reltoastrelid, t.reltoastidxid "
                      "FROM pg_catalog.pg_class c LEFT JOIN "
                      "pg_catalog.pg_class t ON (c.reltoastrelid = t.oid) "
                      "WHERE c.oid = '%u'::pg_catalog.oid;",
        exit_nicely();
    }
 
-   pg_class_relfilenode = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "relfilenode")));
    pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
    pg_class_reltoastidxid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastidxid")));
 
    appendPQExpBuffer(upgrade_buffer,
-                   "\n-- For binary upgrade, must preserve relfilenodes\n");
+                   "\n-- For binary upgrade, must preserve pg_class oids\n");
 
    if (!is_index)
    {
        appendPQExpBuffer(upgrade_buffer,
-                         "SELECT binary_upgrade.set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
-                         pg_class_relfilenode);
+                         "SELECT binary_upgrade.set_next_heap_pg_class_oid('%u'::pg_catalog.oid);\n",
+                         pg_class_oid);
        /* only tables have toast tables, not indexes */
        if (OidIsValid(pg_class_reltoastrelid))
        {
            /*
-            * One complexity is that the table definition might not require the
-            * creation of a TOAST table, and the TOAST table might have been
-            * created long after table creation, when the table was loaded with
-            * wide data.  By setting the TOAST relfilenode we force creation of
-            * the TOAST heap and TOAST index by the backend so we can cleanly
-            * migrate the files during binary migration.
+            * One complexity is that the table definition might not require
+            * the creation of a TOAST table, and the TOAST table might have
+            * been created long after table creation, when the table was
+            * loaded with wide data.  By setting the TOAST oid we force
+            * creation of the TOAST heap and TOAST index by the backend
+            * so we can cleanly copy the files during binary upgrade.
             */
    
            appendPQExpBuffer(upgrade_buffer,
-                             "SELECT binary_upgrade.set_next_toast_relfilenode('%u'::pg_catalog.oid);\n",
+                             "SELECT binary_upgrade.set_next_toast_pg_class_oid('%u'::pg_catalog.oid);\n",
                              pg_class_reltoastrelid);
    
            /* every toast table has an index */
            appendPQExpBuffer(upgrade_buffer,
-                             "SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
+                             "SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
                              pg_class_reltoastidxid);
        }
    }
    else
        appendPQExpBuffer(upgrade_buffer,
-                         "SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
-                         pg_class_relfilenode);
+                         "SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
+                         pg_class_oid);
 
    appendPQExpBuffer(upgrade_buffer, "\n");
 
        Oid         typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
 
        binary_upgrade_set_type_oids_by_type_oid(q, tyinfo->dobj.catId.oid);
-       binary_upgrade_set_relfilenodes(q, typrelid, false);
+       binary_upgrade_set_pg_class_oids(q, typrelid, false);
    }
 
    appendPQExpBuffer(q, "CREATE TYPE %s AS (",
                          fmtId(tbinfo->dobj.name));
 
        if (binary_upgrade)
-           binary_upgrade_set_relfilenodes(q, tbinfo->dobj.catId.oid, false);
+           binary_upgrade_set_pg_class_oids(q, tbinfo->dobj.catId.oid, false);
 
        appendPQExpBuffer(q, "CREATE VIEW %s AS\n    %s\n",
                          fmtId(tbinfo->dobj.name), viewdef);
                          fmtId(tbinfo->dobj.name));
 
        if (binary_upgrade)
-           binary_upgrade_set_relfilenodes(q, tbinfo->dobj.catId.oid, false);
+           binary_upgrade_set_pg_class_oids(q, tbinfo->dobj.catId.oid, false);
 
        appendPQExpBuffer(q, "CREATE %s%s %s",
                          tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
    if (indxinfo->indexconstraint == 0)
    {
        if (binary_upgrade)
-           binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
+           binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
 
        /* Plain secondary index */
        appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
        }
 
        if (binary_upgrade && !coninfo->condef)
-           binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
+           binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
 
        appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
                          fmtId(tbinfo->dobj.name));
 
        if (binary_upgrade)
        {
-           binary_upgrade_set_relfilenodes(query, tbinfo->dobj.catId.oid, false);
+           binary_upgrade_set_pg_class_oids(query, tbinfo->dobj.catId.oid, false);
            binary_upgrade_set_type_oids_by_rel_oid(query, tbinfo->dobj.catId.oid);
        }