Skip to content

Commit 38458e4

Browse files
committed
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.
1 parent eb821b9 commit 38458e4

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

contrib/pg_upgrade/info.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
256256
i_nspname,
257257
i_relname,
258258
i_oid,
259-
i_relfilenode;
259+
i_relfilenode,
260+
i_reltablespace;
260261
char query[QUERY_ALLOC];
261262

262263
/*
@@ -269,7 +270,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
269270

270271
snprintf(query, sizeof(query),
271272
"SELECT c.oid, n.nspname, c.relname, "
272-
" c.relfilenode, %s "
273+
" c.relfilenode, c.reltablespace, %s "
273274
"FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n "
274275
" ON c.relnamespace = n.oid "
275276
" LEFT OUTER JOIN pg_catalog.pg_tablespace t "
@@ -306,6 +307,7 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
306307
i_nspname = PQfnumber(res, "nspname");
307308
i_relname = PQfnumber(res, "relname");
308309
i_relfilenode = PQfnumber(res, "relfilenode");
310+
i_reltablespace = PQfnumber(res, "reltablespace");
309311
i_spclocation = PQfnumber(res, "spclocation");
310312

311313
for (relnum = 0; relnum < ntups; relnum++)
@@ -323,10 +325,13 @@ get_rel_infos(ClusterInfo *cluster, DbInfo *dbinfo)
323325

324326
curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
325327

326-
tblspace = PQgetvalue(res, relnum, i_spclocation);
327-
/* if no table tablespace, use the database tablespace */
328-
if (strlen(tblspace) == 0)
328+
if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
329+
/* Might be "", meaning the cluster default location. */
330+
tblspace = PQgetvalue(res, relnum, i_spclocation);
331+
else
332+
/* A zero reltablespace indicates the database tablespace. */
329333
tblspace = dbinfo->db_tblspace;
334+
330335
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
331336
}
332337
PQclear(res);

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ typedef struct
109109
char relname[NAMEDATALEN]; /* relation name */
110110
Oid reloid; /* relation oid */
111111
Oid relfilenode; /* relation relfile node */
112-
char tablespace[MAXPGPATH]; /* relations tablespace path */
112+
/* relation tablespace path, or "" for the cluster default */
113+
char tablespace[MAXPGPATH];
113114
} RelInfo;
114115

115116
typedef struct

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy