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 1jMTam-0002P3-M3 for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Apr 2020 09:35:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jMTal-0007Sj-HD for pgsql-bugs@arkaria.postgresql.org; Thu, 09 Apr 2020 09:35:23 +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 1jMTal-0007Sc-0C for pgsql-bugs@lists.postgresql.org; Thu, 09 Apr 2020 09:35:23 +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 1jMTae-0000cJ-7D for pgsql-bugs@lists.postgresql.org; Thu, 09 Apr 2020 09:35:21 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 98A811F887; Thu, 9 Apr 2020 11:35:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1586424913; bh=HRV3ljIBkuEzbFVZmXQyQ7VDHFEyp2AtAv+InsVU+1E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ctlDDnP0oBEnXFrsaoEbsh+qPk3GPBVLdh2eySGHtuKOu7kebiZPRP/+4ioiqdd4A rMFwRtFQAdLPCkiWIY4kXQgDadpvvC7HDLCy3CdXkF1RTZ5USzfEUPX/OWO5XvD7kL 1+HLvtLMRBiKpAIkc5E+vL8CXY/4Y3EaePnO2xhY= Date: Thu, 9 Apr 2020 11:35:12 +0200 From: Jehan-Guillaume de Rorthais To: Kyotaro Horiguchi Cc: masao.fujii@oss.nttdata.com, pgsql-bugs@lists.postgresql.org, michael@paquier.xyz Subject: Re: [BUG] non archived WAL removed during production crash recovery Message-ID: <20200409113512.22581b09@firost> In-Reply-To: <20200409.112657.2065530970880154180.horikyota.ntt@gmail.com> References: <20200407171736.61906608@firost> <20200408.173909.874800874546158298.horikyota.ntt@gmail.com> <20200408152603.4e527053@firost> <20200409.112657.2065530970880154180.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 Thu, 09 Apr 2020 11:26:57 +0900 (JST) Kyotaro Horiguchi wrote: [...] > > > At Thu, 2 Apr 2020 15:49:15 +0200, Jehan-Guillaume de Rorthais > > > wrote in > > > > > Ok, so our *current* consensus seems the followings. Right? > > > > > > > > > > - If archive_mode=off, any WAL files with .ready files are removed in > > > > > crash recovery, archive recoery and standby mode. > > > > > > > > yes > > > > > > If archive_mode = off no WAL files are marked as ".ready". > > > > Sure, on the primary side. > > > > What if you build a standby from a backup with archive_mode=on with > > some .ready files in there? > > Well. Backup doesn't have nothing in archive_status directory if it is > taken by pg_basebackup. If the backup is created other way, it can > have some (as Fujii-san mentioned). Master with archive_mode != off > and standby with archive_mode=always should archive WAL files that are > not marked .done, but standby with archive_mode == on should not. The > commit intended that Unless I'm wrong, the commit avoids creating .ready files on standby when a WAL has neither .done or .ready status file. > 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? > What we should check there is, as the commit was intended, not whether > it is under crash or archive recovery, but whether it is running as > primary or standby. Yes. > > > If it is "always", WAL files that are to be archived are > > > marked as ".ready". Finally, the condition reduces to: > > > > > > If archiver is running, archive ".ready" files. Otherwise ignore > > > ".ready" and just remove WAL files after use. > > > > > > > > > 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. > > > > > > That situation implies that archive_mode has been changed. > > > > Why? archive_mode may have been "always" on the primary when eg. a snapshot > > has been created. > > .ready files are created only when archive_mode != off. Yes, on a primary, they are created when archive_mode > off. On standby, when archive_mode=always. If a primary had archive_mode=always, a standby created from its backup will still have archive_mode=always, with no changes. Maybe I miss your point, sorry. Regards,