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 1pNF6i-0007db-3t for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Feb 2023 15:33:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pNF6g-0004FN-Dc for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Feb 2023 15:33:06 +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 1pNF6f-0004Ee-1d for pgsql-bugs@lists.postgresql.org; Wed, 01 Feb 2023 15:33:06 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pNF6a-0000W8-SO for pgsql-bugs@lists.postgresql.org; Wed, 01 Feb 2023 15:33:04 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 681D932009AB; Wed, 1 Feb 2023 10:32:57 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Wed, 01 Feb 2023 10:32:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1675265577; x=1675351977; bh=fpnF23MQir paMoJ/cKak3RZ/RDr0UVgO7czZhPpnxCc=; b=IkRNxwMyV8YSSBZxzC8AcIfa0w cOA9AsG5Ez6VD1YsO8zHIsbRVM+2FhCT3lvxYYy7DHvmTyFookYzn269MLojgMPB 9Ss2GRK1+sGrm6fJ4o3hcWZ1zTy3fTjGFDBfLULB4poSHKL63xFuwMKe6fkS8X6M 6Ul7qcmg144jNfvK4lEIty0wjW1ExHooY/R0P7Tb5K8JRSYhL1IU8NhQ6Q59kUS5 Lhub91XYeq3W4PTSRAHNV5pL5iLg6ptJFVswdi4b6i7GUfvfmr7G9HAkZuXURl9g be/4rdpxnsyQkUMJpNYY3Of3MJPeMlYffCeK8CIlg23pn+SsZ04eBaKjE9CQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1675265577; x=1675351977; bh=fpnF23MQirpaMoJ/cKak3RZ/RDr0 UVgO7czZhPpnxCc=; b=Vlu1Yzeo1Ti30a1a6NIaT6BCobxDKpnfM/417x/ySkQ4 LF5XMWLIouQXDbMF0z1Q1vCZMZYuIcfQxigOqncUqb0fVyHMcYsPv3BDzacG1LqY kYacb7eD15WdWtoZcQ21l7XhIoZb1L9dCunFAoq/SSyOkssPLPau2jMzYiHadBHv P4Cv4qLtt7PuTbNRxDUMn5WgKHN2O445hdNJDKIMWdfj0Ren7idQAB8BdcV7bREj nMcdk11wzAO6e5eEImVCNExVvQRauJ74/3SwXnTUUDS67R30lE/i/Y2g1LEuhuPL V6cvdMy5uvCsI+D9O/Vpms4QEklb4oW+L9KY29iIwA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudefiedgjeekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepvdfffeevhfetveffgeeiteefhfdtvdffjeevhfeuteegleduheetvedu ieettddunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 1 Feb 2023 10:32:56 -0500 (EST) Date: Wed, 1 Feb 2023 07:32:52 -0800 From: Andres Freund To: Kyotaro Horiguchi , Thomas Munro Cc: zxwsbg12138@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17744: Fail Assert while recoverying from pg_basebackup Message-ID: <20230201153252.l6kcfum7trdovw2b@alap3.anarazel.de> References: <17744-2c95e2b7783d7232@postgresql.org> <20230113.183605.282317833423860381.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230113.183605.282317833423860381.horikyota.ntt@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 2023-01-13 18:36:05 +0900, Kyotaro Horiguchi wrote: > At Tue, 10 Jan 2023 07:45:45 +0000, PG Bug reporting form wrote in > > #2 0x0000000000b378e9 in ExceptionalCondition ( > > conditionName=0xd13697 "TransactionIdIsValid(initial)", > > errorType=0xd12df4 "FailedAssertion", fileName=0xd12de8 "procarray.c", > > > > lineNumber=1750) at assert.c:69 > > #3 0x0000000000962195 in ComputeXidHorizons (h=0x7ffe93de25e0) > > at procarray.c:1750 > > #4 0x00000000009628a3 in GetOldestTransactionIdConsideredRunning () > > at procarray.c:2050 > > #5 0x00000000005972bf in CreateRestartPoint (flags=256) at xlog.c:7153 > > #6 0x00000000008cae37 in CheckpointerMain () at checkpointer.c:464 > > The function requires a valid value in > ShmemVariableCache->latestCompleteXid. But it is not initialized and > maintained in this case. The attached quick hack seems working, but > of course more decent fix is needed. I might be missing something, but I suspect the problem here is that we shouldn't have been creating a restart point. Afaict, the setup instructions provided don't configure a recovery.signal, so we'll just perform crash recovery. And I don't think it'd ever make sense to create a restart point during crash recovery? Except that in this case, it's not pure crash recovery, it's restoring from a backup label. Due to which it actually might make sense to create restart points? If you're doing PITR or such you don't really gain anything by doing checkpoints until you've reached consistency, unless you want to optimize for the case that you might need to start/stop the instance multiple times? So maybe it's the right thing to create restart points? Really not sure. If we do want to do restartpoints, we definitely shouldn't try to TruncateSUBTRANS() in the crash-recovery-like-restartpoint case, we've not even done StartupSUBTRANS(), because that's guarded by ArchiveRecoveryRequested. The most obvious (but wrong!), fix would be to change if (EnableHotStandby) TruncateSUBTRANS(GetOldestTransactionIdConsideredRunning()); to if (standbyState != STANDBY_DISABLED) TruncateSUBTRANS(GetOldestTransactionIdConsideredRunning()); except that doesn't work, because we don't have working access to standbyState. Nor the other relevant variables. Gah. We've really made a hash out of the state management for xlog.c. ArchiveRecoveryRequested, InArchiveRecovery, StandbyModeRequested, StandbyMode, EnableHotStandby, LocalHotStandbyActive, ... :(. We use InArchiveRecovery = true, even if there's no archiving involved. Afaict ArchiveRecoveryRequested=false, InArchiveRecovery=true isn't really something the comments around the variables foresee. Greetings, Andres Freund