Skip to content

Commit 4765dd7

Browse files
committed
pg_upgrade: conditionally create cluster delete script
If users create tablespaces inside the old cluster directory, it is impossible for the delete script to delete _only_ the old cluster files, so don't create a script in that case, and issue a message to the user.
1 parent 7420526 commit 4765dd7

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

contrib/pg_upgrade/check.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,17 @@ output_completion_banner(char *analyze_script_file_name,
246246
"by pg_upgrade so, once you start the new server, consider running:\n"
247247
" %s\n\n", analyze_script_file_name);
248248

249-
pg_log(PG_REPORT,
250-
"Running this script will delete the old cluster's data files:\n"
251-
" %s\n",
252-
deletion_script_file_name);
249+
250+
if (deletion_script_file_name)
251+
pg_log(PG_REPORT,
252+
"Running this script will delete the old cluster's data files:\n"
253+
" %s\n",
254+
deletion_script_file_name);
255+
else
256+
pg_log(PG_REPORT,
257+
"Could not create a script to delete the old cluster's data\n"
258+
"files because user-defined tablespaces exist in the old cluster\n"
259+
"directory. The old cluster's contents must be deleted manually.\n");
253260
}
254261

255262

@@ -584,14 +591,38 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name)
584591
{
585592
FILE *script = NULL;
586593
int tblnum;
594+
char old_cluster_pgdata[MAXPGPATH];
587595

588596
*deletion_script_file_name = pg_malloc(MAXPGPATH);
589597

590-
prep_status("Creating script to delete old cluster");
591-
592598
snprintf(*deletion_script_file_name, MAXPGPATH, "delete_old_cluster.%s",
593599
SCRIPT_EXT);
594600

601+
/*
602+
* Some users (oddly) create tablespaces inside the cluster data
603+
* directory. We can't create a proper old cluster delete script
604+
* in that case.
605+
*/
606+
strlcpy(old_cluster_pgdata, old_cluster.pgdata, MAXPGPATH);
607+
canonicalize_path(old_cluster_pgdata);
608+
for (tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
609+
{
610+
char old_tablespace_dir[MAXPGPATH];
611+
612+
strlcpy(old_tablespace_dir, os_info.old_tablespaces[tblnum], MAXPGPATH);
613+
canonicalize_path(old_tablespace_dir);
614+
if (path_is_prefix_of_path(old_cluster_pgdata, old_tablespace_dir))
615+
{
616+
/* Unlink file in case it is left over from a previous run. */
617+
unlink(*deletion_script_file_name);
618+
pg_free(*deletion_script_file_name);
619+
*deletion_script_file_name = NULL;
620+
return;
621+
}
622+
}
623+
624+
prep_status("Creating script to delete old cluster");
625+
595626
if ((script = fopen_priv(*deletion_script_file_name, "w")) == NULL)
596627
pg_log(PG_FATAL, "Could not open file \"%s\": %s\n",
597628
*deletion_script_file_name, getErrorText(errno));

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