summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2012-04-10 23:57:14 +0000
committerBruce Momjian2012-04-10 23:57:14 +0000
commit38458e45736efeb0d82739305c77c529c9cf0e1e (patch)
treebe20280921f1fc9ec62686c482239d7a46c11dd1
parenteb821b91c86a85a37572c9062902f94a5efba528 (diff)
Fix pg_upgrade to properly upgrade a table that is stored in the cluster
default tablespace, but part of a database that is in a user-defined tablespace. Caused "file not found" error during upgrade. Per bug report from Ants Aasma. Backpatch to 9.1 and 9.0.
-rw-r--r--contrib/pg_upgrade/info.c15
-rw-r--r--contrib/pg_upgrade/pg_upgrade.h3
2 files changed, 12 insertions, 6 deletions
diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c
index 36683fa15ea..e0e3a9f0f5f 100644
--- a/contrib/pg_upgrade/info.c
+++ b/contrib/pg_upgrade/info.c
@@ -256,7 +256,8 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
i_nspname,
i_relname,
i_oid,
- i_relfilenode;
+ i_relfilenode,
+ i_reltablespace;
char query[QUERY_ALLOC];
/*
@@ -269,7 +270,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
snprintf(query, sizeof(query),
"SELECT c.oid, n.nspname, c.relname, "
- " c.relfilenode, %s "
+ " c.relfilenode, c.reltablespace, %s "
"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 "
@@ -306,6 +307,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
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++)
@@ -323,10 +325,13 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
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)
+ 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
index c1925cfe7f5..6dcb1a5b50f 100644
--- a/contrib/pg_upgrade/pg_upgrade.h
+++ b/contrib/pg_upgrade/pg_upgrade.h
@@ -109,7 +109,8 @@ typedef struct
char relname[NAMEDATALEN]; /* relation name */
Oid reloid; /* relation oid */
Oid relfilenode; /* relation relfile node */
- char tablespace[MAXPGPATH]; /* relations tablespace path */
+ /* relation tablespace path, or "" for the cluster default */
+ char tablespace[MAXPGPATH];
} RelInfo;
typedef struct