@@ -255,9 +255,10 @@ output_completion_banner(char *analyze_script_file_name,
255
255
deletion_script_file_name );
256
256
else
257
257
pg_log (PG_REPORT ,
258
- "Could not create a script to delete the old cluster's data\n"
259
- "files because user-defined tablespaces exist in the old cluster\n"
260
- "directory. The old cluster's contents must be deleted manually.\n" );
258
+ "Could not create a script to delete the old cluster's data files\n"
259
+ "because user-defined tablespaces or the new cluster's data directory\n"
260
+ "exist in the old cluster directory. The old cluster's contents must\n"
261
+ "be deleted manually.\n" );
261
262
}
262
263
263
264
@@ -693,20 +694,37 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
693
694
{
694
695
FILE * script = NULL ;
695
696
int tblnum ;
696
- char old_cluster_pgdata [MAXPGPATH ];
697
+ char old_cluster_pgdata [MAXPGPATH ], new_cluster_pgdata [ MAXPGPATH ] ;
697
698
698
699
* deletion_script_file_name = pg_malloc (MAXPGPATH );
699
700
700
701
snprintf (* deletion_script_file_name , MAXPGPATH , "delete_old_cluster.%s" ,
701
702
SCRIPT_EXT );
702
703
704
+ strlcpy (old_cluster_pgdata , old_cluster .pgdata , MAXPGPATH );
705
+ canonicalize_path (old_cluster_pgdata );
706
+
707
+ strlcpy (new_cluster_pgdata , new_cluster .pgdata , MAXPGPATH );
708
+ canonicalize_path (new_cluster_pgdata );
709
+
710
+ /* Some people put the new data directory inside the old one. */
711
+ if (path_is_prefix_of_path (old_cluster_pgdata , new_cluster_pgdata ))
712
+ {
713
+ pg_log (PG_WARNING ,
714
+ "\nWARNING: new data directory should not be inside the old data directory, e.g. %s\n" , old_cluster_pgdata );
715
+
716
+ /* Unlink file in case it is left over from a previous run. */
717
+ unlink (* deletion_script_file_name );
718
+ pg_free (* deletion_script_file_name );
719
+ * deletion_script_file_name = NULL ;
720
+ return ;
721
+ }
722
+
703
723
/*
704
724
* Some users (oddly) create tablespaces inside the cluster data
705
725
* directory. We can't create a proper old cluster delete script in that
706
726
* case.
707
727
*/
708
- strlcpy (old_cluster_pgdata , old_cluster .pgdata , MAXPGPATH );
709
- canonicalize_path (old_cluster_pgdata );
710
728
for (tblnum = 0 ; tblnum < os_info .num_old_tablespaces ; tblnum ++ )
711
729
{
712
730
char old_tablespace_dir [MAXPGPATH ];
0 commit comments