@@ -246,10 +246,17 @@ output_completion_banner(char *analyze_script_file_name,
246
246
"by pg_upgrade so, once you start the new server, consider running:\n"
247
247
" %s\n\n" , analyze_script_file_name );
248
248
249
- pg_log (PG_REPORT ,
250
- "Running this script will delete the old cluster's data files:\n"
251
- " %s\n" ,
252
- deletion_script_file_name );
249
+
250
+ if (deletion_script_file_name )
251
+ pg_log (PG_REPORT ,
252
+ "Running this script will delete the old cluster's data files:\n"
253
+ " %s\n" ,
254
+ deletion_script_file_name );
255
+ else
256
+ pg_log (PG_REPORT ,
257
+ "Could not create a script to delete the old cluster's data\n"
258
+ "files because user-defined tablespaces exist in the old cluster\n"
259
+ "directory. The old cluster's contents must be deleted manually.\n" );
253
260
}
254
261
255
262
@@ -584,14 +591,38 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
584
591
{
585
592
FILE * script = NULL ;
586
593
int tblnum ;
594
+ char old_cluster_pgdata [MAXPGPATH ];
587
595
588
596
* deletion_script_file_name = pg_malloc (MAXPGPATH );
589
597
590
- prep_status ("Creating script to delete old cluster" );
591
-
592
598
snprintf (* deletion_script_file_name , MAXPGPATH , "delete_old_cluster.%s" ,
593
599
SCRIPT_EXT );
594
600
601
+ /*
602
+ * Some users (oddly) create tablespaces inside the cluster data
603
+ * directory. We can't create a proper old cluster delete script
604
+ * in that case.
605
+ */
606
+ strlcpy (old_cluster_pgdata , old_cluster .pgdata , MAXPGPATH );
607
+ canonicalize_path (old_cluster_pgdata );
608
+ for (tblnum = 0 ; tblnum < os_info .num_old_tablespaces ; tblnum ++ )
609
+ {
610
+ char old_tablespace_dir [MAXPGPATH ];
611
+
612
+ strlcpy (old_tablespace_dir , os_info .old_tablespaces [tblnum ], MAXPGPATH );
613
+ canonicalize_path (old_tablespace_dir );
614
+ if (path_is_prefix_of_path (old_cluster_pgdata , old_tablespace_dir ))
615
+ {
616
+ /* Unlink file in case it is left over from a previous run. */
617
+ unlink (* deletion_script_file_name );
618
+ pg_free (* deletion_script_file_name );
619
+ * deletion_script_file_name = NULL ;
620
+ return ;
621
+ }
622
+ }
623
+
624
+ prep_status ("Creating script to delete old cluster" );
625
+
595
626
if ((script = fopen_priv (* deletion_script_file_name , "w" )) == NULL )
596
627
pg_log (PG_FATAL , "Could not open file \"%s\": %s\n" ,
597
628
* deletion_script_file_name , getErrorText (errno ));
0 commit comments