]> granicus.if.org Git - postgresql/commitdiff
Fix pg_upgrade to properly upgrade a table that is stored in the cluster
authorBruce Momjian <bruce@momjian.us>
Tue, 10 Apr 2012 23:57:14 +0000 (19:57 -0400)
committerBruce Momjian <bruce@momjian.us>
Tue, 10 Apr 2012 23:57:14 +0000 (19:57 -0400)
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
contrib/pg_upgrade/pg_upgrade.h

index 36683fa15eaa9a0df78dfb95af97ba104d376a49..e0e3a9f0f5f2c87a27ffa58a4a97df59912c3623 100644 (file)
@@ -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);
index c1925cfe7f52a151f00fa640a9a706ad56b46b74..6dcb1a5b50f7aded85f956599d4423280820e7e9 100644 (file)
@@ -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