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 1uZTSb-0044bS-Kt for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jul 2025 11:59:38 +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 1uZTSY-00FxIU-Da for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jul 2025 11:59:35 +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 1uZTSX-00FxIG-MY for pgsql-hackers@lists.postgresql.org; Wed, 09 Jul 2025 11:59:34 +0000 Received: from fout-a8-smtp.messagingengine.com ([103.168.172.151]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1uZTSV-006OTz-37 for pgsql-hackers@lists.postgresql.org; Wed, 09 Jul 2025 11:59:33 +0000 Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id D5AA3EC04EE; Wed, 9 Jul 2025 07:59:30 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Wed, 09 Jul 2025 07:59:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kurilemu.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to; s=fm1; t=1752062370; x= 1752148770; bh=XUyvomGbxrkm4uGqK3cb4hBFPYEqS8UcYzn7EyXrsog=; b=X WCI4IxLz8P9sEG38U3s4UorrIk2CtyLYKz9iIyGE8tz5rXLO3UZeDU5/Y7tocp1y O3ZFPlRuPWNVChUYn1EKAaqF1wSEnDeRSTGFjp1Ly9H7KDuhRC9v5FzuokTJMkat S4cggaBhRA3nKQE2B2s29tZv1lqk4yM01xaOk0aN11KM/14ALv0u9lON0dUODoip JbMnAKR5Wxh6TaxGlLjZYmmTTetvScS9yZvQnCwaHg4xGyDJV+Z51CDY+fvRqSnS u7zUd9DwkJpsh79Uu32ze549QxoXM/rnPr2M4b81bvoxwFAp2wG4LVA/Tr12zJQK 7jp/AYPkKth7mSJP0CmHw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1752062370; x=1752148770; bh=X UyvomGbxrkm4uGqK3cb4hBFPYEqS8UcYzn7EyXrsog=; b=RWpVP1Lg4jb2E2+FP AHAGIPpGZ5fO7ttNRRmRixVKtEikSAMvk28fTN2uJ1CXsBP0Rs9zgI1wOdwXVHvw IMd1X6T+0wmG9jlCamYkrrOnyIxVRpGStuUigQjUKptuXxh0fEJQtl2qBljmoEZc jP6VzGW0qchXVu6XhQj1R5r6gaf+F4xGGSbypCD37xCUzifag2baUBUCdI4x3lAZ 0C7HzlOBMX1jnLcNDPVWQVcF81qmLf+kHsIlNRIpCAsxGkHDY6yf/AMjoQ/Q4EMS VrM10KZ+5o2H91kDqUNSOWg64ZLHySLUmn0kpfqEht07DkJvvXf+zgPZ1gRkW2p+ icRlw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdefjeehtdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfggtggugfgjsehmkeerredttdejnecuhfhrohhmpemllhhvrghrohcu jfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgeskhhurhhilhgvmhhurdguvgeqnecuggftrf grthhtvghrnhepgedutedujeehudevveegheejgeelveevvedvuedtjedtkeeuhfehheeg vedtjeetnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomhenucevlhhush htvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhvhhgvrhhrvges khhurhhilhgvmhhurdguvgdpnhgspghrtghpthhtohepjedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtoheprghmihhtrdhkrghpihhlrgduieesghhmrghilhdrtghomhdprhgt phhtthhopegshhgrrhgrthhhrdhruhhpihhrvgguugihfhhorhhpohhsthhgrhgvshesgh hmrghilhdrtghomhdprhgtphhtthhopeguihhlihhpsggrlhgruhhtsehgmhgrihhlrdgt ohhmpdhrtghpthhtohephhhorhhikhihohhtrgdrnhhtthesghhmrghilhdrtghomhdprh gtphhtthhopehsmhhithhhphgsvddvhedtsehgmhgrihhlrdgtohhmpdhrtghpthhtohep phhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpd hrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhush X-ME-Proxy: Feedback-ID: ie3de48e3:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 9 Jul 2025 07:59:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kurilemu.de; s=schmee; t=1752062368; bh=Jqb/pXeecf0inwf3fLs8rg4Q8cUZdgdMhlSzsbnjXec=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=sTFyUryi9KJGBdSwOLYhVhEEAoZjdZ9MPKlBn15COJT6T37CsyqCoNXSe7ZAGyReD P3Z+uQ8dNq2VLLALWGCs+6NbhKw7OyfUoMHWIpQGefC7TUArFdZFp+Ow+2NV4UyT5M CQU2hUP3WuFjFN4aUXyr71Y4hMC2SUcqEFjAT/4eyb4U7FkljxVXuRGIFIbCNP9iik JvWPk20/5CfypcexvlimEun6mWPRM846/DpWPHoySsToG4qbnIX9s7/mnYAMepLA1Y b3QteKrHhATuRDf1+R+5i7y+YMJMr2k5iAJdAiKChyWBQEfxS367qnwv70rlW6lLob nBBsRFDGTekrA== Received: by schmee.kurilemu.internal (Postfix, from userid 1000) id 6CA6390; Wed, 9 Jul 2025 13:59:28 +0200 (CEST) Date: Wed, 9 Jul 2025 13:59:28 +0200 From: =?utf-8?Q?=C3=81lvaro?= Herrera To: Dilip Kumar Cc: Amit Kapila , Tom Lane , Kyotaro Horiguchi , smithpb2250@gmail.com, bharath.rupireddyforpostgres@gmail.com, pgsql-hackers@lists.postgresql.org Subject: Re: A recent message added to pg_upgade Message-ID: <202507091159.4ml27tcusrvz@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="es5xf7qo3tbeuisb" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --es5xf7qo3tbeuisb Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On 2025-Jul-09, Dilip Kumar wrote: > On Wed, Jul 9, 2025 at 9:07 AM Dilip Kumar wrote: > > After further consideration, I believe your proposed method is > > superior to forcing the max_slot_wal_keep_size to -1 via a check hook. > > The ultimate goal is to prevent WAL removal during a binary upgrade, > > and your approach directly addresses this issue rather than > > controlling it by forcing the GUC value. I am planning to send a > > patch using this approach for both max_slot_wal_keep_size as well as > > for idle_replication_slot_timeout. > > PFA, with this approach. This indeed makes the whole thing a lot simpler and more direct than the original code, and solves this subthread's complaint. It's a bit weird that slot.c and xlog.c now have to worry about IsBinaryUpgrade, but I don't feel any guilt about that. I propose a few comment updates on top of your patch. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/ "Oh, great altar of passive entertainment, bestow upon me thy discordant images at such speed as to render linear thought impossible" (Calvin a la TV) --es5xf7qo3tbeuisb Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="comments.patch.txt" diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 91568024aed..304b60933c9 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -8131,25 +8131,22 @@ KeepLogSeg(XLogRecPtr recptr, XLogSegNo *logSegNo) XLByteToSeg(recptr, currSegNo, wal_segment_size); segno = currSegNo; - /* - * Calculate how many segments are kept by slots first, adjusting for - * max_slot_wal_keep_size. - */ + /* Calculate how many segments are kept by slots. */ keep = XLogGetReplicationSlotMinimumLSN(); if (keep != InvalidXLogRecPtr && keep < recptr) { XLByteToSeg(keep, segno, wal_segment_size); /* - * Avoid WAL removal by the checkpointer process during Binary - * upgrade. If WALs required by logical replication slots are removed, - * the slots are unusable. + * Account for max_slot_wal_keep_size to avoid keeping more than + * configured. However, don't do that during a binary upgrade: if + * slots were to be invalidated because of this, it would not be + * possible to preserve logical ones during the upgrade. */ if (max_slot_wal_keep_size_mb >= 0 && !IsBinaryUpgrade) { uint64 slot_keep_segs; - /* Cap by max_slot_wal_keep_size ... */ slot_keep_segs = ConvertToXSegs(max_slot_wal_keep_size_mb, wal_segment_size); diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 82c7d263f94..0e1e85d52cf 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -2036,7 +2036,7 @@ restart: if (!s->in_use) continue; - /* Prevent logical slot invalidation during binary upgrade. */ + /* Prevent invalidation of logical slots during binary upgrade. */ if (SlotIsLogical(s) && IsBinaryUpgrade) continue; --es5xf7qo3tbeuisb--