The attached two patches clarify pg_upgrades behavior. Specifically,
the first patch updates the C comments regarding pg_upgrade_support.
The second patch clarifies that pg_class.oid really needs preserving,
not pg_class.relfilenode. We used to use create relfilenode files to
preserve pg_class.oids, but no longer in PG >= 9.0. Also add comments
about what is being preserved, and why. This should help future
improvements.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
commit 46d28820b6d213bf26b24ecd289a1c466ecf1956
Author: Bruce Momjian <bruce@momjian.us>
Date: Thu Jan 6 22:44:57 2011 -0500
Improve C comments about backend variables set by pg_upgrade_support
functions.
diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c
index 64fb8f8..820445c 100644
*** /tmp/7SYOed_pg_upgrade.c Fri Jan 7 19:33:04 2011
--- /tmp/Zof2xb_pg_upgrade.c Fri Jan 7 19:33:04 2011
***************
*** 7,12 ****
--- 7,34 ----
* contrib/pg_upgrade/pg_upgrade.c
*/
+ /*
+ * To simplify the upgrade process, we force certain system items to be
+ * consistent 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.)
+ *
+ * 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.
+ *
+ * We control all assignments of pg_type.oid because these are stored
+ * in composite types.
+ */
+
+
+
#include "pg_upgrade.h"
#ifdef HAVE_LANGINFO_H
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 4c55db7..b36efcd 100644
*** /tmp/3oYz9b_heap.c Fri Jan 7 19:33:04 2011
--- /tmp/5f34Wc_heap.c Fri Jan 7 19:33:04 2011
***************
*** 73,79 ****
#include "utils/tqual.h"
! /* Kluge for upgrade-in-place support */
Oid binary_upgrade_next_heap_relfilenode = InvalidOid;
Oid binary_upgrade_next_toast_relfilenode = InvalidOid;
--- 73,79 ----
#include "utils/tqual.h"
! /* Potentially set by contrib/pg_upgrade_support functions */
Oid binary_upgrade_next_heap_relfilenode = InvalidOid;
Oid binary_upgrade_next_toast_relfilenode = InvalidOid;
*************** heap_create_with_catalog(const char *rel
*** 986,992 ****
*/
if (!OidIsValid(relid))
{
! /* Use binary-upgrade overrides if applicable */
if (OidIsValid(binary_upgrade_next_heap_relfilenode) &&
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
--- 986,995 ----
*/
if (!OidIsValid(relid))
{
! /*
! * Use binary-upgrade override for pg_class.relfilenode/oid,
! * if supplied.
! */
if (OidIsValid(binary_upgrade_next_heap_relfilenode) &&
(relkind == RELKIND_RELATION || relkind == RELKIND_SEQUENCE ||
relkind == RELKIND_VIEW || relkind == RELKIND_COMPOSITE_TYPE ||
diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c
index 4dd89e1..b45db4c 100644
*** /tmp/TFFoHe_index.c Fri Jan 7 19:33:04 2011
--- /tmp/LBJijc_index.c Fri Jan 7 19:33:04 2011
***************
*** 68,74 ****
#include "utils/tqual.h"
! /* Kluge for upgrade-in-place support */
Oid binary_upgrade_next_index_relfilenode = InvalidOid;
/* state info for validate_index bulkdelete callback */
--- 68,74 ----
#include "utils/tqual.h"
! /* Potentially set by contrib/pg_upgrade_support functions */
Oid binary_upgrade_next_index_relfilenode = InvalidOid;
/* state info for validate_index bulkdelete callback */
*************** index_create(Oid heapRelationId,
*** 640,646 ****
*/
if (!OidIsValid(indexRelationId))
{
! /* Use binary-upgrade override if applicable */
if (OidIsValid(binary_upgrade_next_index_relfilenode))
{
indexRelationId = binary_upgrade_next_index_relfilenode;
--- 640,649 ----
*/
if (!OidIsValid(indexRelationId))
{
! /*
! * Use binary-upgrade override for pg_class.relfilenode/oid,
! * if supplied.
! */
if (OidIsValid(binary_upgrade_next_index_relfilenode))
{
indexRelationId = binary_upgrade_next_index_relfilenode;
diff --git a/src/backend/catalog/pg_enum.c b/src/backend/catalog/pg_enum.c
index 0cc0a0c..e87a931 100644
*** /tmp/4xILMc_pg_enum.c Fri Jan 7 19:33:05 2011
--- /tmp/CRb4od_pg_enum.c Fri Jan 7 19:33:05 2011
***************
*** 28,33 ****
--- 28,34 ----
#include "utils/tqual.h"
+ /* Potentially set by contrib/pg_upgrade_support functions */
Oid binary_upgrade_next_pg_enum_oid = InvalidOid;
static void RenumberEnumType(Relation pg_enum, HeapTuple *existing, int nelems);
*************** restart:
*** 313,321 ****
if (OidIsValid(binary_upgrade_next_pg_enum_oid))
{
/*
! * In binary upgrades, just add the new label with the predetermined
! * Oid. It's pg_upgrade's responsibility that the Oid meets
! * requirements.
*/
if (neighbor != NULL)
ereport(ERROR,
--- 314,322 ----
if (OidIsValid(binary_upgrade_next_pg_enum_oid))
{
/*
! * Use binary-upgrade override for pg_enum.oid, if supplied.
! * During binary upgrade, all pg_enum.oid's are set this way
! * so they are guaranteed to be consistent.
*/
if (neighbor != NULL)
ereport(ERROR,
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index 69ff191..9c249a7 100644
*** /tmp/6INpDb_pg_type.c Fri Jan 7 19:33:05 2011
--- /tmp/AUZEJa_pg_type.c Fri Jan 7 19:33:05 2011
***************
*** 33,38 ****
--- 33,39 ----
#include "utils/rel.h"
#include "utils/syscache.h"
+ /* Potentially set by contrib/pg_upgrade_support functions */
Oid binary_upgrade_next_pg_type_oid = InvalidOid;
/* ----------------------------------------------------------------
*************** TypeShellMake(const char *typeName, Oid
*** 121,126 ****
--- 122,128 ----
*/
tup = heap_form_tuple(tupDesc, values, nulls);
+ /* Use binary-upgrade override for pg_type.oid, if supplied. */
if (OidIsValid(binary_upgrade_next_pg_type_oid))
{
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
*************** TypeCreate(Oid newTypeOid,
*** 422,427 ****
--- 424,430 ----
/* Force the OID if requested by caller */
if (OidIsValid(newTypeOid))
HeapTupleSetOid(tup, newTypeOid);
+ /* Use binary-upgrade override for pg_type.oid, if supplied. */
else if (OidIsValid(binary_upgrade_next_pg_type_oid))
{
HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid);
diff --git a/src/backend/catalog/toasting.c b/src/backend/catalog/toasting.c
index 59838e3..e495122 100644
*** /tmp/I4Kdwc_toasting.c Fri Jan 7 19:33:05 2011
--- /tmp/CdvKwb_toasting.c Fri Jan 7 19:33:05 2011
***************
*** 31,37 ****
#include "utils/builtins.h"
#include "utils/syscache.h"
! /* Kluges for upgrade-in-place support */
extern Oid binary_upgrade_next_toast_relfilenode;
Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
--- 31,37 ----
#include "utils/builtins.h"
#include "utils/syscache.h"
! /* Potentially set by contrib/pg_upgrade_support functions */
extern Oid binary_upgrade_next_toast_relfilenode;
Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
*************** create_toast_table(Relation rel, Oid toa
*** 200,205 ****
--- 200,206 ----
else
namespaceid = PG_TOAST_NAMESPACE;
+ /* Use binary-upgrade override for pg_type.oid, if supplied. */
if (OidIsValid(binary_upgrade_next_pg_type_toast_oid))
{
toast_typid = binary_upgrade_next_pg_type_toast_oid;
diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c
index 113bede..bc66c3e 100644
*** /tmp/mZ7Pme_typecmds.c Fri Jan 7 19:33:05 2011
--- /tmp/KrUiBb_typecmds.c Fri Jan 7 19:33:05 2011
*************** typedef struct
*** 74,79 ****
--- 74,80 ----
/* atts[] is of allocated length RelationGetNumberOfAttributes(rel) */
} RelToCheck;
+ /* Potentially set by contrib/pg_upgrade_support functions */
Oid binary_upgrade_next_pg_type_array_oid = InvalidOid;
static Oid findTypeInputFunction(List *procname, Oid typeOid);
*************** AssignTypeArrayOid(void)
*** 1517,1523 ****
{
Oid type_array_oid;
! /* Pre-assign the type's array OID for use in pg_type.typarray */
if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
{
type_array_oid = binary_upgrade_next_pg_type_array_oid;
--- 1518,1524 ----
{
Oid type_array_oid;
! /* Use binary-upgrade override for pg_type.typarray, if supplied. */
if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
{
type_array_oid = binary_upgrade_next_pg_type_array_oid;
diff --git a/contrib/pg_upgrade/function.c b/contrib/pg_upgrade/function.c
index 2ab8e4f..9c8c586 100644
*** /tmp/pgdiff.29009/TQ9Hcc_function.c Fri Jan 7 21:18:32 2011
--- contrib/pg_upgrade/function.c Fri Jan 7 19:42:58 2011
*************** install_support_functions(void)
*** 49,79 ****
"LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION "
! " binary_upgrade.set_next_pg_type_array_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) "
"RETURNS VOID "
"AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION "
! " binary_upgrade.set_next_heap_relfilenode(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) "
"RETURNS VOID "
"AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION "
! " binary_upgrade.set_next_index_relfilenode(OID) "
"RETURNS VOID "
"AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;"));
--- 49,79 ----
"LANGUAGE C STRICT;"));
PQclear(executeQueryOrDie(conn,
"CREATE OR REPLACE FUNCTION "
! " 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_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_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_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_pg_class_oid(OID) "
"RETURNS VOID "
"AS '$libdir/pg_upgrade_support' "
"LANGUAGE C STRICT;"));
diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c
index 578bdb9..dc66e38 100644
*** /tmp/pgdiff.29009/nw16Wc_info.c Fri Jan 7 21:18:32 2011
--- contrib/pg_upgrade/info.c Fri Jan 7 21:06:24 2011
*************** get_rel_infos(ClusterInfo *cluster, DbIn
*** 266,272 ****
/*
* 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
* 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
--- 266,272 ----
/*
* pg_largeobject contains user data that does not appear the pg_dumpall
! * --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
diff --git a/contrib/pg_upgrade/pg_upgrade.c b/contrib/pg_upgrade/pg_upgrade.c
index 820445c..3de47fc 100644
*** /tmp/pgdiff.29009/dTf5xe_pg_upgrade.c Fri Jan 7 21:18:32 2011
--- contrib/pg_upgrade/pg_upgrade.c Fri Jan 7 19:35:51 2011
***************
*** 8,30 ****
*/
/*
! * To simplify the upgrade process, we force certain system items to be
! * consistent 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.)
*
! * 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.
*
! * We control all assignments of pg_type.oid because these are stored
! * in composite types.
*/
--- 8,37 ----
*/
/*
! * 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.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.
*
! * 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.)
*
! * 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.
*/
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
index d863155..7f44a9d 100644
*** /tmp/pgdiff.29009/1Epide_pg_upgrade.h Fri Jan 7 21:18:32 2011
--- contrib/pg_upgrade/pg_upgrade.h Fri Jan 7 19:13:07 2011
*************** typedef struct
*** 67,74 ****
{
char nspname[NAMEDATALEN]; /* namespace name */
char relname[NAMEDATALEN]; /* relation name */
! Oid reloid; /* relation oid */
! Oid relfilenode; /* relation relfile node */
Oid toastrelid; /* oid of the toast relation */
char tablespace[MAXPGPATH]; /* relations tablespace path */
} RelInfo;
--- 67,74 ----
{
char nspname[NAMEDATALEN]; /* namespace name */
char relname[NAMEDATALEN]; /* relation name */
! Oid reloid; /* relation oid */
! Oid relfilenode; /* relation relfile node */
Oid toastrelid; /* oid of the toast relation */
char tablespace[MAXPGPATH]; /* relations tablespace path */
} RelInfo;
diff --git a/contrib/pg_upgrade_support/pg_upgrade_support.c b/contrib/pg_upgrade_support/pg_upgrade_support.c
index e55e139..da8bd58 100644
*** /tmp/pgdiff.29009/d19J5b_pg_upgrade_support.c Fri Jan 7 21:18:32 2011
--- contrib/pg_upgrade_support/pg_upgrade_support.c Fri Jan 7 19:39:49 2011
*************** PG_MODULE_MAGIC;
*** 21,49 ****
#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_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_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_pg_enum_oid);
Datum
set_next_pg_type_oid(PG_FUNCTION_ARGS)
{
--- 21,56 ----
#endif
extern PGDLLIMPORT Oid binary_upgrade_next_pg_type_oid;
! 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_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_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)
{
*************** set_next_pg_type_oid(PG_FUNCTION_ARGS)
*** 55,105 ****
}
Datum
! set_next_pg_type_array_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
! binary_upgrade_next_pg_type_array_oid = typoid;
PG_RETURN_VOID();
}
Datum
! set_next_pg_type_toast_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
! binary_upgrade_next_pg_type_toast_oid = typoid;
PG_RETURN_VOID();
}
Datum
! set_next_heap_relfilenode(PG_FUNCTION_ARGS)
{
! Oid relfilenode = PG_GETARG_OID(0);
! binary_upgrade_next_heap_relfilenode = relfilenode;
PG_RETURN_VOID();
}
Datum
! set_next_toast_relfilenode(PG_FUNCTION_ARGS)
{
! Oid relfilenode = PG_GETARG_OID(0);
! binary_upgrade_next_toast_relfilenode = relfilenode;
PG_RETURN_VOID();
}
Datum
! set_next_index_relfilenode(PG_FUNCTION_ARGS)
{
! Oid relfilenode = PG_GETARG_OID(0);
! binary_upgrade_next_index_relfilenode = relfilenode;
PG_RETURN_VOID();
}
--- 62,112 ----
}
Datum
! set_next_array_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
! binary_upgrade_next_array_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
! set_next_toast_pg_type_oid(PG_FUNCTION_ARGS)
{
Oid typoid = PG_GETARG_OID(0);
! binary_upgrade_next_toast_pg_type_oid = typoid;
PG_RETURN_VOID();
}
Datum
! set_next_heap_pg_class_oid(PG_FUNCTION_ARGS)
{
! Oid reloid = PG_GETARG_OID(0);
! binary_upgrade_next_heap_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
! set_next_index_pg_class_oid(PG_FUNCTION_ARGS)
{
! Oid reloid = PG_GETARG_OID(0);
! binary_upgrade_next_index_pg_class_oid = reloid;
PG_RETURN_VOID();
}
Datum
! set_next_toast_pg_class_oid(PG_FUNCTION_ARGS)
{
! Oid reloid = PG_GETARG_OID(0);
! binary_upgrade_next_toast_pg_class_oid = reloid;
PG_RETURN_VOID();
}
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index b36efcd..5dfd814 100644
*** /tmp/pgdiff.29009/PWzZBb_heap.c Fri Jan 7 21:18:32 2011
--- src/backend/catalog/heap.c Fri Jan 7 20:54:55 2011
***************
*** 74,81 ****
/* Potentially set by contrib/pg_upgrade_support functions */
! Oid binary_upgrade_next_heap_relfilenode = InvalidOid;
! Oid binary_upgrade_next_toast_relfilenode = InvalidOid;
static void AddNewRelationTuple(Relation pg_class_desc,
Relation new_rel_desc,
--- 74,81 ----
/* Potentially set by contrib/pg_upgrade_support functions */
! 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,
*************** heap_create_with_catalog(const char *rel
*** 987,1008 ****
if (!OidIsValid(relid))
{
/*
! * Use binary-upgrade override for pg_class.relfilenode/oid,
* if supplied.
*/
! if (OidIsValid(binary_upgrade_next_heap_relfilenode) &&
(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;
}
! else if (OidIsValid(binary_upgrade_next_toast_relfilenode) &&
relkind == RELKIND_TOASTVALUE)
{
! relid = binary_upgrade_next_toast_relfilenode;
! binary_upgrade_next_toast_relfilenode = InvalidOid;
}
else
relid = GetNewRelFileNode(reltablespace, pg_class_desc,
--- 987,1008 ----
if (!OidIsValid(relid))
{
/*
! * Use binary-upgrade override for pg_class.oid/relfilenode,
* if supplied.
*/
! 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_pg_class_oid;
! binary_upgrade_next_heap_pg_class_oid = InvalidOid;
}
! else if (OidIsValid(binary_upgrade_next_toast_pg_class_oid) &&
relkind == RELKIND_TOASTVALUE)
{
! 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 b45db4c..5790f87 100644
*** /tmp/pgdiff.29009/TSqk8d_index.c Fri Jan 7 21:18:32 2011
--- src/backend/catalog/index.c Fri Jan 7 20:55:33 2011
***************
*** 69,75 ****
/* Potentially set by contrib/pg_upgrade_support functions */
! Oid binary_upgrade_next_index_relfilenode = InvalidOid;
/* state info for validate_index bulkdelete callback */
typedef struct
--- 69,75 ----
/* Potentially set by contrib/pg_upgrade_support functions */
! Oid binary_upgrade_next_index_pg_class_oid = InvalidOid;
/* state info for validate_index bulkdelete callback */
typedef struct
*************** index_create(Oid heapRelationId,
*** 641,653 ****
if (!OidIsValid(indexRelationId))
{
/*
! * Use binary-upgrade override for pg_class.relfilenode/oid,
* if supplied.
*/
! if (OidIsValid(binary_upgrade_next_index_relfilenode))
{
! indexRelationId = binary_upgrade_next_index_relfilenode;
! binary_upgrade_next_index_relfilenode = InvalidOid;
}
else
{
--- 641,653 ----
if (!OidIsValid(indexRelationId))
{
/*
! * Use binary-upgrade override for pg_class.oid/relfilenode,
* if supplied.
*/
! if (OidIsValid(binary_upgrade_next_index_pg_class_oid))
{
! 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 e495122..142beae 100644
*** /tmp/pgdiff.29009/TUtB8d_toasting.c Fri Jan 7 21:18:32 2011
--- src/backend/catalog/toasting.c Fri Jan 7 20:30:33 2011
***************
*** 32,40 ****
#include "utils/syscache.h"
/* Potentially set by contrib/pg_upgrade_support functions */
! extern Oid binary_upgrade_next_toast_relfilenode;
! Oid binary_upgrade_next_pg_type_toast_oid = InvalidOid;
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
Datum reloptions);
--- 32,40 ----
#include "utils/syscache.h"
/* Potentially set by contrib/pg_upgrade_support functions */
! extern Oid binary_upgrade_next_toast_pg_class_oid;
! Oid binary_upgrade_next_toast_pg_type_oid = InvalidOid;
static bool create_toast_table(Relation rel, Oid toastOid, Oid toastIndexOid,
Datum reloptions);
*************** create_toast_table(Relation rel, Oid toa
*** 156,162 ****
* creation even if it seems not to need one.
*/
if (!needs_toast_table(rel) &&
! !OidIsValid(binary_upgrade_next_toast_relfilenode))
return false;
/*
--- 156,162 ----
* creation even if it seems not to need one.
*/
if (!needs_toast_table(rel) &&
! !OidIsValid(binary_upgrade_next_toast_pg_class_oid))
return false;
/*
*************** create_toast_table(Relation rel, Oid toa
*** 201,210 ****
namespaceid = PG_TOAST_NAMESPACE;
/* Use binary-upgrade override for pg_type.oid, if supplied. */
! if (OidIsValid(binary_upgrade_next_pg_type_toast_oid))
{
! toast_typid = binary_upgrade_next_pg_type_toast_oid;
! binary_upgrade_next_pg_type_toast_oid = InvalidOid;
}
toast_relid = heap_create_with_catalog(toast_relname,
--- 201,210 ----
namespaceid = PG_TOAST_NAMESPACE;
/* Use binary-upgrade override for pg_type.oid, if supplied. */
! if (OidIsValid(binary_upgrade_next_toast_pg_type_oid))
{
! 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 bc66c3e..2ecb238 100644
*** /tmp/pgdiff.29009/LeePua_typecmds.c Fri Jan 7 21:18:32 2011
--- src/backend/commands/typecmds.c Fri Jan 7 18:21:38 2011
*************** typedef struct
*** 75,81 ****
} RelToCheck;
/* Potentially set by contrib/pg_upgrade_support functions */
! Oid binary_upgrade_next_pg_type_array_oid = InvalidOid;
static Oid findTypeInputFunction(List *procname, Oid typeOid);
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
--- 75,81 ----
} RelToCheck;
/* Potentially set by contrib/pg_upgrade_support functions */
! Oid binary_upgrade_next_array_pg_type_oid = InvalidOid;
static Oid findTypeInputFunction(List *procname, Oid typeOid);
static Oid findTypeOutputFunction(List *procname, Oid typeOid);
*************** AssignTypeArrayOid(void)
*** 1519,1528 ****
Oid type_array_oid;
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
! if (OidIsValid(binary_upgrade_next_pg_type_array_oid))
{
! type_array_oid = binary_upgrade_next_pg_type_array_oid;
! binary_upgrade_next_pg_type_array_oid = InvalidOid;
}
else
{
--- 1519,1528 ----
Oid type_array_oid;
/* Use binary-upgrade override for pg_type.typarray, if supplied. */
! if (OidIsValid(binary_upgrade_next_array_pg_type_oid))
{
! 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 95218ee..40b414b 100644
*** /tmp/pgdiff.29009/LqKWze_pg_dump.c Fri Jan 7 21:18:32 2011
--- src/bin/pg_dump/pg_dump.c Fri Jan 7 20:43:49 2011
*************** static void binary_upgrade_set_type_oids
*** 228,234 ****
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,
Oid pg_class_oid, bool is_index);
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
static const char *fmtCopyColumnList(const TableInfo *ti);
--- 228,234 ----
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_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);
*************** binary_upgrade_set_type_oids_by_type_oid
*** 2243,2249 ****
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",
pg_type_array_oid);
}
--- 2243,2249 ----
appendPQExpBuffer(upgrade_buffer,
"\n-- For binary upgrade, must preserve pg_type array oid\n");
appendPQExpBuffer(upgrade_buffer,
! "SELECT binary_upgrade.set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
pg_type_array_oid);
}
*************** binary_upgrade_set_type_oids_by_rel_oid(
*** 2296,2302 ****
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",
pg_type_toast_oid);
toast_set = true;
--- 2296,2302 ----
appendPQExpBuffer(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
appendPQExpBuffer(upgrade_buffer,
! "SELECT binary_upgrade.set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
pg_type_toast_oid);
toast_set = true;
*************** binary_upgrade_set_type_oids_by_rel_oid(
*** 2309,2332 ****
}
static void
! binary_upgrade_set_relfilenodes(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 "
"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;",
--- 2309,2325 ----
}
static void
! 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_reltoastrelid;
Oid pg_class_reltoastidxid;
appendPQExpBuffer(upgrade_query,
! "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;",
*************** binary_upgrade_set_relfilenodes(PQExpBuf
*** 2346,2389 ****
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");
if (!is_index)
{
appendPQExpBuffer(upgrade_buffer,
! "SELECT binary_upgrade.set_next_heap_relfilenode('%u'::pg_catalog.oid);\n",
! pg_class_relfilenode);
/* 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.
*/
appendPQExpBuffer(upgrade_buffer,
! "SELECT binary_upgrade.set_next_toast_relfilenode('%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",
pg_class_reltoastidxid);
}
}
else
appendPQExpBuffer(upgrade_buffer,
! "SELECT binary_upgrade.set_next_index_relfilenode('%u'::pg_catalog.oid);\n",
! pg_class_relfilenode);
appendPQExpBuffer(upgrade_buffer, "\n");
--- 2339,2381 ----
exit_nicely();
}
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 pg_class oids\n");
if (!is_index)
{
appendPQExpBuffer(upgrade_buffer,
! "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 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_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_pg_class_oid('%u'::pg_catalog.oid);\n",
pg_class_reltoastidxid);
}
}
else
appendPQExpBuffer(upgrade_buffer,
! "SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
! pg_class_oid);
appendPQExpBuffer(upgrade_buffer, "\n");
*************** dumpCompositeType(Archive *fout, TypeInf
*** 7364,7370 ****
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);
}
appendPQExpBuffer(q, "CREATE TYPE %s AS (",
--- 7356,7362 ----
Oid typrelid = atooid(PQgetvalue(res, 0, i_typrelid));
binary_upgrade_set_type_oids_by_type_oid(q, tyinfo->dobj.catId.oid);
! binary_upgrade_set_pg_class_oids(q, typrelid, false);
}
appendPQExpBuffer(q, "CREATE TYPE %s AS (",
*************** dumpTableSchema(Archive *fout, TableInfo
*** 11083,11089 ****
fmtId(tbinfo->dobj.name));
if (binary_upgrade)
! binary_upgrade_set_relfilenodes(q, tbinfo->dobj.catId.oid, false);
appendPQExpBuffer(q, "CREATE VIEW %s AS\n %s\n",
fmtId(tbinfo->dobj.name), viewdef);
--- 11075,11081 ----
fmtId(tbinfo->dobj.name));
if (binary_upgrade)
! 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);
*************** dumpTableSchema(Archive *fout, TableInfo
*** 11134,11140 ****
fmtId(tbinfo->dobj.name));
if (binary_upgrade)
! binary_upgrade_set_relfilenodes(q, tbinfo->dobj.catId.oid, false);
appendPQExpBuffer(q, "CREATE %s%s %s",
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
--- 11126,11132 ----
fmtId(tbinfo->dobj.name));
if (binary_upgrade)
! binary_upgrade_set_pg_class_oids(q, tbinfo->dobj.catId.oid, false);
appendPQExpBuffer(q, "CREATE %s%s %s",
tbinfo->relpersistence == RELPERSISTENCE_UNLOGGED ?
*************** dumpIndex(Archive *fout, IndxInfo *indxi
*** 11616,11622 ****
if (indxinfo->indexconstraint == 0)
{
if (binary_upgrade)
! binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
/* Plain secondary index */
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
--- 11608,11614 ----
if (indxinfo->indexconstraint == 0)
{
if (binary_upgrade)
! binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
/* Plain secondary index */
appendPQExpBuffer(q, "%s;\n", indxinfo->indexdef);
*************** dumpConstraint(Archive *fout, Constraint
*** 11699,11705 ****
}
if (binary_upgrade && !coninfo->condef)
! binary_upgrade_set_relfilenodes(q, indxinfo->dobj.catId.oid, true);
appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
fmtId(tbinfo->dobj.name));
--- 11691,11697 ----
}
if (binary_upgrade && !coninfo->condef)
! binary_upgrade_set_pg_class_oids(q, indxinfo->dobj.catId.oid, true);
appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
fmtId(tbinfo->dobj.name));
*************** dumpSequence(Archive *fout, TableInfo *t
*** 12112,12118 ****
if (binary_upgrade)
{
! binary_upgrade_set_relfilenodes(query, tbinfo->dobj.catId.oid, false);
binary_upgrade_set_type_oids_by_rel_oid(query, tbinfo->dobj.catId.oid);
}
--- 12104,12110 ----
if (binary_upgrade)
{
! 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);
}