9.1

text/plain

Filename: 9.1
Type: text/plain
Part: 1
Message: Re: pg_upgrade incorrectly equates pg_default and database tablespace
diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c
new file mode 100644
index 7e177d4..dad0117
*** a/contrib/pg_upgrade/info.c
--- b/contrib/pg_upgrade/info.c
*************** get_rel_infos(ClusterInfo *cluster, DbIn
*** 250,256 ****
  				i_nspname,
  				i_relname,
  				i_oid,
! 				i_relfilenode;
  	char		query[QUERY_ALLOC];
  
  	/*
--- 250,257 ----
  				i_nspname,
  				i_relname,
  				i_oid,
! 				i_relfilenode,
! 				i_reltablespace;
  	char		query[QUERY_ALLOC];
  
  	/*
*************** get_rel_infos(ClusterInfo *cluster, DbIn
*** 263,269 ****
  
  	snprintf(query, sizeof(query),
  			 "SELECT c.oid, n.nspname, c.relname, "
! 			 "	c.relfilenode, t.spclocation "
  			 "FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
  			 "	   ON c.relnamespace = n.oid "
  			 "  LEFT OUTER JOIN pg_catalog.pg_tablespace t "
--- 264,270 ----
  
  	snprintf(query, sizeof(query),
  			 "SELECT c.oid, n.nspname, c.relname, "
! 			 "	c.relfilenode, c.reltablespace, t.spclocation "
  			 "FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
  			 "	   ON c.relnamespace = n.oid "
  			 "  LEFT OUTER JOIN pg_catalog.pg_tablespace t "
*************** get_rel_infos(ClusterInfo *cluster, DbIn
*** 297,302 ****
--- 298,304 ----
  	i_nspname = PQfnumber(res, "nspname");
  	i_relname = PQfnumber(res, "relname");
  	i_relfilenode = PQfnumber(res, "relfilenode");
+ 	i_reltablespace = PQfnumber(res, "reltablespace");
  	i_spclocation = PQfnumber(res, "spclocation");
  
  	for (relnum = 0; relnum < ntups; relnum++)
*************** get_rel_infos(ClusterInfo *cluster, DbIn
*** 314,323 ****
  
  		curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
  
! 		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);
--- 316,328 ----
  
  		curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
  
! 		if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
! 			/* Might be "", meaning the cluster default location. */
! 			tblspace = PQgetvalue(res, relnum, i_spclocation);
! 		else
! 			/* A zero reltablespace indicates the database tablespace. */
  			tblspace = dbinfo->db_tblspace;
+ 
  		strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
  	}
  	PQclear(res);
diff --git a/contrib/pg_upgrade/pg_upgrade.h b/contrib/pg_upgrade/pg_upgrade.h
new file mode 100644
index 898541b..204749b
*** a/contrib/pg_upgrade/pg_upgrade.h
--- b/contrib/pg_upgrade/pg_upgrade.h
*************** typedef struct
*** 71,77 ****
  	char		relname[NAMEDATALEN];	/* relation name */
  	Oid			reloid;			/* relation oid */
  	Oid			relfilenode;	/* relation relfile node */
! 	char		tablespace[MAXPGPATH];	/* relations tablespace path */
  } RelInfo;
  
  typedef struct
--- 71,78 ----
  	char		relname[NAMEDATALEN];	/* relation name */
  	Oid			reloid;			/* relation oid */
  	Oid			relfilenode;	/* relation relfile node */
! 	/* relation tablespace path, or "" for the cluster default */
! 	char		tablespace[MAXPGPATH];	
  } RelInfo;
  
  typedef struct