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 1mwEwT-0000wd-Kk for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Dec 2021 02:50:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mwEwS-0001Pj-A8 for pgsql-hackers@arkaria.postgresql.org; Sun, 12 Dec 2021 02:50:24 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mwEwR-0001Pa-Tz for pgsql-hackers@lists.postgresql.org; Sun, 12 Dec 2021 02:50:24 +0000 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mwEwO-0004ZL-VS for pgsql-hackers@lists.postgresql.org; Sun, 12 Dec 2021 02:50:22 +0000 Received: by mail-il1-x129.google.com with SMTP id l5so11981145ilv.7 for ; Sat, 11 Dec 2021 18:50:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=mZcN7LKJtobf1cdNyqV9BR4TkKQ4f34s5enAm2S1bfo=; b=5dCeu6utFe/M361asGzGFJuggjBAKcm6JsLqZyFxibYQlR2uDD9EFbn7ArztRyIUmQ jGTNjOrYVWVD5w3Rvde9WlafvCt/MA4RZ4XKiFRKyO4OskIfffr+CsSdm8GewNKkCygx rjp5bZ6G6e208pZUU/TlMKyzgDQT+DeL3CWWYnoBKY7hgzOckCKRt2J14bZdwAEFKSQx qOkZhT5c1mCK3R+rWyYZy6zKlf77Kj2J90XMjcp61A4SjKZl0xbDsNUjlDuHyTPNiwxt syQaFhAUXerbGmhd4mTBCabcUWHZtVQCxhBggc9G0rjvR9PuY2RrDiELBUTIDf9IEHZU 6yOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=mZcN7LKJtobf1cdNyqV9BR4TkKQ4f34s5enAm2S1bfo=; b=ATp5by+LlWlBUuZlbEHVp8BNBX5KVJDSm8C1ecmtR3lTP4nXO9LNN06BVf1/AVWekf yaNw2Um3wqBxegFZVMuOpb6WF4/GyE2XzNoWywHYd05lFRFK6LABIk5DxI68mPKVEXV8 co1j/vm9AnqeOJxINtttztym+wP/kEFfL2svK2jp91eWjt+0XLXSVYOypZjXqJ4d6Hc1 eMNe66NbofawckCiWjIFlKPyto4KEl7/DxGzSxWxR0/0rpLuJP8MyYLdzL0BNSM9pJ2X YqbnL+DUaxzQQNKi3t18IjOmRuDJ61TbE+l/AOYjpWaEzkbDbpE8O3SBX0WyNOTrpxlb vO3Q== X-Gm-Message-State: AOAM532rbUqMqz238kdprxhLVfvVPQQyhH5hfRs7UeS0l4rpGmbxXr/P a9RbzNe9l5C6/STga0cE4J5Pn0Z1rZbEfQ== X-Google-Smtp-Source: ABdhPJwhZ1j+E93+l60jGzDI5pFKD581yc9uubEMrCsDx5wF2r5t741hjpJE5t+FpY0uOVPndvwBwg== X-Received: by 2002:a05:6e02:170b:: with SMTP id u11mr26267890ill.33.1639277419690; Sat, 11 Dec 2021 18:50:19 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id e2sm5260786ili.45.2021.12.11.18.50.18 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 11 Dec 2021 18:50:18 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id DCF218009E1; Sat, 11 Dec 2021 20:50:17 -0600 (CST) Date: Sat, 11 Dec 2021 20:50:17 -0600 From: Justin Pryzby To: Bruce Momjian Cc: pgsql-hackers@lists.postgresql.org Subject: pg_upgrade should truncate/remove its logs before running Message-ID: <20211212025017.GN17618@telsasoft.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="s33SFO/vI16wUVFN" Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --s33SFO/vI16wUVFN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I have seen this numerous times but had not dug into it, until now. If pg_upgrade fails and is re-run, it appends to its logfiles, which is confusing since, if it fails again, it then looks like the original error recurred and wasn't fixed. The "append" behavior dates back to 717f6d608. I think it should either truncate the logfiles, or error early if any of the files exist. Or it could put all its output files into a newly-created subdirectory. Or this message could be output to the per-db logfiles, and not just the static ones: | "pg_upgrade run on %s". For the per-db logfiels with OIDs in their name, changing open() from "append" mode to truncate mode doesn't work, since they're written to in parallel. They have to be removed/truncated in advance. This is one possible fix. You can test its effect by deliberately breaking one of the calls to exec_progs(), like this. - "\"%s/pg_restore\" %s %s --exit-on-error --verbose " + "\"%s/pg_restore\" %s %s --exit-on-error --verboose " --s33SFO/vI16wUVFN Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-pg_upgrade-fail-if-logfiles-exist.patch" From 1b1a86df1febce5f55257c625b81e1499f6bfce3 Mon Sep 17 00:00:00 2001 From: Justin Pryzby Date: Sat, 11 Dec 2021 19:19:50 -0600 Subject: [PATCH] pg_upgrade: fail if logfiles exist.. Rather than appending to them, which is confusing since old errors are still present. --- src/bin/pg_upgrade/check.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/bin/pg_upgrade/check.c b/src/bin/pg_upgrade/check.c index 1106912863..92060e5abe 100644 --- a/src/bin/pg_upgrade/check.c +++ b/src/bin/pg_upgrade/check.c @@ -18,6 +18,7 @@ static void check_new_cluster_is_empty(void); static void check_databases_are_compatible(void); static void check_locale_and_encoding(DbInfo *olddb, DbInfo *newdb); static bool equivalent_locale(int category, const char *loca, const char *locb); +static void remove_logfiles(void); static void check_is_install_user(ClusterInfo *cluster); static void check_proper_datallowconn(ClusterInfo *cluster); static void check_for_prepared_transactions(ClusterInfo *cluster); @@ -168,7 +169,10 @@ check_and_dump_old_cluster(bool live_check) * the old server is running. */ if (!user_opts.check) + { + remove_logfiles(); generate_old_dump(); + } if (!live_check) stop_postmaster(false); @@ -635,6 +639,24 @@ create_script_for_old_cluster_deletion(char **deletion_script_file_name) check_ok(); } +/* + * Remove any per-db logfiles left around by a previous upgrade attempt. + * The statically-named logfiles aren't touched, since there are clear + * separators added by parseCommandLine(). + */ +static void +remove_logfiles(void) +{ + int dbnum; + for (dbnum = 0; dbnum < old_cluster.dbarr.ndbs; dbnum++) + { + char log_file_name[MAXPGPATH]; + DbInfo *old_db = &old_cluster.dbarr.dbs[dbnum]; + snprintf(log_file_name, sizeof(log_file_name), DB_DUMP_LOG_FILE_MASK, old_db->db_oid); + if (unlink(log_file_name) < 0 && errno != ENOENT) + pg_log(PG_FATAL, "failed to remove pre-existing logfile: %s: %m", log_file_name); + } +} /* * check_is_install_user() -- 2.17.0 --s33SFO/vI16wUVFN--