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 1jKP9P-0006GE-Pb for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Apr 2020 16:26:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jKP9O-0007mn-D4 for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Apr 2020 16:26: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 1jKP9N-0007mg-NB for pgsql-bugs@lists.postgresql.org; Fri, 03 Apr 2020 16:26: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 1jKP9K-0004WM-SK for pgsql-bugs@lists.postgresql.org; Fri, 03 Apr 2020 16:26:32 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 8E80E208E7; Fri, 3 Apr 2020 18:26:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1585931186; bh=rzr1Xs0Hc3dLNrb21Lb1sCW3GzXJDBP0wSSMCaf/p9U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jxJ4Io4NPKQWCx1UjgXx15za2bPzp4nv3fzK3bDQhl0Cr5t4PHQw3Dxvg77V/GB1I HDxkQq3asLUJ6t3bJLKp022N6tegFbsaLOnVqqFIy8xT6CdXNP2nNRXRP3T0O10Zew XJo+4rXypid5WdGAVTIHcvD78th9JTJs885CfxKE= Date: Fri, 3 Apr 2020 18:26:25 +0200 From: Jehan-Guillaume de Rorthais To: Fujii Masao Cc: Kyotaro Horiguchi , pgsql-bugs@lists.postgresql.org, michael@paquier.xyz Subject: Re: [BUG] non archived WAL removed during production crash recovery Message-ID: <20200403182625.0fccc6fd@firost> In-Reply-To: <3d543ef2-ae02-5e59-3bfe-b79d00dab360@oss.nttdata.com> References: <20200402.130443.1791362864704140391.horikyota.ntt@gmail.com> <20200402.130734.613319908534820379.horikyota.ntt@gmail.com> <03900fc5-fff4-109a-fe69-83de2c167929@oss.nttdata.com> <20200402.162323.770257425358491539.horikyota.ntt@gmail.com> <20200402154915.4984cff2@firost> <3d543ef2-ae02-5e59-3bfe-b79d00dab360@oss.nttdata.com> Organization: Dalibo MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/hFsTesUnE4wI_trfLOopy+I" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --MP_/hFsTesUnE4wI_trfLOopy+I Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Thu, 2 Apr 2020 23:55:46 +0900 Fujii Masao wrote: > On 2020/04/02 22:49, Jehan-Guillaume de Rorthais wrote: >> On Thu, 2 Apr 2020 19:38:59 +0900 >> Fujii Masao wrote: [...] >>> That is, WAL files with .ready files are removed when either >>> archive_mode!=always in standby mode or archive_mode=off. >> >> sounds fine to me. To some extends, it appears to me this sentence was relatively close to my previous patch, as far as you exclude IN_CRASH_RECOVERY from the shortcut: XLogArchiveCheckDone(const char *xlog) { [...] if ( (inRecoveryState != IN_CRASH_RECOVERY) && ( (inRecoveryState == NOT_IN_RECOVERY && !XLogArchivingActive()) || (inRecoveryState == IN_ARCHIVE_RECOVERY && !XLogArchivingAlways()))) return true; Which means that only .done cleanup would occurs during CRASH_RECOVERY and .ready files might be created if no .done exists. No matter the futur status of the cluster: primary or standby. Normal shortcut will apply during first checkpoint after the crash recovery step. This should handle the case where a backup without backup_label (taken from a snapshot or after a shutdown with immediate) is restored to build a standby. Please, find in attachment a third version of my patch "0001-v3-Fix-WAL-retention-during-production-crash-recovery.patch". "0002-v1-Add-test-on-non-archived-WAL-during-crash-recovery.patch" is left untouched. But I'm considering adding some more tests relative to this discussion. > BTW, now I'm thinking that the flag in shmem should be updated when > the startup process sets StandbyModeRequested to true at the beginning > of the recovery. That is, > > - Add something like SharedStandbyModeRequested into XLogCtl. This field > should be initialized with false; > - Set XLogCtl->SharedStandbyModeRequested to true when the startup > process detects the standby.signal file and sets the local variable > StandbyModeRequested to true. > - Make XLogArchiveCheckDone() use XLogCtl->SharedStandbyModeRequested > to know whether the server is in standby mode or not. > > Thought? I try to avoid a new flag in memory with the proposal in attachment of this email. It seems to me various combinaisons of booleans with subtle differences around the same subject makes it a bit trappy and complicated to understand. If my proposal is rejected, I'll be happy to volunteer to add XLogCtl->SharedStandbyModeRequested though. It seems like a simple enough fix as well. Regards, --MP_/hFsTesUnE4wI_trfLOopy+I Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-v3-Fix-WAL-retention-during-production-crash-recovery.patch