Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u08SD-00CeyQ-3b for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Apr 2025 00:29:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u08SB-001Gmb-Ef for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Apr 2025 00:29:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u08SA-001GmS-Pg for pgsql-hackers@lists.postgresql.org; Thu, 03 Apr 2025 00:29:07 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u08S8-002dgV-2A for pgsql-hackers@postgresql.org; Thu, 03 Apr 2025 00:29:05 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-224019ad9edso4993195ad.1 for ; Wed, 02 Apr 2025 17:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; t=1743640143; x=1744244943; darn=postgresql.org; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=IZSXL8Z3ncAKSOxlL+LSv668zx7NyhvayHeR7vs5sLo=; b=YLI46m7vVyJqvGrXQzdnMi5BG0bAU6z4pQde3BHxkJVcSDgmxx/KuLlieVkx8Sgd0z 2ZuJZcuV4S0jAojxfHOshD0CJVNVChvDPMJLw1+s3Ony6XMCzlZoiE0y5kkuphcAe86J j7utW3iezi/OCm9UVbCSEx9b47TVGPGvcMiRU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743640143; x=1744244943; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IZSXL8Z3ncAKSOxlL+LSv668zx7NyhvayHeR7vs5sLo=; b=csd/f15nD5vBA76zFtJ5uyAHpAvvuIovqC4CK1+IBcoVKPdStm2Ypbam9WPt0kbq5Q Nluc0v5nm6/vg5hfb1pY9iAsXtcUqhP0RB16AV20ZHrqc12HRO4wCGBIFYso8bIedHgA pUbRIyzV5I9prWCNf0cOv24QVMYA3weVL27b0VrpWsEY1+jrPekxcP1/C+DT8JY+g0tU WK/7KfUMyLHSUVUNItvbpGIyaK3a9IJbfMiuvKc/5HhliwWUMnUgmZG/e0RjwZJylgZe fu/OKQwcjEqTHA8XR5T3yLlDJz8+IS+TQaBfPS2/YwYAnmcbopAQKrzdswggju/NuIsc ByGQ== X-Forwarded-Encrypted: i=1; AJvYcCWQGVs/5MeUrJMbbDRZEzkJPGmTK9MX1AKRwK5ZzTlNiGoefo9RMMigwMgCyznO2ecJgCA35YaV5y+mTMhK@postgresql.org X-Gm-Message-State: AOJu0YyxLQKT/Ezvwzwv+ts90G/ZAHUcGELevRaEEdYofRClZWZIb5V2 ISB41A778DDSDggobylc4JRH1Nhj+7Ktylc+3n8ilQ2/rOM+c53DD7D4utdSdw== X-Gm-Gg: ASbGncthubmochBzQexvFq3oL79O7Y8nFui7+c/Mi05v0aeat6jSCHlSTt4UqhvYphO ECX3I4fhVeFkvdMoP95SEw28Cbt77Y1Uv22CZXPkPn/c2VS71cG9EpUCBsq+hheRki2YxJ6CiSR T6OSsOtcxeafhlSTpnWpDe4A59JIjo0AuPRdgxG8Ly7NiTWO6y5PrsBNNoA0m4wnPj+r6oEy/Hk 0JivIpIJeOsSXYtMxUzvQoGKVGZL82ZfV6qWpxRLc73HcLQ+CWGofgkpcHd5q42OO5rSJBIMKtE izckGMGsEaF6mGRs+wloZyo+mIxii6knM6pyr3/QxA== X-Google-Smtp-Source: AGHT+IEw6xkOZWWDohhR7uDorfNKcWM2yXu2EUO84JZaLfgZ+qs+FHwckeI+j0gox0E/SvwB1w3iew== X-Received: by 2002:a17:902:d2c4:b0:224:c76:5e57 with SMTP id d9443c01a7336-2296c85f055mr56800895ad.39.1743640143448; Wed, 02 Apr 2025 17:29:03 -0700 (PDT) Received: from google.com ([2601:647:5600:80d0::31cd]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2297865c1ffsm1940015ad.126.2025.04.02.17.29.01 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Apr 2025 17:29:02 -0700 (PDT) Date: Wed, 2 Apr 2025 17:29:00 -0700 From: Noah Misch To: Michael Paquier Cc: Nathan Bossart , Andres Freund , Robert Pang , Kyotaro Horiguchi , Tom Lane , robertmhaas@gmail.com, pgsql-hackers@postgresql.org Subject: Re: Back-patch of: avoid multiple hard links to same WAL file after a crash Message-ID: <20250403002900.5d.nmisch@google.com> References: <7chjz7zeigbsbt7nim4cj6zryflzcpy2lgenas3yh7cpvwf3gb@m6cwqzlvfd6q> <20250306193013.36.nmisch@google.com> <20250311205749.a8.nmisch@google.com> <20250312012315.fd.nmisch@google.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="402OII5J8w+WWZaJ" Content-Disposition: inline In-Reply-To: <20250312012315.fd.nmisch@google.com> User-Agent: Mutt/2.2.12 (2023-09-09) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --402OII5J8w+WWZaJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Tue, Mar 11, 2025 at 06:23:15PM -0700, Noah Misch wrote: > On Wed, Mar 12, 2025 at 09:46:27AM +0900, Michael Paquier wrote: > > On Tue, Mar 11, 2025 at 01:57:49PM -0700, Noah Misch wrote: > > > Thanks for crafting back-branch versions. I've queued a task to confirm I get > > > the same result. > > > > Thanks for that. That helps a lot. > > I'll let you know when I get there. Your back-patches are correct. Thanks. > > > There's a test case I'll polish, too. > > > > Are you considering the addition of a TAP test in 17~ based on a wait > > injection point in the checkpointer coupled with a check of the server > > logs to see if we see the error patterns you've spotted? > > No, nothing involving injection points or otherwise version-specific. Here it is. Making it fail three times took looping 1383s, 5841s, and 2594s. Hence, it couldn't be expected to catch the regression before commit, but it would have made sufficient buildfarm and CI noise in the day after commit. --402OII5J8w+WWZaJ Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="test-archive-restartpoint-v1.patch" Author: Noah Misch Commit: Noah Misch Test restartpoints in archive recovery. v14 commit 1f95181b44c843729caaa688f74babe9403b5850 and its v13 equivalent caused timing-dependent failures in archive recovery, at restartpoints. The symptom was "invalid magic number 0000 in log segment X, offset 0", "unexpected pageaddr X in log segment Y, offset 0" [X < Y], or an assertion failure. Commit FIXME and predecessors back-patched v15 changes to fix that. This test reproduces the problem probabilistically, typically in less than 1000 iterations of the test. Hence, buildfarm and CI runs would have surfaced enough failures to get attention within a day. Back-patch to v13 (all supported versions). Reported by Arun Thirupathi. Reviewed by FIXME. Discussion: https://postgr.es/m/20250306193013.36.nmisch@google.com diff --git a/src/test/recovery/meson.build b/src/test/recovery/meson.build index 057bcde..cb98376 100644 --- a/src/test/recovery/meson.build +++ b/src/test/recovery/meson.build @@ -53,6 +53,7 @@ tests += { 't/042_low_level_backup.pl', 't/043_no_contrecord_switch.pl', 't/044_invalidate_inactive_slots.pl', + 't/045_archive_restartpoint.pl', ], }, } diff --git a/src/test/recovery/t/045_archive_restartpoint.pl b/src/test/recovery/t/045_archive_restartpoint.pl new file mode 100644 index 0000000..b143bc4 --- /dev/null +++ b/src/test/recovery/t/045_archive_restartpoint.pl @@ -0,0 +1,57 @@ + +# Copyright (c) 2024-2025, PostgreSQL Global Development Group + +# Test restartpoints during archive recovery. +use strict; +use warnings; + +use PostgreSQL::Test::Cluster; +use PostgreSQL::Test::Utils; +use Test::More; + +my $archive_max_mb = 320; +my $wal_segsize = 1; + +# Initialize primary node +my $node_primary = PostgreSQL::Test::Cluster->new('primary'); +$node_primary->init( + has_archiving => 1, + allows_streaming => 1, + extra => [ '--wal-segsize' => $wal_segsize ]); +$node_primary->start; +my $backup_name = 'my_backup'; +$node_primary->backup($backup_name); + +$node_primary->safe_psql('postgres', + ('DO $$BEGIN FOR i IN 1..' . $archive_max_mb / $wal_segsize) + . ' LOOP CHECKPOINT; PERFORM pg_switch_wal(); END LOOP; END$$;'); + +# Force archiving of WAL file containing recovery target +my $until_lsn = $node_primary->lsn('write'); +$node_primary->safe_psql('postgres', "SELECT pg_switch_wal()"); +$node_primary->stop; + +# Archive recovery +my $node_restore = PostgreSQL::Test::Cluster->new('restore'); +$node_restore->init_from_backup($node_primary, $backup_name, + has_restoring => 1); +$node_restore->append_conf('postgresql.conf', + "recovery_target_lsn = '$until_lsn'"); +$node_restore->append_conf('postgresql.conf', + 'recovery_target_action = pause'); +$node_restore->append_conf('postgresql.conf', + 'max_wal_size = ' . 2 * $wal_segsize); +$node_restore->append_conf('postgresql.conf', 'log_checkpoints = on'); + +$node_restore->start; + +# Wait until restore has replayed enough data +my $caughtup_query = + "SELECT '$until_lsn'::pg_lsn <= pg_last_wal_replay_lsn()"; +$node_restore->poll_query_until('postgres', $caughtup_query) + or die "Timed out while waiting for restore to catch up"; + +$node_restore->stop; +ok(1, 'restore caught up'); + +done_testing(); --402OII5J8w+WWZaJ--