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 1jOO7z-0006kC-SC for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Apr 2020 16:09:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jOO7y-0004FO-O5 for pgsql-bugs@arkaria.postgresql.org; Tue, 14 Apr 2020 16:09:34 +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 1jOO7y-0004FE-EC; Tue, 14 Apr 2020 16:09:34 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jOO7r-0000wX-2A; Tue, 14 Apr 2020 16:09:33 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id DCF412060D; Tue, 14 Apr 2020 18:09:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1586880564; bh=BqHxuYsBN7Y2sKEBB8Fvh/QxDla3BAmdQ2NvCIfz7+Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dz5oEbuqSEcaL1nwEfF5HTgKka0GJejE5JVx4ieM8e9fqc+8alRSJbiStmArKLUVo 3GPvYSDQprWTk+WEokqBlNPFuIbsZZe/EyhkA6ZsssMHvZMYl5KLQ5+LOiui7VLBk/ h2EpgPutAoz6UTataTIHk4gpELZPFhE8bbyHmVlw= Date: Tue, 14 Apr 2020 18:09:23 +0200 From: Jehan-Guillaume de Rorthais To: Kyotaro Horiguchi Cc: masao.fujii@oss.nttdata.com, pgsql-bugs@lists.postgresql.org, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org Subject: Re: [BUG] non archived WAL removed during production crash recovery Message-ID: <20200414180923.759f4d9c@firost> In-Reply-To: <20200410.110031.2261790267570514549.horikyota.ntt@gmail.com> References: <20200408152603.4e527053@firost> <20200409.112657.2065530970880154180.horikyota.ntt@gmail.com> <20200409113512.22581b09@firost> <20200410.110031.2261790267570514549.horikyota.ntt@gmail.com> Organization: Dalibo MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 10 Apr 2020 11:00:31 +0900 (JST) Kyotaro Horiguchi wrote: [...] > > > but the mistake here is it thinks that inRecovery represents whether it is > > > running as a standby or not, but actually it is true on primary during > > > crash recovery. > > > > Indeed. > > > > > On the other hand, with the patch, standby with archive_mode=on > > > wrongly archives WAL files during crash recovery. > > > > "without the patch" you mean? You are talking about 78ea8b5daab, right? > > No. I menat the v4 patch in [1]. > > [1] https://www.postgresql.org/message-id/20200407171736.61906608%40firost > > Prior to appllying the patch (that is the commit 78ea..), > XLogArchiveCheckDone() correctly returns true (= allow to remove it) > for the same condition. > > The proposed patch does the folloing thing. > > if (!XLogArchivingActive() || > recoveryState == ARCHIVE_RECOVERING && !XLogArchivingAlways()) > return true; > > It doesn't return for the condition "recoveryState=CRASH_RECOVERING > and archive_mode = on". Then the WAL files is mitakenly marked as > ".ready" if not marked yet. Indeed. But .ready files are then deleted during the first restartpoint. I'm not sure how to fix this behavior without making the code too complex. This is discussed in my last answer to Michael few minutes ago as well. > By the way, the code seems not following the convention a bit > here. Let the inserting code be in the same style to the existing code > around. > > + if ( ! XLogArchivingActive() ) > > I think we don't put the spaces within the parentheses above. Indeed, This is fixed in patch v5 sent few minutes ago. > | ARCHIVE_RECOVERING/CRASH_RECOVERING/NOT_IN_RECOVERY > > The first two and the last one are in different style. *I* prefer them > (if we use it) be "IN_ARCHIVE_RECOVERY/IN_CRASH_RECOVERY/NOT_IN_RECOVERY". I like Michael's proposal. See v5 of the patch. Thank you for your review! Regards,