Skip to content

Commit bf26c4f

Browse files
committed
pg_upgrade: suppress creation of delete script
Suppress creation of the pg_upgrade delete script when the new data directory is inside the old data directory. Reported-by: IRC Backpatch-through: 9.3, where delete script tests were added
1 parent 9dfb5b9 commit bf26c4f

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

contrib/pg_upgrade/check.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,10 @@ output_completion_banner(char *analyze_script_file_name,
255255
deletion_script_file_name);
256256
else
257257
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");
261262
}
262263

263264

@@ -693,20 +694,37 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
693694
{
694695
FILE *script = NULL;
695696
int tblnum;
696-
char old_cluster_pgdata[MAXPGPATH];
697+
char old_cluster_pgdata[MAXPGPATH], new_cluster_pgdata[MAXPGPATH];
697698

698699
*deletion_script_file_name = pg_malloc(MAXPGPATH);
699700

700701
snprintf(*deletion_script_file_name, MAXPGPATH, "delete_old_cluster.%s",
701702
SCRIPT_EXT);
702703

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+
703723
/*
704724
* Some users (oddly) create tablespaces inside the cluster data
705725
* directory. We can't create a proper old cluster delete script in that
706726
* case.
707727
*/
708-
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
709-
canonicalize_path(old_cluster_pgdata);
710728
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
711729
{
712730
char old_tablespace_dir[MAXPGPATH];

0 commit comments

Comments
 (0)