@@ -195,9 +195,10 @@ output_completion_banner(char *analyze_script_file_name,
195
195
deletion_script_file_name );
196
196
else
197
197
pg_log (PG_REPORT ,
198
- "Could not create a script to delete the old cluster's data\n"
199
- "files because user-defined tablespaces exist in the old cluster\n"
200
- "directory. The old cluster's contents must be deleted manually.\n" );
198
+ "Could not create a script to delete the old cluster's data files\n"
199
+ "because user-defined tablespaces or the new cluster's data directory\n"
200
+ "exist in the old cluster directory. The old cluster's contents must\n"
201
+ "be deleted manually.\n" );
201
202
}
202
203
203
204
@@ -490,18 +491,35 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
490
491
{
491
492
FILE * script = NULL ;
492
493
int tblnum ;
493
- char old_cluster_pgdata [MAXPGPATH ];
494
+ char old_cluster_pgdata [MAXPGPATH ], new_cluster_pgdata [ MAXPGPATH ] ;
494
495
495
496
* deletion_script_file_name = psprintf ("%sdelete_old_cluster.%s" ,
496
497
SCRIPT_PREFIX ,SCRIPT_EXT );
497
498
499
+ strlcpy (old_cluster_pgdata ,old_cluster .pgdata ,MAXPGPATH );
500
+ canonicalize_path (old_cluster_pgdata );
501
+
502
+ strlcpy (new_cluster_pgdata ,new_cluster .pgdata ,MAXPGPATH );
503
+ canonicalize_path (new_cluster_pgdata );
504
+
505
+ /* Some people put the new data directory inside the old one. */
506
+ if (path_is_prefix_of_path (old_cluster_pgdata ,new_cluster_pgdata ))
507
+ {
508
+ pg_log (PG_WARNING ,
509
+ "\nWARNING: new data directory should not be inside the old data directory, e.g. %s\n" ,old_cluster_pgdata );
510
+
511
+ /* Unlink file in case it is left over from a previous run. */
512
+ unlink (* deletion_script_file_name );
513
+ pg_free (* deletion_script_file_name );
514
+ * deletion_script_file_name = NULL ;
515
+ return ;
516
+ }
517
+
498
518
/*
499
519
* Some users (oddly) create tablespaces inside the cluster data
500
520
* directory. We can't create a proper old cluster delete script in that
501
521
* case.
502
522
*/
503
- strlcpy (old_cluster_pgdata ,old_cluster .pgdata ,MAXPGPATH );
504
- canonicalize_path (old_cluster_pgdata );
505
523
for (tblnum = 0 ;tblnum < os_info .num_old_tablespaces ;tblnum ++ )
506
524
{
507
525
char old_tablespace_dir [MAXPGPATH ];