(unnamed)

text/plain

Filename: (unnamed)
Type: text/plain
Part: 2
Message: pg_upgrade patches applied
commit 25cc7424e3b4d3bd76fa54bfc6907f294b4b99d1
Author: Bruce Momjian <bruce@momjian.us>
Date:   Tue Jan 4 19:11:00 2011 -0500

    Simplify functions and parameters used by pg_upgrade.

diff --git a/contrib/pg_upgrade/dump.c b/contrib/pg_upgrade/dump.c
index a192cbb..52ab481 100644
*** /tmp/tIZ55c_dump.c	Wed Jan  5 09:04:50 2011
--- /tmp/HVwJqb_dump.c	Wed Jan  5 09:04:50 2011
***************
*** 10,16 ****
  #include "pg_upgrade.h"
  
  
- 
  void
  generate_old_dump(void)
  {
--- 10,15 ----
diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c
index a83248c..9e69ecd 100644
*** /tmp/HVyUPd_info.c	Wed Jan  5 09:04:50 2011
--- /tmp/dK2i7d_info.c	Wed Jan  5 09:04:50 2011
***************
*** 13,36 ****
  
  
  static void get_db_infos(ClusterInfo *cluster);
! static void dbarr_print(ClusterInfo *cluster);
! static void relarr_print(RelInfoArr *arr);
! static void get_rel_infos(ClusterInfo *cluster, const int dbnum);
! static void relarr_free(RelInfoArr *rel_arr);
! static void map_rel(const RelInfo *oldrel,
! 		const RelInfo *newrel, const DbInfo *old_db,
! 		const DbInfo *new_db, const char *olddata,
! 		const char *newdata, FileNameMap *map);
! static void map_rel_by_id(Oid oldid, Oid newid,
! 			  const char *old_nspname, const char *old_relname,
! 			  const char *new_nspname, const char *new_relname,
! 			  const char *old_tablespace, const DbInfo *old_db,
! 			  const DbInfo *new_db, const char *olddata,
! 			  const char *newdata, FileNameMap *map);
! static RelInfo *relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr,
! 				Oid oid);
! static RelInfo *relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
  				  const char *nspname, const char *relname);
  
  
  /*
--- 13,30 ----
  
  
  static void get_db_infos(ClusterInfo *cluster);
! static void print_db_arr(ClusterInfo *cluster);
! static void print_rel_arr(RelInfoArr *arr);
! static void get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo);
! static void free_rel_arr(RelInfoArr *rel_arr);
! static void create_rel_filename_map(const char *old_data, const char *new_data,
! 			  const DbInfo *old_db, const DbInfo *new_db,
! 			  const RelInfo *old_rel, const RelInfo *new_rel,
! 			  FileNameMap *map);
! static RelInfo *relarr_lookup_rel_name(ClusterInfo *cluster, RelInfoArr *rel_arr,
  				  const char *nspname, const char *relname);
+ static RelInfo *relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr,
+ 				Oid oid);
  
  
  /*
*************** gen_db_file_maps(DbInfo *old_db, DbInfo 
*** 62,72 ****
  		if (strcmp(newrel->nspname, "pg_toast") == 0)
  			continue;
  
! 		oldrel = relarr_lookup_rel(&old_cluster, &old_db->rel_arr,
  								   newrel->nspname, newrel->relname);
  
! 		map_rel(oldrel, newrel, old_db, new_db, old_pgdata, new_pgdata,
! 				maps + num_maps);
  		num_maps++;
  
  		/*
--- 56,66 ----
  		if (strcmp(newrel->nspname, "pg_toast") == 0)
  			continue;
  
! 		oldrel = relarr_lookup_rel_name(&old_cluster, &old_db->rel_arr,
  								   newrel->nspname, newrel->relname);
  
! 		create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
! 				oldrel, newrel, maps + num_maps);
  		num_maps++;
  
  		/*
*************** gen_db_file_maps(DbInfo *old_db, DbInfo 
*** 81,100 ****
  			char		old_name[MAXPGPATH];
  
  			/* construct the new and old relnames for the toast relation */
! 			snprintf(old_name, sizeof(old_name), "pg_toast_%u",
! 					 oldrel->reloid);
! 			snprintf(new_name, sizeof(new_name), "pg_toast_%u",
! 					 newrel->reloid);
  
  			/* look them up in their respective arrays */
! 			old_toast = relarr_lookup_reloid(&old_cluster, &old_db->rel_arr,
  											 oldrel->toastrelid);
! 			new_toast = relarr_lookup_rel(&new_cluster, &new_db->rel_arr,
  										  "pg_toast", new_name);
  
  			/* finally create a mapping for them */
! 			map_rel(old_toast, new_toast, old_db, new_db, old_pgdata, new_pgdata,
! 					maps + num_maps);
  			num_maps++;
  
  			/*
--- 75,92 ----
  			char		old_name[MAXPGPATH];
  
  			/* construct the new and old relnames for the toast relation */
! 			snprintf(old_name, sizeof(old_name), "pg_toast_%u", oldrel->reloid);
! 			snprintf(new_name, sizeof(new_name), "pg_toast_%u", newrel->reloid);
  
  			/* look them up in their respective arrays */
! 			old_toast = relarr_lookup_rel_oid(&old_cluster, &old_db->rel_arr,
  											 oldrel->toastrelid);
! 			new_toast = relarr_lookup_rel_name(&new_cluster, &new_db->rel_arr,
  										  "pg_toast", new_name);
  
  			/* finally create a mapping for them */
! 			create_rel_filename_map(old_pgdata, new_pgdata, old_db, new_db,
! 					old_toast, new_toast, maps + num_maps);
  			num_maps++;
  
  			/*
*************** gen_db_file_maps(DbInfo *old_db, DbInfo 
*** 113,127 ****
  					 newrel->reloid);
  
  			/* look them up in their respective arrays */
! 			/* we lose our cache location here */
! 			old_toast = relarr_lookup_rel(&old_cluster, &old_db->rel_arr,
  										  "pg_toast", old_name);
! 			new_toast = relarr_lookup_rel(&new_cluster, &new_db->rel_arr,
  										  "pg_toast", new_name);
  
  			/* finally create a mapping for them */
! 			map_rel(old_toast, new_toast, old_db, new_db, old_pgdata,
! 					new_pgdata, maps + num_maps);
  			num_maps++;
  		}
  	}
--- 105,118 ----
  					 newrel->reloid);
  
  			/* look them up in their respective arrays */
! 			old_toast = relarr_lookup_rel_name(&old_cluster, &old_db->rel_arr,
  										  "pg_toast", old_name);
! 			new_toast = relarr_lookup_rel_name(&new_cluster, &new_db->rel_arr,
  										  "pg_toast", new_name);
  
  			/* finally create a mapping for them */
! 			create_rel_filename_map(old_pgdata, new_pgdata, old_db,
! 					new_db, old_toast, new_toast, maps + num_maps);
  			num_maps++;
  		}
  	}
*************** gen_db_file_maps(DbInfo *old_db, DbInfo 
*** 131,186 ****
  }
  
  
- static void
- map_rel(const RelInfo *oldrel, const RelInfo *newrel,
- 		const DbInfo *old_db, const DbInfo *new_db, const char *olddata,
- 		const char *newdata, FileNameMap *map)
- {
- 	map_rel_by_id(oldrel->relfilenode, newrel->relfilenode, oldrel->nspname,
- 				  oldrel->relname, newrel->nspname, newrel->relname, oldrel->tablespace, old_db,
- 				  new_db, olddata, newdata, map);
- }
- 
- 
  /*
!  * map_rel_by_id()
   *
   * fills a file node map structure and returns it in "map".
   */
  static void
! map_rel_by_id(Oid oldid, Oid newid,
! 			  const char *old_nspname, const char *old_relname,
! 			  const char *new_nspname, const char *new_relname,
! 			  const char *old_tablespace, const DbInfo *old_db,
! 			  const DbInfo *new_db, const char *olddata,
! 			  const char *newdata, FileNameMap *map)
  {
! 	map->old_relfilenode = oldid;
! 	map->new_relfilenode = newid;
  
! 	snprintf(map->old_nspname, sizeof(map->old_nspname), "%s", old_nspname);
! 	snprintf(map->old_relname, sizeof(map->old_relname), "%s", old_relname);
! 	snprintf(map->new_nspname, sizeof(map->new_nspname), "%s", new_nspname);
! 	snprintf(map->new_relname, sizeof(map->new_relname), "%s", new_relname);
  
! 	if (strlen(old_tablespace) == 0)
  	{
  		/*
! 		 * relation belongs to the default tablespace, hence relfiles would
  		 * exist in the data directories.
  		 */
! 		snprintf(map->old_dir, sizeof(map->old_dir), "%s/base/%u", olddata, old_db->db_oid);
! 		snprintf(map->new_dir, sizeof(map->new_dir), "%s/base/%u", newdata, new_db->db_oid);
  	}
  	else
  	{
  		/*
! 		 * relation belongs to some tablespace, hence copy its physical
! 		 * location
  		 */
! 		snprintf(map->old_dir, sizeof(map->old_dir), "%s%s/%u", old_tablespace,
  				 old_cluster.tablespace_suffix, old_db->db_oid);
! 		snprintf(map->new_dir, sizeof(map->new_dir), "%s%s/%u", old_tablespace,
  				 new_cluster.tablespace_suffix, new_db->db_oid);
  	}
  }
--- 122,166 ----
  }
  
  
  /*
!  * create_rel_filename_map()
   *
   * fills a file node map structure and returns it in "map".
   */
  static void
! create_rel_filename_map(const char *old_data, const char *new_data,
! 			  const DbInfo *old_db, const DbInfo *new_db,
! 			  const RelInfo *old_rel, const RelInfo *new_rel,
! 			  FileNameMap *map)
  {
! 	map->old_relfilenode = old_rel->relfilenode;
! 	map->new_relfilenode = new_rel->relfilenode;
  
! 	snprintf(map->old_nspname, sizeof(map->old_nspname), "%s", old_rel->nspname);
! 	snprintf(map->new_nspname, sizeof(map->new_nspname), "%s", new_rel->nspname);
  
! 	snprintf(map->old_relname, sizeof(map->old_relname), "%s", old_rel->relname);
! 	snprintf(map->new_relname, sizeof(map->new_relname), "%s", new_rel->relname);
! 
! 	if (strlen(old_rel->tablespace) == 0)
  	{
  		/*
! 		 * relation belongs to the default tablespace, hence relfiles should
  		 * exist in the data directories.
  		 */
! 		snprintf(map->old_dir, sizeof(map->old_dir), "%s/base/%u", old_data,
! 				 old_db->db_oid);
! 		snprintf(map->new_dir, sizeof(map->new_dir), "%s/base/%u", new_data,
! 				 new_db->db_oid);
  	}
  	else
  	{
  		/*
! 		 * relation belongs to some tablespace, so use the tablespace location
  		 */
! 		snprintf(map->old_dir, sizeof(map->old_dir), "%s%s/%u", old_rel->tablespace,
  				 old_cluster.tablespace_suffix, old_db->db_oid);
! 		snprintf(map->new_dir, sizeof(map->new_dir), "%s%s/%u", new_rel->tablespace,
  				 new_cluster.tablespace_suffix, new_db->db_oid);
  	}
  }
*************** get_db_and_rel_infos(ClusterInfo *cluste
*** 271,280 ****
  	get_db_infos(cluster);
  
  	for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
! 		get_rel_infos(cluster, dbnum);
  
  	if (log_opts.debug)
! 		dbarr_print(cluster);
  }
  
  
--- 251,260 ----
  	get_db_infos(cluster);
  
  	for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
! 		get_rel_infos(cluster, &cluster->dbarr.dbs[dbnum]);
  
  	if (log_opts.debug)
! 		print_db_arr(cluster);
  }
  
  
*************** get_db_and_rel_infos(ClusterInfo *cluste
*** 288,297 ****
   * FirstNormalObjectId belongs to the user
   */
  static void
! get_rel_infos(ClusterInfo *cluster, const int dbnum)
  {
  	PGconn	   *conn = connectToServer(cluster,
! 									   cluster->dbarr.dbs[dbnum].db_name);
  	PGresult   *res;
  	RelInfo    *relinfos;
  	int			ntups;
--- 268,277 ----
   * FirstNormalObjectId belongs to the user
   */
  static void
! get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
  {
  	PGconn	   *conn = connectToServer(cluster,
! 									   dbinfo->db_name);
  	PGresult   *res;
  	RelInfo    *relinfos;
  	int			ntups;
*************** get_rel_infos(ClusterInfo *cluster, cons
*** 373,388 ****
  		tblspace = PQgetvalue(res, relnum, i_spclocation);
  		/* if no table tablespace, use the database tablespace */
  		if (strlen(tblspace) == 0)
! 			tblspace = cluster->dbarr.dbs[dbnum].db_tblspace;
  		strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
  	}
  	PQclear(res);
  
  	PQfinish(conn);
  
! 	cluster->dbarr.dbs[dbnum].rel_arr.rels = relinfos;
! 	cluster->dbarr.dbs[dbnum].rel_arr.nrels = num_rels;
! 	cluster->dbarr.dbs[dbnum].rel_arr.last_relname_lookup = 0;
  }
  
  
--- 353,368 ----
  		tblspace = PQgetvalue(res, relnum, i_spclocation);
  		/* if no table tablespace, use the database tablespace */
  		if (strlen(tblspace) == 0)
! 			tblspace = dbinfo->db_tblspace;
  		strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
  	}
  	PQclear(res);
  
  	PQfinish(conn);
  
! 	dbinfo->rel_arr.rels = relinfos;
! 	dbinfo->rel_arr.nrels = num_rels;
! 	dbinfo->rel_arr.last_relname_lookup = 0;
  }
  
  
*************** dbarr_lookup_db(DbInfoArr *db_arr, const
*** 407,419 ****
  
  
  /*
!  * relarr_lookup_rel()
   *
   * Searches "relname" in rel_arr. Returns the *real* pointer to the
   * RelInfo structure.
   */
  static RelInfo *
! relarr_lookup_rel(ClusterInfo *cluster, RelInfoArr *rel_arr,
  					const char *nspname, const char *relname)
  {
  	int			relnum;
--- 387,399 ----
  
  
  /*
!  * relarr_lookup_rel_name()
   *
   * Searches "relname" in rel_arr. Returns the *real* pointer to the
   * RelInfo structure.
   */
  static RelInfo *
! relarr_lookup_rel_name(ClusterInfo *cluster, RelInfoArr *rel_arr,
  					const char *nspname, const char *relname)
  {
  	int			relnum;
*************** relarr_lookup_rel(ClusterInfo *cluster, 
*** 443,456 ****
  
  
  /*
!  * relarr_lookup_reloid()
   *
   *	Returns a pointer to the RelInfo structure for the
   *	given oid or NULL if the desired entry cannot be
   *	found.
   */
  static RelInfo *
! relarr_lookup_reloid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
  {
  	int			relnum;
  
--- 423,436 ----
  
  
  /*
!  * relarr_lookup_rel_oid()
   *
   *	Returns a pointer to the RelInfo structure for the
   *	given oid or NULL if the desired entry cannot be
   *	found.
   */
  static RelInfo *
! relarr_lookup_rel_oid(ClusterInfo *cluster, RelInfoArr *rel_arr, Oid oid)
  {
  	int			relnum;
  
*************** relarr_lookup_reloid(ClusterInfo *cluste
*** 466,472 ****
  
  
  static void
! relarr_free(RelInfoArr *rel_arr)
  {
  	pg_free(rel_arr->rels);
  	rel_arr->nrels = 0;
--- 446,452 ----
  
  
  static void
! free_rel_arr(RelInfoArr *rel_arr)
  {
  	pg_free(rel_arr->rels);
  	rel_arr->nrels = 0;
*************** dbarr_free(DbInfoArr *db_arr)
*** 480,492 ****
  	int			dbnum;
  
  	for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
! 		relarr_free(&db_arr->dbs[dbnum].rel_arr);
  	db_arr->ndbs = 0;
  }
  
  
  static void
! dbarr_print(ClusterInfo *cluster)
  {
  	int			dbnum;
  
--- 460,472 ----
  	int			dbnum;
  
  	for (dbnum = 0; dbnum < db_arr->ndbs; dbnum++)
! 		free_rel_arr(&db_arr->dbs[dbnum].rel_arr);
  	db_arr->ndbs = 0;
  }
  
  
  static void
! print_db_arr(ClusterInfo *cluster)
  {
  	int			dbnum;
  
*************** dbarr_print(ClusterInfo *cluster)
*** 495,508 ****
  	for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
  	{
  		pg_log(PG_DEBUG, "Database: %s\n", cluster->dbarr.dbs[dbnum].db_name);
! 		relarr_print(&cluster->dbarr.dbs[dbnum].rel_arr);
  		pg_log(PG_DEBUG, "\n\n");
  	}
  }
  
  
  static void
! relarr_print(RelInfoArr *arr)
  {
  	int			relnum;
  
--- 475,488 ----
  	for (dbnum = 0; dbnum < cluster->dbarr.ndbs; dbnum++)
  	{
  		pg_log(PG_DEBUG, "Database: %s\n", cluster->dbarr.dbs[dbnum].db_name);
! 		print_rel_arr(&cluster->dbarr.dbs[dbnum].rel_arr);
  		pg_log(PG_DEBUG, "\n\n");
  	}
  }
  
  
  static void
! print_rel_arr(RelInfoArr *arr)
  {
  	int			relnum;