(unnamed)

text/plain

Filename: (unnamed)
Type: text/plain
Part: 0
Message: More pg_upgrade clarifications
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;