@@ -27,7 +27,7 @@ static void map_rel(migratorContext *ctx, const RelInfo *oldrel,
27
27
static void map_rel_by_id (migratorContext * ctx , Oid oldid , Oid newid ,
28
28
const char * old_nspname , const char * old_relname ,
29
29
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 ,
31
31
const DbInfo * new_db , const char * olddata ,
32
32
const char * newdata , FileNameMap * map );
33
33
static RelInfo * relarr_lookup_reloid (migratorContext * ctx ,
@@ -140,7 +140,7 @@ map_rel(migratorContext *ctx, const RelInfo *oldrel, const RelInfo *newrel,
140
140
const char * newdata , FileNameMap * map )
141
141
{
142
142
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 ,
144
144
new_db , olddata , newdata , map );
145
145
}
146
146
@@ -154,7 +154,7 @@ static void
154
154
map_rel_by_id (migratorContext * ctx , Oid oldid , Oid newid ,
155
155
const char * old_nspname , const char * old_relname ,
156
156
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 ,
158
158
const DbInfo * new_db , const char * olddata ,
159
159
const char * newdata , FileNameMap * map )
160
160
{
@@ -166,14 +166,14 @@ map_rel_by_id(migratorContext *ctx, Oid oldid, Oid newid,
166
166
snprintf (map -> new_nspname , sizeof (map -> new_nspname ), "%s" , new_nspname );
167
167
snprintf (map -> new_relname , sizeof (map -> new_relname ), "%s" , new_relname );
168
168
169
+ /* In case old/new tablespaces don't match, do them separately. */
169
170
if (strlen (old_tablespace ) == 0 )
170
171
{
171
172
/*
172
173
* relation belongs to the default tablespace, hence relfiles would
173
174
* exist in the data directories.
174
175
*/
175
176
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 );
177
177
}
178
178
else
179
179
{
@@ -183,7 +183,24 @@ map_rel_by_id(migratorContext *ctx, Oid oldid, Oid newid,
183
183
*/
184
184
snprintf (map -> old_file , sizeof (map -> old_file ), "%s%s/%u" , old_tablespace ,
185
185
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 ,
187
204
ctx -> new .tablespace_suffix , new_db -> db_oid );
188
205
}
189
206
}
0 commit comments