diff options
author | Bruce Momjian <bruce@momjian.us> | 2020-10-15 19:33:36 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2020-10-15 19:33:36 -0400 |
commit | d9ae2297bf0f668467780bd80815a4a2d30e822c (patch) | |
tree | 2064be28cf8a8765716b5c53250a710d3508e8a1 /src | |
parent | 43ca5e07d1bb160deeddaba8456d462a460dc4f8 (diff) | |
download | postgresql-d9ae2297bf0f668467780bd80815a4a2d30e822c.tar.gz postgresql-d9ae2297bf0f668467780bd80815a4a2d30e822c.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pg_upgrade/check.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index c8ad2507640..e0a9d37c13a 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -24,6 +24,7 @@ static void check_for_prepared_transactions(ClusterInfo *cluster); static void check_for_isn_and_int8_passing_mismatch(ClusterInfo *cluster); static void check_for_reg_data_type_usage(ClusterInfo *cluster); static void check_for_jsonb_9_4_usage(ClusterInfo *cluster); +static void check_for_new_tablespace_dir(ClusterInfo *new_cluster); static void get_bin_version(ClusterInfo *cluster); static char *get_canonical_locale_name(int category, const char *locale); @@ -138,6 +139,8 @@ check_new_cluster(void) check_is_install_user(&new_cluster); check_for_prepared_transactions(&new_cluster); + + check_for_new_tablespace_dir(&new_cluster); } @@ -477,6 +480,43 @@ create_script_for_cluster_analyze(char **analyze_script_file_name) /* + * A previous run of pg_upgrade might have failed and the new cluster + * directory recreated, but they might have forgotten to remove + * the new cluster's tablespace directories. Therefore, check that + * new cluster tablespace directories do not already exist. If + * they do, it would cause an error while restoring global objects. + * This allows the failure to be detected at check time, rather than + * during schema restore. + * + * Note, v8.4 has no tablespace_suffix, which is fine so long as the + * version being upgraded *to* has a suffix, since it's not allowed + * to pg_upgrade from a version to the same version if tablespaces are + * in use. + */ +static void +check_for_new_tablespace_dir(ClusterInfo *new_cluster) +{ + char new_tablespace_dir[MAXPGPATH]; + + prep_status("Checking for new cluster tablespace directories"); + + for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++) + { + struct stat statbuf; + + snprintf(new_tablespace_dir, MAXPGPATH, "%s%s", + os_info.old_tablespaces[tblnum], + new_cluster->tablespace_suffix); + + if (stat(new_tablespace_dir, &statbuf) == 0 || errno != ENOENT) + pg_fatal("new cluster tablespace directory already exists: \"%s\"\n", + new_tablespace_dir); + } + + check_ok(); +} + +/* * create_script_for_old_cluster_deletion() * * This is particularly useful for tablespace deletion. |