Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3386f34

Browse filesBrowse 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 48e6c94 commit 3386f34
Copy full SHA for 3386f34

File tree

Expand file treeCollapse file tree

1 file changed

+24
-6
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+24
-6
lines changed

‎src/bin/pg_upgrade/check.c

Copy file name to clipboardExpand all lines: src/bin/pg_upgrade/check.c
+24-6Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,10 @@ output_completion_banner(char *analyze_script_file_name,
195195
deletion_script_file_name);
196196
else
197197
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");
201202
}
202203

203204

@@ -496,18 +497,35 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
496497
{
497498
FILE *script = NULL;
498499
int tblnum;
499-
char old_cluster_pgdata[MAXPGPATH];
500+
char old_cluster_pgdata[MAXPGPATH], new_cluster_pgdata[MAXPGPATH];
500501

501502
*deletion_script_file_name = psprintf("%sdelete_old_cluster.%s",
502503
SCRIPT_PREFIX, SCRIPT_EXT);
503504

505+
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
506+
canonicalize_path(old_cluster_pgdata);
507+
508+
strlcpy(new_cluster_pgdata, new_cluster.pgdata, MAXPGPATH);
509+
canonicalize_path(new_cluster_pgdata);
510+
511+
/* Some people put the new data directory inside the old one. */
512+
if (path_is_prefix_of_path(old_cluster_pgdata, new_cluster_pgdata))
513+
{
514+
pg_log(PG_WARNING,
515+
"\nWARNING: new data directory should not be inside the old data directory, e.g. %s\n", old_cluster_pgdata);
516+
517+
/* Unlink file in case it is left over from a previous run. */
518+
unlink(*deletion_script_file_name);
519+
pg_free(*deletion_script_file_name);
520+
*deletion_script_file_name = NULL;
521+
return;
522+
}
523+
504524
/*
505525
* Some users (oddly) create tablespaces inside the cluster data
506526
* directory. We can't create a proper old cluster delete script in that
507527
* case.
508528
*/
509-
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
510-
canonicalize_path(old_cluster_pgdata);
511529
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
512530
{
513531
char old_tablespace_dir[MAXPGPATH];

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.