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 1jPR7J-0008Q5-CG for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Apr 2020 13:33:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPR7H-0006M0-Q9 for pgsql-bugs@arkaria.postgresql.org; Fri, 17 Apr 2020 13:33:11 +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 1jPR7H-0006Lt-BX for pgsql-bugs@lists.postgresql.org; Fri, 17 Apr 2020 13:33:11 +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 1jPR7E-0000wF-RZ for pgsql-bugs@lists.postgresql.org; Fri, 17 Apr 2020 13:33:10 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id 9954820479; Fri, 17 Apr 2020 15:33:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1587130385; bh=BdMphmUXac/9idTsZqVqPAJiCjAVyMfTranOXmg/7RI=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=kyxH/oLZA9uk8DrlfmI6NDErqO6yUFfy+W1HkrAbSFnamhwb/BBzZToT1Yg5W8rk5 +3edWbwyg4QdUsTLv3JpKDAjM7mqZe/7GxJMrPWoez/v3ZlVMAAIsh1cfXv1AneDHL uiRKUouhwYrzbDYhMFDsKYsf0LPyZHTsvnkoHxwc= Date: Fri, 17 Apr 2020 15:33:04 +0200 From: Jehan-Guillaume de Rorthais To: Michael Paquier Cc: Kyotaro Horiguchi , masao.fujii@oss.nttdata.com, pgsql-bugs@lists.postgresql.org Subject: Re: [BUG] non archived WAL removed during production crash recovery Message-ID: <20200417153304.01a226cc@firost> In-Reply-To: <20200417065043.GC350229@paquier.xyz> References: <20200408022345.GC1606@paquier.xyz> <20200408135830.25a8e2ef@firost> <20200409184622.390f9b7f@firost> <20200410.111454.269125561493324950.horikyota.ntt@gmail.com> <20200413071414.GF2169@paquier.xyz> <20200414180319.731f9593@firost> <20200416081100.GD81957@paquier.xyz> <20200416234308.3e5f64bf@firost> <20200417065043.GC350229@paquier.xyz> 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, 17 Apr 2020 15:50:43 +0900 Michael Paquier wrote: > On Fri, Apr 17, 2020 at 12:07:39AM +0200, Jehan-Guillaume de Rorthais wrote: > > On Thu, 16 Apr 2020 17:11:00 +0900 Michael Paquier > > wrote: > >> Removing .done files does not matter as the segments related to them are > >> already gone. > > > > Not necessarily. There's a time windows between the moment the archiver set > > the .done file and when the checkpointer removes the associated WAL file. > > So, after a PANIC because of lack of space, WAL associated with .done files > > but not removed yet will be removed during the crash recovery. > > Not sure that it is something that matters for this thread though, so > if necessary I think that it could be be discussed separately. OK. However, unless I'm wrong, what I am describing as an desired behavior is the current behavior of XLogArchiveCheckDone. So, we might want to decide if v8 should return false during crash recovery no matter the archive_mode setup, or if we keep the curent behavior. I vote for keeping it this way. [...] > > Unless I'm wrong, the empty string does not raise an error in > > pg_stat_archiver, and I wanted to add a test on this as well. > > Exactly, it won't raise an error. Instead I switched to use a poll > query with pg_stat_file() and .ready files, but this has proved to > delay the test considerably if we did not create more segments. And > your approach has the merit to be more simple with only two segments > manipulated for the whole test. So I have tried first my idea, > noticed the mess it introduced, and just kept your approach. Maybe we could use something more common for all plateform? Eg.: archive_command='this command does not exist' At least, we would have the same error everywhere, as far as it could matter... > > Thanks for your review! Let me know if you want me to add/change/fix some > > tests. > > Thanks, I have worked more on the test, refactoring pieces related to > the segment names, adjusting some comments and fixing some of the > logic. Note that you introduced something incorrect at the creation > of $standby2 as you have been updating postgresql.conf.auto for > $standby1. erf, last minute quick edit with lack of review on my side :( > I have noticed an extra issue while looking at the backend pieces > today: at the beginning of the REDO loop we forgot one place where > SharedRecoveryState *has* to be updated to a correct state (around > the comment "Update pg_control to show that we are..." in xlog.c) as > the startup process may decide to switch the control file state to > DB_IN_ARCHIVE_RECOVERY or DB_IN_CRASH_RECOVERY, but we forgot to > update the new shared flag at this early stage. It did not matter > before because SharedRecoveryInProgress would be only "true" for both, > but that's not the case anymore as we need to make the difference > between crash recovery and archive recovery in the new flag. There is > no actual need to update SharedRecoveryState to RECOVERY_STATE_CRASH > as the initial shared memory state is RECOVERY_STATE_CRASH, but > updating the flag makes the code more consistent IMCRASHO so I updated it > anyway in the attached. Grmbl...I had this logic the other way around: init with RECOVERY_STATE_RECOVERY and set to CRASH in this exact if/then/else block... I removed it in v4 when setting XLogCtl->SharedRecoveryState to RECOVERY or CRASH based on ControlFile->state. Sorry, I forgot it after discussing the init value in v5 :( Regards,