From 38458e45736efeb0d82739305c77c529c9cf0e1e Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Tue, 10 Apr 2012 19:57:14 -0400 Subject: [PATCH] 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. --- contrib/pg_upgrade/info.c | 15 ++++++++++----- contrib/pg_upgrade/pg_upgrade.h | 3 ++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c index 36683fa15e..e0e3a9f0f5 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 c1925cfe7f..6dcb1a5b50 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 -- 2.40.0