From: Álvaro Herrera <alvherre@kurilemu.de>
To: Dilip Kumar <dilipbalaut@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
Cc: smithpb2250@gmail.com
Cc: bharath.rupireddyforpostgres@gmail.com
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: A recent message added to pg_upgade
Date: Wed, 9 Jul 2025 13:59:28 +0200
Message-ID: <202507091159.4ml27tcusrvz@alvherre.pgsql> (raw)
In-Reply-To: <CAFiTN-veBzcXVxSfkD2qJrks9=d8mNv-_ZsaBSKMzAOPvkk2jQ@mail.gmail.com>
On 2025-Jul-09, Dilip Kumar wrote:
> On Wed, Jul 9, 2025 at 9:07 AM Dilip Kumar <dilipbalaut@gmail.com> 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)
Attachments:comments.patch.txt (text/plain, 1.8K) downloaddiff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.cindex 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.cindex 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;
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: alvherre@kurilemu.de, dilipbalaut@gmail.com, amit.kapila16@gmail.com, tgl@sss.pgh.pa.us, horikyota.ntt@gmail.com, smithpb2250@gmail.com, bharath.rupireddyforpostgres@gmail.com
Subject: Re: A recent message added to pg_upgade
In-Reply-To: <202507091159.4ml27tcusrvz@alvherre.pgsql>
References: <CAFiTN-veBzcXVxSfkD2qJrks9=d8mNv-_ZsaBSKMzAOPvkk2jQ@mail.gmail.com> <202507091159.4ml27tcusrvz@alvherre.pgsql>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox