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 1jJg3k-0008AP-Ln for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Apr 2020 16:17:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJg3j-0007OT-IN for pgsql-bugs@arkaria.postgresql.org; Wed, 01 Apr 2020 16:17:43 +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 1jJg3j-0007OF-0L for pgsql-bugs@lists.postgresql.org; Wed, 01 Apr 2020 16:17:43 +0000 Received: from mail.dalibo.com ([212.85.157.172]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJg3g-0000oQ-2C for pgsql-bugs@lists.postgresql.org; Wed, 01 Apr 2020 16:17:42 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id EFD7320AD9; Wed, 1 Apr 2020 18:17:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1585757857; bh=e7u48rCinVD4aERKH8g3F8uTFVYuklcuA6d0oTZYY3g=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SMJLvPwxaqFtC9/B9aLh7EEHRMoGSVR3A3eoi2eRGToR3vlXw5SHnA1mTjQsLXGgD RVJz9OpQqzLKO9mc2HJrqqP6XWeebDfujs9HKFOEAI9CulvgRe3Opls7eeigQeO0ox 9iHogzoyWmELR4XQ83fDgnIhi/xgWzeH2jxkO38Y= Date: Wed, 1 Apr 2020 18:17:35 +0200 From: Jehan-Guillaume de Rorthais To: Fujii Masao Cc: pgsql-bugs@lists.postgresql.org, Michael Paquier Subject: Re: [BUG] non archived WAL removed during production crash recovery Message-ID: <20200401181735.11100908@firost> In-Reply-To: References: <20200331172229.40ee00dc@firost> Organization: Dalibo MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/h7vEWdLbZK.sp3iu_oxK3Oq" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --MP_/h7vEWdLbZK.sp3iu_oxK3Oq Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Wed, 1 Apr 2020 17:27:22 +0900 Fujii Masao wrote: [...] > > bool inRecovery = RecoveryInProgress(); > > > > /* > > * The file is always deletable if archive_mode is "off". On standbys > > * archiving is disabled if archive_mode is "on", and enabled with > > * "always". On a primary, archiving is enabled if archive_mode is "on" > > * or "always". > > */ > > if (!((XLogArchivingActive() && !inRecovery) || > > (XLogArchivingAlways() && inRecovery))) > > return true; > > > > Please find in attachment a patch that fix this issue using the following > > test instead: > > > > if (!((XLogArchivingActive() && !StandbyModeRequested) || > > (XLogArchivingAlways() && inRecovery))) > > return true; > > > > I'm not sure if we should rely on StandbyModeRequested for the second part > > of the test as well thought. What was the point to rely on > > RecoveryInProgress() to get the recovery status from shared mem? > > Since StandbyModeRequested is the startup process-local variable, > it basically cannot be used in XLogArchiveCheckDone() that other process > may call. Ok, you answered my wondering about using recovery status from shared mem. This was obvious. Thanks for your help! I was wondering if we could use "ControlFile->state != DB_IN_CRASH_RECOVERY". It seems fine during crash recovery as the control file is updated before the checkpoint, but it doesn't feel right for other code paths where the control file might not be up-to-date on filesystem, right ? > So another approach would be necessary... One straight idea is to > add new shmem flag indicating whether we are in standby mode or not. I was thinking about setting XLogCtlData->SharedRecoveryInProgress as an enum using: enum RecoveryState { NOT_IN_RECOVERY = 0 IN_CRASH_RECOVERY, IN_ARCHIVE_RECOVERY } Please, find in attachment a patch implementing this. Plus, I added a second commit to add one test in regard with this bug. > Another is to make the startup process remove .ready file if necessary. I'm not sure to understand this one. Regards, --MP_/h7vEWdLbZK.sp3iu_oxK3Oq Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-v2-Fix-WAL-retention-during-production-crash-recovery.patch