mirror of
https://github.com/postgres/postgres.git
synced 2025-07-17 06:41:09 +03:00
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.
This commit is contained in:
@ -306,6 +306,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
|
|||||||
int i_relname = -1;
|
int i_relname = -1;
|
||||||
int i_oid = -1;
|
int i_oid = -1;
|
||||||
int i_relfilenode = -1;
|
int i_relfilenode = -1;
|
||||||
|
int i_reltablespace = -1;
|
||||||
int i_reltoastrelid = -1;
|
int i_reltoastrelid = -1;
|
||||||
char query[QUERY_ALLOC];
|
char query[QUERY_ALLOC];
|
||||||
|
|
||||||
@ -320,7 +321,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
|
|||||||
|
|
||||||
snprintf(query, sizeof(query),
|
snprintf(query, sizeof(query),
|
||||||
"SELECT DISTINCT c.oid, n.nspname, c.relname, "
|
"SELECT DISTINCT c.oid, n.nspname, c.relname, "
|
||||||
" c.relfilenode, c.reltoastrelid, t.spclocation "
|
" c.relfilenode, c.reltoastrelid, c.reltablespace, t.spclocation "
|
||||||
"FROM pg_catalog.pg_class c JOIN "
|
"FROM pg_catalog.pg_class c JOIN "
|
||||||
" pg_catalog.pg_namespace n "
|
" pg_catalog.pg_namespace n "
|
||||||
" ON c.relnamespace = n.oid "
|
" ON c.relnamespace = n.oid "
|
||||||
@ -339,7 +340,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
|
|||||||
" ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
|
" ('pg_largeobject', 'pg_largeobject_loid_pn_index'%s) )) "
|
||||||
" AND relkind IN ('r','t', 'i'%s)"
|
" AND relkind IN ('r','t', 'i'%s)"
|
||||||
"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
|
"GROUP BY c.oid, n.nspname, c.relname, c.relfilenode,"
|
||||||
" c.reltoastrelid, t.spclocation, "
|
" c.reltoastrelid, c.reltablespace, t.spclocation, "
|
||||||
" n.nspname "
|
" n.nspname "
|
||||||
"ORDER BY n.nspname, c.relname;",
|
"ORDER BY n.nspname, c.relname;",
|
||||||
FirstNormalObjectId,
|
FirstNormalObjectId,
|
||||||
@ -361,6 +362,7 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
|
|||||||
i_relname = PQfnumber(res, "relname");
|
i_relname = PQfnumber(res, "relname");
|
||||||
i_relfilenode = PQfnumber(res, "relfilenode");
|
i_relfilenode = PQfnumber(res, "relfilenode");
|
||||||
i_reltoastrelid = PQfnumber(res, "reltoastrelid");
|
i_reltoastrelid = PQfnumber(res, "reltoastrelid");
|
||||||
|
i_reltablespace = PQfnumber(res, "reltablespace");
|
||||||
i_spclocation = PQfnumber(res, "spclocation");
|
i_spclocation = PQfnumber(res, "spclocation");
|
||||||
|
|
||||||
for (relnum = 0; relnum < ntups; relnum++)
|
for (relnum = 0; relnum < ntups; relnum++)
|
||||||
@ -379,10 +381,13 @@ get_rel_infos(migratorContext *ctx, const DbInfo *dbinfo,
|
|||||||
curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
|
curr->relfilenode = atooid(PQgetvalue(res, relnum, i_relfilenode));
|
||||||
curr->toastrelid = atooid(PQgetvalue(res, relnum, i_reltoastrelid));
|
curr->toastrelid = atooid(PQgetvalue(res, relnum, i_reltoastrelid));
|
||||||
|
|
||||||
tblspace = PQgetvalue(res, relnum, i_spclocation);
|
if (atooid(PQgetvalue(res, relnum, i_reltablespace)) != 0)
|
||||||
/* if no table tablespace, use the database tablespace */
|
/* Might be "", meaning the cluster default location. */
|
||||||
if (strlen(tblspace) == 0)
|
tblspace = PQgetvalue(res, relnum, i_spclocation);
|
||||||
|
else
|
||||||
|
/* A zero reltablespace indicates the database tablespace. */
|
||||||
tblspace = dbinfo->db_tblspace;
|
tblspace = dbinfo->db_tblspace;
|
||||||
|
|
||||||
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
|
strlcpy(curr->tablespace, tblspace, sizeof(curr->tablespace));
|
||||||
}
|
}
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
|
@ -69,7 +69,8 @@ typedef struct
|
|||||||
Oid reloid; /* relation oid */
|
Oid reloid; /* relation oid */
|
||||||
Oid relfilenode; /* relation relfile node */
|
Oid relfilenode; /* relation relfile node */
|
||||||
Oid toastrelid; /* oid of the toast relation */
|
Oid toastrelid; /* oid of the toast relation */
|
||||||
char tablespace[MAXPGPATH]; /* relations tablespace path */
|
/* relation tablespace path, or "" for the cluster default */
|
||||||
|
char tablespace[MAXPGPATH];
|
||||||
} RelInfo;
|
} RelInfo;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
Reference in New Issue
Block a user