Skip to content

Commit 59cfff6

Browse files
committed
pg_upgrade: generate check error for left-over new tablespace
Previously, if pg_upgrade failed, and the user recreated the cluster but did not remove the new cluster tablespace directory, a later pg_upgrade would fail since the new tablespace directory would already exists. This adds error reporting for this during check. Reported-by: Justin Pryzby Discussion: https://postgr.es/m/20200925005531.GJ23631@telsasoft.com Backpatch-through: 9.5
1 parent ae3e75a commit 59cfff6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/bin/pg_upgrade/check.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static void check_for_tables_with_oids(ClusterInfo *cluster);
2626
static void check_for_reg_data_type_usage(ClusterInfo *cluster);
2727
static void check_for_jsonb_9_4_usage(ClusterInfo *cluster);
2828
static void check_for_pg_role_prefix(ClusterInfo *cluster);
29+
static void check_for_new_tablespace_dir(ClusterInfo *new_cluster);
2930
static char *get_canonical_locale_name(int category, const char *locale);
3031

3132

@@ -179,6 +180,8 @@ check_new_cluster(void)
179180
check_is_install_user(&new_cluster);
180181

181182
check_for_prepared_transactions(&new_cluster);
183+
184+
check_for_new_tablespace_dir(&new_cluster);
182185
}
183186

184187

@@ -519,6 +522,43 @@ create_script_for_cluster_analyze(char **analyze_script_file_name)
519522
}
520523

521524

525+
/*
526+
* A previous run of pg_upgrade might have failed and the new cluster
527+
* directory recreated, but they might have forgotten to remove
528+
* the new cluster's tablespace directories. Therefore, check that
529+
* new cluster tablespace directories do not already exist. If
530+
* they do, it would cause an error while restoring global objects.
531+
* This allows the failure to be detected at check time, rather than
532+
* during schema restore.
533+
*
534+
* Note, v8.4 has no tablespace_suffix, which is fine so long as the
535+
* version being upgraded *to* has a suffix, since it's not allowed
536+
* to pg_upgrade from a version to the same version if tablespaces are
537+
* in use.
538+
*/
539+
static void
540+
check_for_new_tablespace_dir(ClusterInfo *new_cluster)
541+
{
542+
char new_tablespace_dir[MAXPGPATH];
543+
544+
prep_status("Checking for new cluster tablespace directories");
545+
546+
for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++)
547+
{
548+
struct stat statbuf;
549+
550+
snprintf(new_tablespace_dir, MAXPGPATH, "%s%s",
551+
os_info.old_tablespaces[tblnum],
552+
new_cluster->tablespace_suffix);
553+
554+
if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT)
555+
pg_fatal("new cluster tablespace directory already exists: \"%s\"\n",
556+
new_tablespace_dir);
557+
}
558+
559+
check_ok();
560+
}
561+
522562
/*
523563
* create_script_for_old_cluster_deletion()
524564
*

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