17
17
#include "common/logging.h"
18
18
#include "pg_upgrade.h"
19
19
20
- static void transfer_single_new_db (FileNameMap * maps , int size , char * old_tablespace );
20
+ static void transfer_single_new_db (FileNameMap * maps , int size , char * old_tablespace , char * new_tablespace );
21
21
static void transfer_relfile (FileNameMap * map , const char * type_suffix , bool vm_must_add_frozenbit );
22
22
23
23
/*
@@ -136,21 +136,22 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
136
136
*/
137
137
if (user_opts .jobs <= 1 )
138
138
parallel_transfer_all_new_dbs (old_db_arr , new_db_arr , old_pgdata ,
139
- new_pgdata , NULL );
139
+ new_pgdata , NULL , NULL );
140
140
else
141
141
{
142
142
int tblnum ;
143
143
144
144
/* transfer default tablespace */
145
145
parallel_transfer_all_new_dbs (old_db_arr , new_db_arr , old_pgdata ,
146
- new_pgdata , old_pgdata );
146
+ new_pgdata , old_pgdata , new_pgdata );
147
147
148
- for (tblnum = 0 ; tblnum < os_info . num_old_tablespaces ; tblnum ++ )
148
+ for (tblnum = 0 ; tblnum < old_cluster . num_tablespaces ; tblnum ++ )
149
149
parallel_transfer_all_new_dbs (old_db_arr ,
150
150
new_db_arr ,
151
151
old_pgdata ,
152
152
new_pgdata ,
153
- os_info .old_tablespaces [tblnum ]);
153
+ old_cluster .tablespaces [tblnum ],
154
+ new_cluster .tablespaces [tblnum ]);
154
155
/* reap all children */
155
156
while (reap_child (true) == true)
156
157
;
@@ -169,7 +170,8 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
169
170
*/
170
171
void
171
172
transfer_all_new_dbs (DbInfoArr * old_db_arr , DbInfoArr * new_db_arr ,
172
- char * old_pgdata , char * new_pgdata , char * old_tablespace )
173
+ char * old_pgdata , char * new_pgdata ,
174
+ char * old_tablespace , char * new_tablespace )
173
175
{
174
176
int old_dbnum ,
175
177
new_dbnum ;
@@ -204,7 +206,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
204
206
new_pgdata );
205
207
if (n_maps )
206
208
{
207
- transfer_single_new_db (mappings , n_maps , old_tablespace );
209
+ transfer_single_new_db (mappings , n_maps , old_tablespace , new_tablespace );
208
210
}
209
211
/* We allocate something even for n_maps == 0 */
210
212
pg_free (mappings );
@@ -234,10 +236,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
234
236
* moved_db_dir: Destination for the pg_restore-generated database directory.
235
237
*/
236
238
static bool
237
- prepare_for_swap (const char * old_tablespace , Oid db_oid ,
238
- char * old_catalog_dir , char * new_db_dir , char * moved_db_dir )
239
+ prepare_for_swap (const char * old_tablespace , const char * new_tablespace ,
240
+ Oid db_oid , char * old_catalog_dir , char * new_db_dir ,
241
+ char * moved_db_dir )
239
242
{
240
- const char * new_tablespace ;
241
243
const char * old_tblspc_suffix ;
242
244
const char * new_tblspc_suffix ;
243
245
char old_tblspc [MAXPGPATH ];
@@ -247,24 +249,14 @@ prepare_for_swap(const char *old_tablespace, Oid db_oid,
247
249
struct stat st ;
248
250
249
251
if (strcmp (old_tablespace , old_cluster .pgdata ) == 0 )
250
- {
251
- new_tablespace = new_cluster .pgdata ;
252
- new_tblspc_suffix = "/base" ;
253
252
old_tblspc_suffix = "/base" ;
254
- }
255
253
else
256
- {
257
- /*
258
- * XXX: The below line is a hack to deal with the fact that we
259
- * presently don't have an easy way to find the corresponding new
260
- * tablespace's path. This will need to be fixed if/when we add
261
- * pg_upgrade support for in-place tablespaces.
262
- */
263
- new_tablespace = old_tablespace ;
254
+ old_tblspc_suffix = old_cluster .tablespace_suffix ;
264
255
256
+ if (strcmp (new_tablespace , new_cluster .pgdata ) == 0 )
257
+ new_tblspc_suffix = "/base" ;
258
+ else
265
259
new_tblspc_suffix = new_cluster .tablespace_suffix ;
266
- old_tblspc_suffix = old_cluster .tablespace_suffix ;
267
- }
268
260
269
261
/* Old and new cluster paths. */
270
262
snprintf (old_tblspc , sizeof (old_tblspc ), "%s%s" , old_tablespace , old_tblspc_suffix );
@@ -450,7 +442,7 @@ swap_catalog_files(FileNameMap *maps, int size, const char *old_catalog_dir,
450
442
* during pg_restore.
451
443
*/
452
444
static void
453
- do_swap (FileNameMap * maps , int size , char * old_tablespace )
445
+ do_swap (FileNameMap * maps , int size , char * old_tablespace , char * new_tablespace )
454
446
{
455
447
char old_catalog_dir [MAXPGPATH ];
456
448
char new_db_dir [MAXPGPATH ];
@@ -470,21 +462,23 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
470
462
*/
471
463
if (old_tablespace )
472
464
{
473
- if (prepare_for_swap (old_tablespace , maps [0 ].db_oid ,
465
+ if (prepare_for_swap (old_tablespace , new_tablespace , maps [0 ].db_oid ,
474
466
old_catalog_dir , new_db_dir , moved_db_dir ))
475
467
swap_catalog_files (maps , size ,
476
468
old_catalog_dir , new_db_dir , moved_db_dir );
477
469
}
478
470
else
479
471
{
480
- if (prepare_for_swap (old_cluster .pgdata , maps [0 ].db_oid ,
472
+ if (prepare_for_swap (old_cluster .pgdata , new_cluster . pgdata , maps [0 ].db_oid ,
481
473
old_catalog_dir , new_db_dir , moved_db_dir ))
482
474
swap_catalog_files (maps , size ,
483
475
old_catalog_dir , new_db_dir , moved_db_dir );
484
476
485
- for (int tblnum = 0 ; tblnum < os_info . num_old_tablespaces ; tblnum ++ )
477
+ for (int tblnum = 0 ; tblnum < old_cluster . num_tablespaces ; tblnum ++ )
486
478
{
487
- if (prepare_for_swap (os_info .old_tablespaces [tblnum ], maps [0 ].db_oid ,
479
+ if (prepare_for_swap (old_cluster .tablespaces [tblnum ],
480
+ new_cluster .tablespaces [tblnum ],
481
+ maps [0 ].db_oid ,
488
482
old_catalog_dir , new_db_dir , moved_db_dir ))
489
483
swap_catalog_files (maps , size ,
490
484
old_catalog_dir , new_db_dir , moved_db_dir );
@@ -498,7 +492,8 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
498
492
* create links for mappings stored in "maps" array.
499
493
*/
500
494
static void
501
- transfer_single_new_db (FileNameMap * maps , int size , char * old_tablespace )
495
+ transfer_single_new_db (FileNameMap * maps , int size ,
496
+ char * old_tablespace , char * new_tablespace )
502
497
{
503
498
int mapnum ;
504
499
bool vm_must_add_frozenbit = false;
@@ -520,7 +515,7 @@ transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
520
515
*/
521
516
Assert (!vm_must_add_frozenbit );
522
517
523
- do_swap (maps , size , old_tablespace );
518
+ do_swap (maps , size , old_tablespace , new_tablespace );
524
519
return ;
525
520
}
526
521
0 commit comments