Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLudK-0007OI-B6 for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2020 20:47:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kLudI-0006vd-0n for pgsql-hackers@arkaria.postgresql.org; Fri, 25 Sep 2020 20:47:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kLudH-0006vW-Pu for pgsql-hackers@lists.postgresql.org; Fri, 25 Sep 2020 20:47:55 +0000 Received: from mail-io1-xd44.google.com ([2607:f8b0:4864:20::d44]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kLudF-0003vH-07 for pgsql-hackers@postgresql.org; Fri, 25 Sep 2020 20:47:55 +0000 Received: by mail-io1-xd44.google.com with SMTP id z25so4362275iol.10 for ; Fri, 25 Sep 2020 13:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=sP9dsVdVik5RmGzGN3DOIiG5h0e5viUzCa30fSoXETo=; b=Z6xDHWs0SKJCv3Jn2RhFRTU/EaaV7ahncMihp7NnzBnVUZunYE7CEChnMP/5qCn0Fm 7d/FrHVyP/j5Ii3trk//1V8KWQKjCDQ2ZTZWDNVX511MA0oAoDEmOUqWxXeEP9plYDMx I/5nJuO18Fl5RN82XSeOH/fCAw5LL+0UIVIYcdNcYgYhy/axHyYGxqU83+zWgWAR3D7Z mp66IlfCKmal/cnQoqtIK8fmsJ76X4Z919kBdKbmmtmo9s0f52wNwMK8oRuhKsnkyPy3 6ey2URQiC7ouLxtWBUn0vRxODRcJmnP/XHdMW/G8oSBLyjwCSl5ds/4QlwfJZuSwFy8u Vk7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=sP9dsVdVik5RmGzGN3DOIiG5h0e5viUzCa30fSoXETo=; b=l5q9x8sW39eiAMTVfZdcYl+XHRkjIwy+K137fDBwjxoE8FIJvxRC51Z4Z1vz3jnKSk A7vZJh7AQgktfB/Ot3GTQDUELBER9MyO3teH3ALdu2IqbZu2EhhmwIrffLHPFcNj3GBA /Zb0X0XS4SOuENF50pR41lOqP2f3oxd/suYfAD4FwQwM9p2UEPLwJp0sY8tJH6uqm0/p Xv03aBjh/Dzb6ylC+C+xqobZp/RtgM8d1I7u4MGwW9iJGv1GEGYBqi+EYXuZycPs0QNc PS4K/0IynduIiyZeaiYL4Ym/Ss68VoRt5tAtmOxdOw4bfiELr+DXvxsfwu0/V+PPA/F5 MIsA== X-Gm-Message-State: AOAM531ddjQHz8bMXrpaiZY35zBJrpOTqEUmi3Jd4dxCNxx5OH7F4yfv 9jWf0Z4YBI13johJO9DGfw8C7LTRDz5brg== X-Google-Smtp-Source: ABdhPJydDfIL57759Nkjtpvkc6v+rpBV6o55VqEjAPURIrklNF5jD/1+X+gnNbhupwuNv4fb/VJSxQ== X-Received: by 2002:a5d:9842:: with SMTP id p2mr292885ios.113.1601066871230; Fri, 25 Sep 2020 13:47:51 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id a23sm1617585ioc.54.2020.09.25.13.47.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 25 Sep 2020 13:47:50 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 803CD801141; Fri, 25 Sep 2020 15:47:49 -0500 (CDT) Date: Fri, 25 Sep 2020 15:47:49 -0500 From: Justin Pryzby To: pgsql-hackers@postgresql.org Subject: Re: pg_upgrade: fail early if a tablespace dir already exists for new cluster version Message-ID: <20200925204749.GW23631@telsasoft.com> References: <20200925005531.GJ23631@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="+9faIjRurCDpBc7U" Content-Disposition: inline In-Reply-To: <20200925005531.GJ23631@telsasoft.com> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --+9faIjRurCDpBc7U Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Added at https://commitfest.postgresql.org/30/2739/ --+9faIjRurCDpBc7U Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-pg_upgrade-check-to-avoid-tablespace-failure-mode.patch" From 831246aa6d6837b2b0da7c96ad2f44ffd6cd3951 Mon Sep 17 00:00:00 2001 From: Justin Pryzby 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 --+9faIjRurCDpBc7U--