1717#include "common/logging.h"
1818#include "pg_upgrade.h"
1919
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 );
2121static void transfer_relfile (FileNameMap * map , const char * type_suffix , bool vm_must_add_frozenbit );
2222
2323/*
@@ -136,21 +136,22 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
136136 */
137137 if (user_opts .jobs <= 1 )
138138 parallel_transfer_all_new_dbs (old_db_arr , new_db_arr , old_pgdata ,
139- new_pgdata , NULL );
139+ new_pgdata , NULL , NULL );
140140 else
141141 {
142142 int tblnum ;
143143
144144 /* transfer default tablespace */
145145 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 );
147147
148- for (tblnum = 0 ; tblnum < os_info . num_old_tablespaces ; tblnum ++ )
148+ for (tblnum = 0 ; tblnum < old_cluster . num_tablespaces ; tblnum ++ )
149149 parallel_transfer_all_new_dbs (old_db_arr ,
150150 new_db_arr ,
151151 old_pgdata ,
152152 new_pgdata ,
153- os_info .old_tablespaces [tblnum ]);
153+ old_cluster .tablespaces [tblnum ],
154+ new_cluster .tablespaces [tblnum ]);
154155 /* reap all children */
155156 while (reap_child (true) == true)
156157 ;
@@ -169,7 +170,8 @@ transfer_all_new_tablespaces(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
169170 */
170171void
171172transfer_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 )
173175{
174176 int old_dbnum ,
175177 new_dbnum ;
@@ -204,7 +206,7 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
204206 new_pgdata );
205207 if (n_maps )
206208 {
207- transfer_single_new_db (mappings , n_maps , old_tablespace );
209+ transfer_single_new_db (mappings , n_maps , old_tablespace , new_tablespace );
208210 }
209211 /* We allocate something even for n_maps == 0 */
210212 pg_free (mappings );
@@ -234,10 +236,10 @@ transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
234236 * moved_db_dir: Destination for the pg_restore-generated database directory.
235237 */
236238static 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 )
239242{
240- const char * new_tablespace ;
241243 const char * old_tblspc_suffix ;
242244 const char * new_tblspc_suffix ;
243245 char old_tblspc [MAXPGPATH ];
@@ -247,24 +249,14 @@ prepare_for_swap(const char *old_tablespace, Oid db_oid,
247249 struct stat st ;
248250
249251 if (strcmp (old_tablespace , old_cluster .pgdata ) == 0 )
250- {
251- new_tablespace = new_cluster .pgdata ;
252- new_tblspc_suffix = "/base" ;
253252 old_tblspc_suffix = "/base" ;
254- }
255253 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 ;
264255
256+ if (strcmp (new_tablespace , new_cluster .pgdata ) == 0 )
257+ new_tblspc_suffix = "/base" ;
258+ else
265259 new_tblspc_suffix = new_cluster .tablespace_suffix ;
266- old_tblspc_suffix = old_cluster .tablespace_suffix ;
267- }
268260
269261 /* Old and new cluster paths. */
270262 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,
450442 * during pg_restore.
451443 */
452444static void
453- do_swap (FileNameMap * maps , int size , char * old_tablespace )
445+ do_swap (FileNameMap * maps , int size , char * old_tablespace , char * new_tablespace )
454446{
455447 char old_catalog_dir [MAXPGPATH ];
456448 char new_db_dir [MAXPGPATH ];
@@ -470,21 +462,23 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
470462 */
471463 if (old_tablespace )
472464 {
473- if (prepare_for_swap (old_tablespace , maps [0 ].db_oid ,
465+ if (prepare_for_swap (old_tablespace , new_tablespace , maps [0 ].db_oid ,
474466 old_catalog_dir , new_db_dir , moved_db_dir ))
475467 swap_catalog_files (maps , size ,
476468 old_catalog_dir , new_db_dir , moved_db_dir );
477469 }
478470 else
479471 {
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 ,
481473 old_catalog_dir , new_db_dir , moved_db_dir ))
482474 swap_catalog_files (maps , size ,
483475 old_catalog_dir , new_db_dir , moved_db_dir );
484476
485- for (int tblnum = 0 ; tblnum < os_info . num_old_tablespaces ; tblnum ++ )
477+ for (int tblnum = 0 ; tblnum < old_cluster . num_tablespaces ; tblnum ++ )
486478 {
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 ,
488482 old_catalog_dir , new_db_dir , moved_db_dir ))
489483 swap_catalog_files (maps , size ,
490484 old_catalog_dir , new_db_dir , moved_db_dir );
@@ -498,7 +492,8 @@ do_swap(FileNameMap *maps, int size, char *old_tablespace)
498492 * create links for mappings stored in "maps" array.
499493 */
500494static 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 )
502497{
503498 int mapnum ;
504499 bool vm_must_add_frozenbit = false;
@@ -520,7 +515,7 @@ transfer_single_new_db(FileNameMap *maps, int size, char *old_tablespace)
520515 */
521516 Assert (!vm_must_add_frozenbit );
522517
523- do_swap (maps , size , old_tablespace );
518+ do_swap (maps , size , old_tablespace , new_tablespace );
524519 return ;
525520 }
526521
0 commit comments