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 1jRxz2-00081o-PZ for pgsql-bugs@arkaria.postgresql.org; Fri, 24 Apr 2020 13:03:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jRxz1-00085d-BU for pgsql-bugs@arkaria.postgresql.org; Fri, 24 Apr 2020 13:03:07 +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 1jRxz0-00085W-OZ for pgsql-bugs@lists.postgresql.org; Fri, 24 Apr 2020 13:03:07 +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 1jRxyy-0000TS-Eb for pgsql-bugs@lists.postgresql.org; Fri, 24 Apr 2020 13:03:06 +0000 Received: from firost (larco.ioguix.net [82.66.0.6]) by mail.dalibo.com (Postfix) with ESMTPSA id CFA6F205DD; Fri, 24 Apr 2020 15:03:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1587733381; bh=mluslQo0fqkr+yJOZ9zQn2hWwjgEyiNMvarps7qcf0U=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=j3d4A8K6g4nK3s6Zb+JFUZUIEkxmgiKPJ7pmA0ik3uhqaXuvOQToJrLc4PsudNLHL DYdJf7iWtzaugljUr955pwAsJDfCR9dPKJ84Mv/AzmaXNwvNu1lIBsSHpif+ls6YwX sQdPtTV2wkSdA+JuoeCbrtyyvukf7T6tcuIzkKPs= Date: Fri, 24 Apr 2020 15:03:00 +0200 From: Jehan-Guillaume de Rorthais To: Michael Paquier Cc: Tom Lane , 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: <20200424150300.1b3b0c20@firost> In-Reply-To: <20200424034248.GL33034@paquier.xyz> References: <20200422175824.637bda91@firost> <20200422181717.491fb499@firost> <20200422234618.GI33034@paquier.xyz> <20200423.140546.1055476118690602079.horikyota.ntt@gmail.com> <20200423185953.5f8e5b8f@firost> <20200423235402.GJ33034@paquier.xyz> <25921.1587694875@sss.pgh.pa.us> <20200424034248.GL33034@paquier.xyz> Organization: Dalibo MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/kbqga+I=naXE+VsNP_fbnFv" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --MP_/kbqga+I=naXE+VsNP_fbnFv Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline On Fri, 24 Apr 2020 12:43:51 +0900 Michael Paquier wrote: > On Thu, Apr 23, 2020 at 10:21:15PM -0400, Tom Lane wrote: > > Looks like the news is not good :-( > > Yes, I was looking at that for the last couple of hours, and just > pushed something to put back the buildfarm to a green state for now > (based on the first results things seem stable now) by removing the > defective subset of tests. > > > I see that my own florican is one of the failing critters, though > > it failed only on HEAD which seems odd. Any suggestions what to > > look for? > > The issue comes from the parts of the test where we expect some .ready > files to exist (or not) after triggering a restartpoint to force some > segments to be recycled. And looking more at it, I suspect that the > issue is actually that we don't make sure in the test that the > standbys started have replayed up to the segment switch record > triggered on the primary (the one within generate_series(10,20)), and > then the follow-up restart point does not actually recycle the > segments we expect to recycle. That's more likely going to be a > problem on slower machines as the window gets wider between the moment > the standbys reach their consistency point and the moment the switch > record is replayed. Indeed. In regard with your fix, as we don't know if the standby caught up with the latest available record, there's really no point to keep this test either: # Recovery with archive_mode=on should not create .ready files. # Note that this segment did not exist in the backup. ok( !-f "$standby1_data/$segment_path_2_ready", ".ready file for WAL segment $segment_name_2 not created on standby when archive_mode=on on standby" ); I agree the three tests could be removed as they were not covering the bug we were chasing. However, they might still be useful to detect futur non expected behavior changes. If you agree with this, please, find in attachment a patch proposal against HEAD that recreate these three tests **after** a waiting loop on both standby1 and standby2. This waiting loop is inspired from the tests in 9.5 -> 10. Regards, --MP_/kbqga+I=naXE+VsNP_fbnFv Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=wait-for-wal-replay.patch diff --git a/src/test/recovery/t/020_archive_status.pl b/src/test/recovery/t/020_archive_status.pl index 401412e687..d197066567 100644 --- a/src/test/recovery/t/020_archive_status.pl +++ b/src/test/recovery/t/020_archive_status.pl @@ -5,7 +5,7 @@ use strict; use warnings; use PostgresNode; use TestLib; -use Test::More tests => 13; +use Test::More tests => 16; use Config; my $primary = get_new_node('master'); @@ -93,7 +93,7 @@ $primary->safe_psql( $primary->poll_query_until('postgres', q{SELECT archived_count FROM pg_stat_archiver}, '1') - or die "Timed out while waiting for archiving to finish"; + or die "Timed out while waiting for archiving to finish"; ok(!-f "$primary_data/$segment_path_1_ready", ".ready file for archived WAL segment $segment_name_1 removed"); @@ -119,14 +119,23 @@ my $segment_path_2_done = "$segment_path_2.done"; $primary->safe_psql( 'postgres', q{ INSERT INTO mine SELECT generate_series(10,20) AS x; - SELECT pg_switch_wal(); CHECKPOINT; }); +# Make sure that the standby has caught here. +my $primary_lsn = $primary->safe_psql('postgres', + q{SELECT pg_current_wal_lsn()}); + +# force archiving current wal +$primary->safe_psql( + 'postgres', q{ + SELECT pg_switch_wal(); +}); + $primary->poll_query_until('postgres', q{ SELECT last_archived_wal FROM pg_stat_archiver }, $segment_name_2) - or die "Timed out while waiting for archiving to finish"; + or die "Timed out while waiting for archiving to finish"; # Test standby with archive_mode = on. my $standby1 = get_new_node('standby'); @@ -134,14 +143,30 @@ $standby1->init_from_backup($primary, 'backup', has_restoring => 1); $standby1->append_conf('postgresql.conf', "archive_mode = on"); my $standby1_data = $standby1->data_dir; $standby1->start; + +$standby1->poll_query_until('postgres', + qq{ SELECT pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '$primary_lsn') >= 0 }) + or die "Timed out while waiting for xlog replay on standby2"; + $standby1->safe_psql('postgres', q{CHECKPOINT}); +# Recovery with archive_mode=on does not keep .ready signal files inherited +# from backup. Note that this WAL segment existed in the backup. +ok( !-f "$standby1_data/$segment_path_1_ready", + ".ready file for WAL segment $segment_name_1 present in backup got removed with archive_mode=on on standby" +); + # Recovery with archive_mode=on should not create .ready files. # Note that this segment did not exist in the backup. ok( !-f "$standby1_data/$segment_path_2_ready", ".ready file for WAL segment $segment_name_2 not created on standby when archive_mode=on on standby" ); +# Recovery with archive_mode = on creates .done files. +ok( -f "$standby1_data/$segment_path_2_done", + ".done file for WAL segment $segment_name_2 created when archive_mode=on on standby" +); + # Test recovery with archive_mode = always, which should always keep # .ready files if archiving is enabled, though here we want the archive # command to fail to persist the .ready files. Note that this node @@ -153,12 +178,20 @@ $standby2->append_conf('postgresql.conf', 'archive_mode = always'); my $standby2_data = $standby2->data_dir; $standby2->start; +$standby2->poll_query_until('postgres', + qq{ SELECT pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '$primary_lsn') >= 0 }) + or die "Timed out while waiting for xlog replay on standby2"; + $standby2->safe_psql('postgres', q{CHECKPOINT}); ok( -f "$standby2_data/$segment_path_1_ready", ".ready file for WAL segment $segment_name_1 existing in backup is kept with archive_mode=always on standby" ); +ok( -f "$standby2_data/$segment_path_2_ready", + ".ready file for WAL segment $segment_name_2 created with archive_mode=always on standby" +); + # Reset statistics of the archiver for the next checks. $standby2->safe_psql('postgres', q{SELECT pg_stat_reset_shared('archiver')}); --MP_/kbqga+I=naXE+VsNP_fbnFv--