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 1jK1ui-00065t-Ct for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2020 15:37:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jK1uh-0005a2-AY for pgsql-bugs@arkaria.postgresql.org; Thu, 02 Apr 2020 15:37:51 +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 1jK1ug-0005Zv-Pk for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2020 15:37:51 +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 1jK1ue-00049r-Cx for pgsql-bugs@lists.postgresql.org; Thu, 02 Apr 2020 15:37:50 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id C53B120ACB; Thu, 2 Apr 2020 17:37:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1585841865; bh=061G3O7p9XC+0Arg35+umlGvXMaBibS4JffP8JUQBvk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QjQR1GF/Ji2fZ4DA2cDgMmB6bZEq5IBe3c8lEvA05uRaSU0VxwOzwK6wvgPdSHvbQ YeO62GS40QzlSIsH9Ol4UksgLIleV8nHtd06wU8WLOAPr3QG7LJvDfnn3qFyVr1e2b iMdyZN9DmsTFas9VP+sknp1bNQXcz02GUsnWKXCo= Date: Thu, 2 Apr 2020 17:37:44 +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: <20200402173744.0a504243@firost> In-Reply-To: References: <20200401181735.11100908@firost> <20200402.130443.1791362864704140391.horikyota.ntt@gmail.com> <20200402.130734.613319908534820379.horikyota.ntt@gmail.com> <20200402150234.278ae845@firost> 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 Thu, 2 Apr 2020 23:58:00 +0900 Fujii Masao wrote: > On 2020/04/02 22:02, Jehan-Guillaume de Rorthais wrote: > > On Thu, 02 Apr 2020 13:07:34 +0900 (JST) > > Kyotaro Horiguchi wrote: > > > >> Sorry, it was quite ambiguous. > >> > >> At Thu, 02 Apr 2020 13:04:43 +0900 (JST), Kyotaro Horiguchi > >> wrote in > >>> At Wed, 1 Apr 2020 18:17:35 +0200, Jehan-Guillaume de Rorthais > >>> wrote in > >>>> Please, find in attachment a patch implementing this. > >>> > >>> The patch partially reintroduces the issue the patch have > >>> fixed. Specifically a standby running a crash recovery wrongly marks a > >>> WAL file as ".ready" if it is extant in pg_wal without accompanied by > >>> .ready file. > >> > >> The patch partially reintroduces the issue the commit 78ea8b5daa have > >> fixed. Specifically a standby running a crash recovery wrongly marks a > >> WAL file as ".ready" if it is extant in pg_wal without accompanied by > >> .ready file. > > > > As far as I understand StartupXLOG(), NOT_IN_RECOVERY and IN_CRASH_RECOVERY > > are only set for production clusters, not standby ones. > > DB_IN_CRASH_RECOVERY can be set even in standby mode. For example, > if you start the standby from the cold backup of the primary, In cold backup? Then ControlFile->state == DB_SHUTDOWNED, right? Unless I'm wrong, this should be catched by: if (ArchiveRecoveryRequested && ( [...] || ControlFile->state == DB_SHUTDOWNED)) { InArchiveRecovery = true; if (StandbyModeRequested) StandbyMode = true; } With InArchiveRecovery=true, we later set DB_IN_ARCHIVE_RECOVERY instead of DB_IN_CRASH_RECOVERY. > since InArchiveRecovery is false at the beginning of the recovery, > DB_IN_CRASH_RECOVERY is set in that moment. But then after all the valid > WAL in pg_wal have been replayed, InArchiveRecovery is set to true and > DB_IN_ARCHIVE_RECOVERY is set. However, I suppose this is true if you restore a backup from a snapshot without backup_label, right?