@@ -27,7 +27,7 @@ static void map_rel(migratorContext *ctx, const RelInfo *oldrel,
2727static void map_rel_by_id (migratorContext * ctx , Oid oldid , Oid newid ,
2828 const char * old_nspname , const char * old_relname ,
2929 const char * new_nspname , const char * new_relname ,
30- const char * old_tablespace , const DbInfo * old_db ,
30+ const char * old_tablespace , const char * new_tablespace , const DbInfo * old_db ,
3131 const DbInfo * new_db , const char * olddata ,
3232 const char * newdata , FileNameMap * map );
3333static RelInfo * relarr_lookup_reloid (migratorContext * ctx ,
@@ -140,7 +140,7 @@ map_rel(migratorContext *ctx, const RelInfo *oldrel, const RelInfo *newrel,
140140 const char * newdata , FileNameMap * map )
141141{
142142 map_rel_by_id (ctx , oldrel -> relfilenode , newrel -> relfilenode , oldrel -> nspname ,
143- oldrel -> relname , newrel -> nspname , newrel -> relname , oldrel -> tablespace , old_db ,
143+ oldrel -> relname , newrel -> nspname , newrel -> relname , oldrel -> tablespace , newrel -> tablespace , old_db ,
144144 new_db , olddata , newdata , map );
145145}
146146
@@ -154,7 +154,7 @@ static void
154154map_rel_by_id (migratorContext * ctx , Oid oldid , Oid newid ,
155155 const char * old_nspname , const char * old_relname ,
156156 const char * new_nspname , const char * new_relname ,
157- const char * old_tablespace , const DbInfo * old_db ,
157+ const char * old_tablespace , const char * new_tablespace , const DbInfo * old_db ,
158158 const DbInfo * new_db , const char * olddata ,
159159 const char * newdata , FileNameMap * map )
160160{
@@ -166,14 +166,14 @@ map_rel_by_id(migratorContext *ctx, Oid oldid, Oid newid,
166166 snprintf (map -> new_nspname , sizeof (map -> new_nspname ), "%s" , new_nspname );
167167 snprintf (map -> new_relname , sizeof (map -> new_relname ), "%s" , new_relname );
168168
169+ /* In case old/new tablespaces don't match, do them separately. */
169170 if (strlen (old_tablespace ) == 0 )
170171 {
171172 /*
172173 * relation belongs to the default tablespace, hence relfiles would
173174 * exist in the data directories.
174175 */
175176 snprintf (map -> old_file , sizeof (map -> old_file ), "%s/base/%u" , olddata , old_db -> db_oid );
176- snprintf (map -> new_file , sizeof (map -> new_file ), "%s/base/%u" , newdata , new_db -> db_oid );
177177 }
178178 else
179179 {
@@ -183,7 +183,24 @@ map_rel_by_id(migratorContext *ctx, Oid oldid, Oid newid,
183183 */
184184 snprintf (map -> old_file , sizeof (map -> old_file ), "%s%s/%u" , old_tablespace ,
185185 ctx -> old .tablespace_suffix , old_db -> db_oid );
186- snprintf (map -> new_file , sizeof (map -> new_file ), "%s%s/%u" , old_tablespace ,
186+ }
187+
188+ /* Do the same for new tablespaces */
189+ if (strlen (new_tablespace ) == 0 )
190+ {
191+ /*
192+ * relation belongs to the default tablespace, hence relfiles would
193+ * exist in the data directories.
194+ */
195+ snprintf (map -> new_file , sizeof (map -> new_file ), "%s/base/%u" , newdata , new_db -> db_oid );
196+ }
197+ else
198+ {
199+ /*
200+ * relation belongs to some tablespace, hence copy its physical
201+ * location
202+ */
203+ snprintf (map -> new_file , sizeof (map -> new_file ), "%s%s/%u" , new_tablespace ,
187204 ctx -> new .tablespace_suffix , new_db -> db_oid );
188205 }
189206}
0 commit comments