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 1mfe2S-00040i-5S for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Oct 2021 08:12:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mfe2Q-0004nO-T0 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Oct 2021 08:11:58 +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 1mfe2Q-0004nF-FL for pgsql-hackers@lists.postgresql.org; Wed, 27 Oct 2021 08:11:58 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mfe2N-0003lE-4Y for pgsql-hackers@lists.postgresql.org; Wed, 27 Oct 2021 08:11:57 +0000 Received: by mail-wr1-x42e.google.com with SMTP id o14so2565595wra.12 for ; Wed, 27 Oct 2021 01:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aiven.io; s=google; h=from:to:cc:subject:date:message-id:organization:in-reply-to :references:mime-version:content-transfer-encoding; bh=uLOL/Z5hDhpUQgyzx1e2OxNv23YtJnTM+IEmUH9JA/w=; b=LEaKJ/RxRzGfW9Ao8zIh+waP6g0usvO5WTRdQmU4NkpHiDi5HI0nT5YG5lNGcj29Iy x8/AGdUrjuXj2UyqssAWobBVolVP27kA3vQEtpCpT8lny3/Wunuq//sfujmEQ9KHWuoi KLYcLBMKKcFePa4dYAxe+PMEsMMREYZAd9xyE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:organization :in-reply-to:references:mime-version:content-transfer-encoding; bh=uLOL/Z5hDhpUQgyzx1e2OxNv23YtJnTM+IEmUH9JA/w=; b=EGorA15AlLeo3owE6dIFCTUjjK59mJksS8wOb363XwNAS3Zy76LUr7zoZuF/CXFcjf wUCMpJWJrG749NzrxdfcOSJjytTxwmjU3OL5UUQaNftVhAOmU8eRH2sdmlTL5LjU671N LCbFwAL6udHYTAlCs1PbTbfgbRQCK9MoC6l6Mj4NbTO95Blc8JucKuILMT5TwnLs51S2 CAWGpXqz1sf6/xPIXfBVkgrMuYfx5SQ2nvZDN6Ns0IkpVNL3l0maObCZWgRgqvAnqKog kYUbW0vosfgDMNQ5W0HLJg8zz9d6g61Mwm5B/NV/i8u49herGkV07JfPd/xhI6P4H2b0 xBqA== X-Gm-Message-State: AOAM531nymHwjXmywzj5AYU7FqSUj5vOPHsc2Ek3e2Lw+vioUXI1rXAW WllXSeVFU9MPrr9F2D5MFF3ceA== X-Google-Smtp-Source: ABdhPJy+PE16PRHT7isBaesWFKls/t+yvAA1afyE1zgM1NtjQSG1FGcowkghEYUAtuXxgr0SfqmGmg== X-Received: by 2002:adf:c183:: with SMTP id x3mr36468955wre.90.1635322313745; Wed, 27 Oct 2021 01:11:53 -0700 (PDT) Received: from aivenronan.localnet (static-176-158-121-96.ftth.abo.bbox.fr. [176.158.121.96]) by smtp.gmail.com with ESMTPSA id u2sm20287699wrr.35.2021.10.27.01.11.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 01:11:52 -0700 (PDT) From: Ronan Dunklau To: Kyotaro Horiguchi Cc: bharath.rupireddyforpostgres@gmail.com, michael@paquier.xyz, pgsql-hackers@lists.postgresql.org, sawada.mshk@gmail.com Subject: Re: pg_receivewal starting position Date: Wed, 27 Oct 2021 10:11:00 +0200 Message-ID: <12900687.dW097sEU6C@aivenronan> Organization: aiven In-Reply-To: <4777975.0VBMTVartN@aivenronan> References: <20211027.111728.1991417859896017411.horikyota.ntt@gmail.com> <4777975.0VBMTVartN@aivenronan> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart23056841.ouqheUzb2q" Content-Transfer-Encoding: 7Bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --nextPart23056841.ouqheUzb2q Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="iso-8859-1" Le mercredi 27 octobre 2021, 10:00:40 CEST Ronan Dunklau a =E9crit : > Le mercredi 27 octobre 2021, 04:17:28 CEST Kyotaro Horiguchi a =E9crit : > > +my @walfiles =3D glob "$slot_dir/*"; > >=20 > > This is not used. >=20 > Sorry, fixed in attached version. >=20 > > Each pg_receivewal run stalls for about 10 or more seconds before > > finishing, which is not great from the standpoint of recently > > increasing test run time. > >=20 > > Maybe we want to advance LSN a bit, after taking $nextlsn then pass > > "-s 1" to pg_receivewal. >=20 > I incorrectly assumed it was due to the promotion time without looking in= to > it. In fact, you're right the LSN was not incremented after we fetched the > end lsn, and thus we would wait for quite a while. I fixed that too. >=20 > Thank you for the review ! Sorry I sent an intermediary version of the patch, here is the correct one. =2D-=20 Ronan Dunklau --nextPart23056841.ouqheUzb2q Content-Disposition: attachment; filename="v15-0001-Add-a-test-for-pg_receivewal-following-timeline-.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="v15-0001-Add-a-test-for-pg_receivewal-following-timeline-.patch" From 8fa22687e50f02539119568f98b6a11c077f1774 Mon Sep 17 00:00:00 2001 From: Ronan Dunklau Date: Tue, 26 Oct 2021 10:54:12 +0200 Subject: [PATCH v15] Add a test for pg_receivewal following timeline switch. pg_receivewal is able to follow a timeline switch, but this was not tested anywher. This test case verify that it works as expected both when resuming from a replication slot and from the archive directory, which have different methods of retrieving the timeline it left off. --- src/bin/pg_basebackup/t/020_pg_receivewal.pl | 88 +++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_basebackup/t/020_pg_receivewal.pl b/src/bin/pg_basebackup/t/020_pg_receivewal.pl index 092c9b6f25..f561aca8f8 100644 --- a/src/bin/pg_basebackup/t/020_pg_receivewal.pl +++ b/src/bin/pg_basebackup/t/020_pg_receivewal.pl @@ -5,7 +5,7 @@ use strict; use warnings; use PostgreSQL::Test::Utils; use PostgreSQL::Test::Cluster; -use Test::More tests => 31; +use Test::More tests => 39; program_help_ok('pg_receivewal'); program_version_ok('pg_receivewal'); @@ -206,3 +206,89 @@ $primary->command_ok( "WAL streamed from the slot's restart_lsn"); ok(-e "$slot_dir/$walfile_streamed", "WAL from the slot's restart_lsn has been archived"); + +# Test a timeline switch. +# This test is split in two, using the same standby: one test check the +# resume-from-folder case, the other the resume-from-slot one. + +# Setup a standby for our tests +my $backup_name = "basebackup"; +$primary->backup($backup_name); +my $standby = PostgreSQL::Test::Cluster->new("standby"); +$standby->init_from_backup($primary, $backup_name, has_streaming => 1); +$standby->start; + +# Cleanup the previous stream directories to reuse them +unlink glob "'${stream_dir}/*'"; +unlink glob "'${slot_dir}/*'"; + +# Create two replication slots. +# First one is to make sure we keep the wal for the resume-from-folder case. +my $folder_slot = "folder_slot"; +$standby->psql('', + "CREATE_REPLICATION_SLOT $folder_slot PHYSICAL (RESERVE_WAL)", + replication => 1); +# Second one is for testing the resume-from-slot case +my $archive_slot = "archive_slot"; +$standby->psql('', + "CREATE_REPLICATION_SLOT $archive_slot PHYSICAL (RESERVE_WAL)", + replication => 1); +# Get a walfilename from before the promotion to make sure it is archived +# after promotion +my $walfile_before_promotion = $primary->safe_psql('postgres', + "SELECT pg_walfile_name(pg_current_wal_insert_lsn())"); +# Populate the stream_dir for the resume-from-folder case. +$nextlsn = $primary->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();'); +chomp($nextlsn); +# Switch wal to make sure it is not a partial file but a complete segment. +$primary->psql('postgres', + 'INSERT INTO test_table VALUES (generate_series(1,100));'); +$primary->psql('postgres', 'SELECT pg_switch_wal();'); + +$standby->run_log( + [ 'pg_receivewal', '-D', $stream_dir, '--verbose', '--endpos', $nextlsn, + '--slot', $folder_slot, '--no-sync'], + "Stream some wal before promoting"); + +# Everything is setup, promote the standby to trigger a timeline switch +$standby->psql( + 'postgres', + "SELECT pg_promote(wait_seconds => 300)"); + +# Force a wal switch to make sure at least one full WAL is archived on the new +# timeline, and fetch this walfilename. +my $walfile_after_promotion = $standby->safe_psql('postgres', + "SELECT pg_walfile_name(pg_current_wal_insert_lsn())"); +$standby->psql('postgres', + 'INSERT INTO test_table VALUES (generate_series(1,100));'); +$standby->psql('postgres', 'SELECT pg_switch_wal();'); +$nextlsn = + $standby->safe_psql('postgres', 'SELECT pg_current_wal_insert_lsn();'); +chomp($nextlsn); +$standby->psql('postgres', + 'INSERT INTO test_table VALUES (generate_series(1,100));'); + +# Now, try to resume after the promotion, from the folder. +$standby->command_ok( + [ 'pg_receivewal', '-D', $stream_dir, '--verbose', '--endpos', $nextlsn, + '--slot', $folder_slot, '--no-sync'], + "Stream some wal after promoting, resuming from the folder's position"); + +ok(-e "$stream_dir/$walfile_before_promotion", + "WAL from the old timeline has been archived resuming from the folder"); +ok(-e "$stream_dir/$walfile_after_promotion", + "WAL from the new timeline has been archived resuming from the folder"); +ok(-e "$stream_dir/00000002.history", + "Timeline history file has been archived resuming from the folder"); + +# Same thing, resuming from the slot +$standby->command_ok( + [ 'pg_receivewal', '-D', $slot_dir, '--verbose', '--endpos', $nextlsn, + '--slot', $archive_slot, '--no-sync'], + "Stream some wal after promoting, resuming from the slot's position"); +ok(-e "$slot_dir/$walfile_before_promotion", + "WAL from the old timeline has been archived resuming from the slot"); +ok(-e "$slot_dir/$walfile_after_promotion", + "WAL from the new timeline has been archived resuming from the slot"); +ok(-e "$slot_dir/00000002.history", + "Timeline history file has been archived resuming from the slot"); -- 2.33.1 --nextPart23056841.ouqheUzb2q--