summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorMagnus Hagander <magnus@hagander.net>2011-12-07 10:35:00 +0100
committerMagnus Hagander <magnus@hagander.net>2011-12-07 10:37:33 +0100
commit16d8e594acd96661267cb7897834f9cba51a2ffd (patch)
tree4ab54a17950270328b54550af91aae4e2c6e245f /contrib
parentc6e3ac11b60ac4a8942ab964252d51c1c0bd8845 (diff)
Remove spclocation field from pg_tablespace
Instead, add a function pg_tablespace_location(oid) used to return the same information, and do this by reading the symbolic link. Doing it this way makes it possible to relocate a tablespace when the database is down by simply changing the symbolic link.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/pg_upgrade/info.c25
-rw-r--r--contrib/pg_upgrade/tablespace.c18
2 files changed, 29 insertions, 14 deletions
diff --git a/contrib/pg_upgrade/info.c b/contrib/pg_upgrade/info.c
index b55bd6d23c2..c33e13a6704 100644
--- a/contrib/pg_upgrade/info.c
+++ b/contrib/pg_upgrade/info.c
@@ -193,15 +193,21 @@ get_db_infos(ClusterInfo *cluster)
int i_datname,
i_oid,
i_spclocation;
+ char query[QUERY_ALLOC];
- res = executeQueryOrDie(conn,
- "SELECT d.oid, d.datname, t.spclocation "
- "FROM pg_catalog.pg_database d "
- " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
- " ON d.dattablespace = t.oid "
- "WHERE d.datallowconn = true "
+ snprintf(query, sizeof(query),
+ "SELECT d.oid, d.datname, %s "
+ "FROM pg_catalog.pg_database d "
+ " LEFT OUTER JOIN pg_catalog.pg_tablespace t "
+ " ON d.dattablespace = t.oid "
+ "WHERE d.datallowconn = true "
/* we don't preserve pg_database.oid so we sort by name */
- "ORDER BY 2");
+ "ORDER BY 2",
+ /* 9.2 removed the spclocation column */
+ (GET_MAJOR_VERSION(old_cluster.major_version) <= 901) ?
+ "t.spclocation" : "pg_catalog.pg_tablespace_location(t.oid) AS spclocation");
+
+ res = executeQueryOrDie(conn, "%s", query);
i_oid = PQfnumber(res, "oid");
i_datname = PQfnumber(res, "datname");
@@ -265,7 +271,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
snprintf(query, sizeof(query),
"SELECT c.oid, n.nspname, c.relname, "
- " c.relfilenode, t.spclocation "
+ " c.relfilenode, %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 "
@@ -280,6 +286,9 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
" relname IN ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
/* we preserve pg_class.oid so we sort by it to match old/new */
"ORDER BY 1;",
+ /* 9.2 removed the spclocation column */
+ (GET_MAJOR_VERSION(old_cluster.major_version) <= 901) ?
+ "t.spclocation" : "pg_catalog.pg_tablespace_location(t.oid) AS spclocation",
/* see the comment at the top of old_8_3_create_sequence_script() */
(GET_MAJOR_VERSION(old_cluster.major_version) <= 803) ?
"" : ", 'S'",
diff --git a/contrib/pg_upgrade/tablespace.c b/contrib/pg_upgrade/tablespace.c
index 08d227c10a0..df2285f3669 100644
--- a/contrib/pg_upgrade/tablespace.c
+++ b/contrib/pg_upgrade/tablespace.c
@@ -44,12 +44,18 @@ get_tablespace_paths(void)
PGresult *res;
int tblnum;
int i_spclocation;
-
- res = executeQueryOrDie(conn,
- "SELECT spclocation "
- "FROM pg_catalog.pg_tablespace "
- "WHERE spcname != 'pg_default' AND "
- " spcname != 'pg_global'");
+ char query[QUERY_ALLOC];
+
+ snprintf(query, sizeof(query),
+ "SELECT %s "
+ "FROM pg_catalog.pg_tablespace "
+ "WHERE spcname != 'pg_default' AND "
+ " spcname != 'pg_global'",
+ /* 9.2 removed the spclocation column */
+ (GET_MAJOR_VERSION(old_cluster.major_version) <= 901) ?
+ "t.spclocation" : "pg_catalog.pg_tablespace_location(oid) AS spclocation");
+
+ res = executeQueryOrDie(conn, "%s", query);
if ((os_info.num_tablespaces = PQntuples(res)) != 0)
os_info.tablespaces = (char **) pg_malloc(