aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2011-01-07 21:25:34 -0500
committerBruce Momjian <bruce@momjian.us>2011-01-07 21:26:13 -0500
commit2896c87ce4dc789722296f010eaefd5cbb86ece3 (patch)
tree5e98d2ca57edf90e7224dfe1ddf0764dc6a56bef /src
parent541fc3d4df66a5e51d172a78288069bd92dda0c8 (diff)
downloadpostgresql-2896c87ce4dc789722296f010eaefd5cbb86ece3.tar.gz
postgresql-2896c87ce4dc789722296f010eaefd5cbb86ece3.zip
Force pg_upgrade's to preserve pg_class.oid, not pg_class.relfilenode.
Toast tables have identical pg_class.oid and pg_class.relfilenode, but for clarity it is good to preserve the pg_class.oid. Update comments regarding what is preserved, and do some variable/function renaming for clarity.
Diffstat (limited to 'src')
-rw-r--r--src/backend/catalog/heap.c18
-rw-r--r--src/backend/catalog/index.c10
-rw-r--r--src/backend/catalog/toasting.c12
-rw-r--r--src/backend/commands/typecmds.c8
-rw-r--r--src/bin/pg_dump/pg_dump.c56
5 files changed, 48 insertions, 56 deletions
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index b36efcdba3c..5dfd8141eb6 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -74,8 +74,8 @@
/* 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,
@@ -987,22 +987,22 @@ heap_create_with_catalog(const char *relname,
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,
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index b45db4c9ec3..5790f872fe6 100644
--- a/src/backend/catalog/index.c
+++ b/src/backend/catalog/index.c
@@ -69,7 +69,7 @@
/* 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
@@ -641,13 +641,13 @@ index_create(Oid heapRelationId,
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
{
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index e4951226818..142beaeb6e6 100644
--- a/src/backend/catalog/toasting.c
+++ b/src/backend/catalog/toasting.c
@@ -32,9 +32,9 @@
#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);
@@ -156,7 +156,7 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
* 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;
/*
@@ -201,10 +201,10 @@ create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid, Datum reloptio
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,
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index bc66c3e6400..2ecb238b9eb 100644
--- a/src/backend/commands/typecmds.c
+++ b/src/backend/commands/typecmds.c
@@ -75,7 +75,7 @@ typedef struct
} 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);
@@ -1519,10 +1519,10 @@ AssignTypeArrayOid(void)
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
{
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 95218ee8317..40b414b3ecd 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -228,7 +228,7 @@ static void binary_upgrade_set_type_oids_by_type_oid(
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);
@@ -2243,7 +2243,7 @@ binary_upgrade_set_type_oids_by_type_oid(PQExpBuffer upgrade_buffer,
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);
}
@@ -2296,7 +2296,7 @@ binary_upgrade_set_type_oids_by_rel_oid(PQExpBuffer upgrade_buffer,
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;
@@ -2309,24 +2309,17 @@ binary_upgrade_set_type_oids_by_rel_oid(PQExpBuffer upgrade_buffer,
}
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;",
@@ -2346,44 +2339,43 @@ binary_upgrade_set_relfilenodes(PQExpBuffer upgrade_buffer, Oid pg_class_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");
@@ -7364,7 +7356,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
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 (",
@@ -11083,7 +11075,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
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);
@@ -11134,7 +11126,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
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 ?
@@ -11616,7 +11608,7 @@ dumpIndex(Archive *fout, IndxInfo *indxinfo)
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);
@@ -11699,7 +11691,7 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
}
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));
@@ -12112,7 +12104,7 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
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);
}