Skip to content

Commit bec4d0f

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 b754716 commit bec4d0f

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
@@ -263,9 +263,10 @@ output_completion_banner(char *analyze_script_file_name,
263263
deletion_script_file_name);
264264
else
265265
pg_log(PG_REPORT,
266-
"Could not create a script to delete the old cluster's data\n"
267-
"files because user-defined tablespaces exist in the old cluster\n"
268-
"directory. The old cluster's contents must be deleted manually.\n");
266+
"Could not create a script to delete the old cluster's data files\n"
267+
"because user-defined tablespaces or the new cluster's data directory\n"
268+
"exist in the old cluster directory. The old cluster's contents must\n"
269+
"be deleted manually.\n");
269270
}
270271

271272

@@ -656,17 +657,34 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
656657
{
657658
FILE *script = NULL;
658659
int tblnum;
659-
char old_cluster_pgdata[MAXPGPATH];
660+
char old_cluster_pgdata[MAXPGPATH], new_cluster_pgdata[MAXPGPATH];
660661

661662
*deletion_script_file_name = psprintf("delete_old_cluster.%s", SCRIPT_EXT);
662663

664+
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
665+
canonicalize_path(old_cluster_pgdata);
666+
667+
strlcpy(new_cluster_pgdata, new_cluster.pgdata, MAXPGPATH);
668+
canonicalize_path(new_cluster_pgdata);
669+
670+
/* Some people put the new data directory inside the old one. */
671+
if (path_is_prefix_of_path(old_cluster_pgdata, new_cluster_pgdata))
672+
{
673+
pg_log(PG_WARNING,
674+
"\nWARNING: new data directory should not be inside the old data directory, e.g. %s\n", old_cluster_pgdata);
675+
676+
/* Unlink file in case it is left over from a previous run. */
677+
unlink(*deletion_script_file_name);
678+
pg_free(*deletion_script_file_name);
679+
*deletion_script_file_name = NULL;
680+
return;
681+
}
682+
663683
/*
664684
* Some users (oddly) create tablespaces inside the cluster data
665685
* directory. We can't create a proper old cluster delete script in that
666686
* case.
667687
*/
668-
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
669-
canonicalize_path(old_cluster_pgdata);
670688
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
671689
{
672690
char old_tablespace_dir[MAXPGPATH];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy