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 1jJ3t4-0002ji-LE for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2020 23:32:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJ3t3-0004lE-1x for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2020 23:32:09 +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 1jJ3t1-0004l6-Cc for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2020 23:32:08 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJ3sy-0002FT-2V for pgsql-hackers@postgresql.org; Mon, 30 Mar 2020 23:32:06 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id F02C6350; Mon, 30 Mar 2020 19:32:01 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Mon, 30 Mar 2020 19:32:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm1; bh=Fiu4F3E/l1otmBILzX1jmDnQuEb 42otzkbPskUZLDjQ=; b=WUVjqgIxOAkdMAqTrcSVJet37hULNEmXJ8Y2Gxsvgod cSuOe9tNwR6dMq+sSyX5F8aXritr+QIjlgywU9mZ04M73mrzuu4N1laGIl7J9liv 6ywjtl+CjuFP+eAcR+fRKAARKARJh8b5DCISDp7IqWA7Bf+pXbaSYrdZY8rCy9rA HiW7s8XXDb+cF3XM1hOmdcrvcuqSsbV9UWP6EHYPw7h9SKONvysQVX8UjNVq398Y Qe4zLFxLizvX8EgJF7Dj61MbM2Ng8bnCouHC9Zjfpq9USFjc3O4DVlcxm/e0YENJ sW1qe63iSpinfgZ15YqBEzXfjea0yCGUZm6TbbKNQvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=Fiu4F3 E/l1otmBILzX1jmDnQuEb42otzkbPskUZLDjQ=; b=fq6ds7ThY9v0UoKdVrIPRh IM9R8MSmiKDnLbGSjM87X9f9rIkHekLv8ePUMJe4qvJAA/dcBcL1UJW/Hmx5wWCH IACmAMvH5wXubuXjOQfhineWPI42drAkGM3JKTsxAOl+bAj7sBfXZ+Nx1cF2mU+d il4xIAHU7SLJmgHt/fCVr/oVhoTfV4FbuSQECHuHjADfz7N8pH1M5PBUtwqGSy3D BhQDgr46/4Jjhw8pkTYhBG2wOD+SzbOn05MBTVAT7Po6SOXmsDZuilKEl+GmyDMC fGLFTar2g+cEF9++IEwRCDc8o2nbNIwp6HInFkO+AEugMqyI4oBhhosmUi9aRhrA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudeiiedgvddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkfhggtggujgesthdtre dttddtvdenucfhrhhomheptehnughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghn rghrrgiivghlrdguvgeqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenuc fkphepieejrdduiedtrddvudejrddvhedtnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Received: from intern.anarazel.de (c-67-160-217-250.hsd1.ca.comcast.net [67.160.217.250]) by mail.messagingengine.com (Postfix) with ESMTPA id 2FD00306CA80; Mon, 30 Mar 2020 19:32:01 -0400 (EDT) Date: Mon, 30 Mar 2020 16:31:59 -0700 From: Andres Freund To: Kyotaro Horiguchi Cc: tejeswarm@hotmail.com, pgsql-hackers@postgresql.org, hexexpert@comcast.net Subject: Re: Corruption during WAL replay Message-ID: <20200330233159.af74fwkcod6y7u7k@alap3.anarazel.de> References: <20200324.181812.758439179869796321.horikyota.ntt@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200324.181812.758439179869796321.horikyota.ntt@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On 2020-03-24 18:18:12 +0900, Kyotaro Horiguchi wrote: > At Mon, 23 Mar 2020 20:56:59 +0000, Teja Mupparti wrote in > > The original bug reporting-email and the relevant discussion is here > ... > > The crux of the fix is, in the current code, engine drops the buffer and then truncates the file, but a crash before the truncate and after the buffer-drop is causing the corruption. Patch reverses the order i.e. truncate the file and drop the buffer later. > > BufferAlloc doesn't wait for the BM_IO_IN_PROGRESS for a valid buffer. I don't think that's true. For any of this to be relevant the buffer has to be dirty. In which case BufferAlloc() has to call FlushBuffer(). Which in turn does a WaitIO() if BM_IO_IN_PROGRESS is set. What path are you thinking of? Or alternatively, what am I missing? > I'm not sure it's acceptable to remember all to-be-deleted buffers > while truncation. I don't see a real problem with it. Nor really a good alternative. Note that for autovacuum truncations we'll only truncate a limited number of buffers at once, and for most relation truncations we don't enter this path (since we create a new relfilenode instead). > > + /*START_CRIT_SECTION();*/ > Is this a point of argument? It is not needed if we choose the > strategy (c) in [1], since the protocol is aiming to allow server to > continue running after truncation failure. > > [1]: https://www.postgresql.org/message-id/20191207001232.klidxnm756wqxvwx%40alap3.anarazel.de I think it's entirely broken to continue running after a truncation failure. We obviously have to first WAL log the truncation (since otherwise we can crash just after doing the truncation). But we cannot just continue running after WAL logging, but not performing the associated action: The most obvious reason is that otherwise a replica will execute the trunction, but the primary will not. The whole justification for that behaviour "It would turn a usually harmless failure to truncate, that might spell trouble at WAL replay, into a certain PANIC." was always dubious (since on-disk and in-memory state now can diverge), but it's clearly wrong once replication had entered the picture. There's just no alternative to a critical section here. If we are really concerned with truncation failing - I don't know why we would be, we accept that we have to be able to modify files etc to stay up - we can add a pre-check ensuring that permissions are set up appropriately to allow us to truncate. Greetings, Andres Freund