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 1l4i0j-00063i-Jx for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jan 2021 10:25:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l4i0i-00081S-CS for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Jan 2021 10:25:16 +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 1l4i0i-00081J-2x for pgsql-hackers@lists.postgresql.org; Wed, 27 Jan 2021 10:25:16 +0000 Received: from mail1.dalibo.net ([212.83.143.11] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4i0g-0007Pe-34 for pgsql-hackers@lists.postgresql.org; Wed, 27 Jan 2021 10:25:15 +0000 Received: from dalibo.com (unknown [82.67.164.42]) by mail.dalibo.com (Postfix) with ESMTPSA id 844D02043A; Wed, 27 Jan 2021 11:25:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1611743112; bh=3p9FhYxr/g9PTaoUNpGyy/E3vHvlX+lgUrzx17r8G7M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ilD5+NsoAGWznLN2Q0/9+fhtUv3orVi25k78mVvtFBvsmsfhX4UOF84J4pZCAVTst vgzLq2IloYcCEjR25fjvpqIdM7bjou2Q1LBU97aHTbJyn1wfRGBqHD66PNk7ZWkxIZ sLyh+74iCpCy2GcSIy07GLGo/D3AxedrzqPmbVog= Date: Wed, 27 Jan 2021 11:25:11 +0100 From: Denis Laxalde To: Andres Freund Cc: pgsql-hackers@lists.postgresql.org Subject: Re: [PATCH] Disable bgworkers during servers start in pg_upgrade Message-ID: <20210127102511.tvhu2wmrxoz3tle4@dalibo.com> References: <20210121152357.s6eflhqyh4g5e6dv@dalibo.com> <20210124003611.lkyxhd2mpdmv5xzh@alap3.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="y3a77itoykn4x2sb" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210124003611.lkyxhd2mpdmv5xzh@alap3.anarazel.de> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --y3a77itoykn4x2sb Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Hi, Andres Freund a écrit : > On 2021-01-21 16:23:58 +0100, Denis Laxalde wrote: > > We found an issue in pg_upgrade on a cluster with a third-party > > background worker. The upgrade goes fine, but the new cluster is then in > > an inconsistent state. The background worker comes from the PoWA > > extension but the issue does not appear to related to this particular > > code. > > Well, it does imply that that backgrounder did something, as the pure > existence of a bgworker shouldn't affect > > anything. Presumably the issue is that the bgworker actually does > transactional writes, which causes problems because the xids / > multixacts from early during pg_upgrade won't actually be valid after we > do pg_resetxlog etc. > > > > As a solution, it seems that, for similar reasons that we restrict > > socket access to prevent accidental connections (from commit > > f763b77193), we should also prevent background workers to start at this > > step. > > I think that'd have quite the potential for negative impact - imagine > extensions that refuse to be loaded outside of shared_preload_libraries > (e.g. because they need to allocate shared memory) but that are required > during the course of pg_upgrade (e.g. because it's a tableam, a PL or > such). Those libraries will then tried to be loaded during the upgrade > (due to the _PG_init() hook being called when functions from the > extension are needed, e.g. the tableam or PL handler). > > Nor is it clear to me that the only way this would be problematic is > with shared_preload_libraries. A library in local_preload_libraries, or > a demand loaded library can trigger bgworkers (or database writes in > some other form) as well. Thank you for those insights! > I wonder if we could > > a) set default_transaction_read_only to true, and explicitly change it > in the sessions that need that. > b) when in binary upgrade mode / -b, error out on all wal writes in > sessions that don't explicitly set a session-level GUC to allow > writes. Solution "a" appears to be enough to solve the problem described in my initial email. See attached patch implementing this. Cheers, Denis --y3a77itoykn4x2sb Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Set-default-transactions-to-read-only-at-servers-sta.patch" From d8b74f9220775736917b7fc08bbe397d7e2eedcd Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Wed, 20 Jan 2021 17:25:58 +0100 Subject: [PATCH] Set default transactions to read-only at servers start in pg_upgrade In essence, this is for a similar reason that we use a restricted socket access from f763b77193b04eba03a1f4ce46df34dc0348419e because background workers may produce undesired activities during the upgrade. Author: Denis Laxalde Co-authored-by: Jehan-Guillaume de Rorthais --- src/bin/pg_upgrade/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c index 31b1425202..b17f348a5b 100644 --- a/src/bin/pg_upgrade/server.c +++ b/src/bin/pg_upgrade/server.c @@ -244,7 +244,7 @@ start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error) * vacuumdb --freeze actually freezes the tuples. */ snprintf(cmd, sizeof(cmd), - "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" -o \"-p %d%s%s %s%s\" start", + "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" -o \"-p %d%s%s %s%s -c default_transaction_read_only=on\" start", cluster->bindir, SERVER_LOG_FILE, cluster->pgconfig, cluster->port, (cluster->controldata.cat_ver >= BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? " -b" : -- 2.20.1 --y3a77itoykn4x2sb--