pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Justin Pryzby <pryzby@telsasoft.com>
To: pgsql-hackers@postgresql.org
Subject: Re: pg_upgrade: fail early if a tablespace dir already exists for new cluster version
Date: Fri, 25 Sep 2020 15:47:49 -0500
Message-ID: <20200925204749.GW23631@telsasoft.com> (raw)
In-Reply-To: <20200925005531.GJ23631@telsasoft.com>
References: <20200925005531.GJ23631@telsasoft.com>

Added at
https://commitfest.postgresql.org/30/2739/

Attachments:

v2-0001-pg_upgrade-check-to-avoid-tablespace-failure-mode.patch (text/x-diff, 2.5K) download From 831246aa6d6837b2b0da7c96ad2f44ffd6cd3951 Mon Sep 17 00:00:00 2001 From: Justin Pryzby <pryzbyj@telsasoft.com> Date: Thu, 24 Sep 2020 19:49:40 -0500 Subject: [PATCH v2] pg_upgrade --check to avoid tablespace failure mode --- src/bin/pg_upgrade/check.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 2f7aa632c5..154e3d249e 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -13,6 +13,7 @@ #include "fe_utils/string_utils.h" #include "mb/pg_wchar.h" #include "pg_upgrade.h" +#include "common/relpath.h" static void check_new_cluster_is_empty(void); static void check_databases_are_compatible(void); @@ -27,6 +28,7 @@ static void check_for_tables_with_oids(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_pg_role_prefix(ClusterInfo *cluster); +static void check_for_existing_tablespace_dirs(ClusterInfo *new_cluster); static char *get_canonical_locale_name(int category, const char *locale); @@ -187,6 +189,8 @@ check_new_cluster(void) check_is_install_user(&new_cluster); check_for_prepared_transactions(&new_cluster); + + check_for_existing_tablespace_dirs(&new_cluster); } @@ -542,6 +546,39 @@ create_script_for_cluster_analyze(char **analyze_script_file_name) } +/* + * Check that tablespace dirs do not already exist for new cluster version. + * If they did, it'd cause an error while restoring global objects. + * This allows failing earlier rather than only after dumping schema. + * + * Note, v8.4 has no tablespace_suffix, which is fine so long as the version we + * being upgraded *to* has a suffix. + */ +static void +check_for_existing_tablespace_dirs(ClusterInfo *new_cluster) +{ + char old_tablespace_dir[MAXPGPATH]; + + prep_status("Checking for pre-existing tablespace directories"); + + for (int tblnum = 0; tblnum < os_info.num_old_tablespaces; tblnum++) + { + struct stat statbuf; + snprintf(old_tablespace_dir, MAXPGPATH, "%s%s", + os_info.old_tablespaces[tblnum], + new_cluster->tablespace_suffix); + + canonicalize_path(old_tablespace_dir); + + // XXX: lstat ? + if (stat(old_tablespace_dir, &statbuf) == 0 || errno != ENOENT) + pg_fatal("tablespace directory already exists for new cluster version: \"%s\"\n", + old_tablespace_dir); + } + + check_ok(); +} + /* * create_script_for_old_cluster_deletion() * -- 2.17.0

view thread (13+ messages)  latest in thread

Message-ID: <20200925204749.GW23631@telsasoft.com>
Permalink:  ../20200925204749.GW23631@telsasoft.com/
Also on:    postgresql.org/message-id/20200925204749.GW23631@telsasoft.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: pryzby@telsasoft.com
  Subject: Re: pg_upgrade: fail early if a tablespace dir already exists for new cluster version
  In-Reply-To: <20200925204749.GW23631@telsasoft.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox