Re: Clear logical slot's 'synced' flag on promotion of standby

From: Ajin Cherian <itsajin(at)gmail(dot)com>
To: shveta malik <shveta(dot)malik(at)gmail(dot)com>
Cc: Ashutosh Sharma <ashu(dot)coek88(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Clear logical slot's 'synced' flag on promotion of standby
Date: 2025-09-23 07:40:49
Message-ID: CAFPTHDZdS97GusD-ot1gooXPHZtEnZ6N==J9Z5wmq3mQDqfYcg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Sep 19, 2025 at 7:26 PM shveta malik <shveta(dot)malik(at)gmail(dot)com> wrote:
>
>
> Please find a few comments:
>
> 1)
> + * Reset all replication slots that have synced=true to synced=false.
>
> Can we please change it to:
> Reset the synced flag to false for all replication slots where it is
> currently true.
>

Changed.

> 2)
> I was wondering that since we reset the sync flag everytime we load
> slots from disk , then do we even need ResetSyncedSlots() during
> promotion? But I guess we still need it because even after promotion
> (if not restarted), existing backend sessions stay alive and it makes
> sense if they too see 'synced' as false after promotion. Is it worth
> adding this in comments atop ResetSyncedSlots() call during promotion?
>

Yes, on promotion a server could run for a long time without ever
being restarted. Do we want slots to remain in the synced state until
the next restart? I think not. I think it's best to have the logic
both in the promotion path and in the restart path.
Added a comment in xlog.c for this.

> 3)
> + if (!StandbyMode)
> + slot->data.synced = false;
>
> a)
> Do we need to mark the slot as dirty so it gets saved to disk on the
> next chance?
>
> I think ReplicationSlotSave can be skipped, as it may not be
> appropriate in the restore flow. But marking the slot dirty is
> important to avoid resetting the sync flag again on the next startup.
> A crash between marking it dirty and persisting it would still require
> a reset, but that seems acceptable. Thoughts?
>
> b)
> Also if we are marking it dirty, it makes sense to set synced to false
> only after checking if synced is true already.

Changed this accordingly. Marking it as dirty also required acquiring
the slot and releasing it afterwards. I've also not checked for
logical slots, as if the synced flag is set, it should only be for
logical slots.

Attaching v3 with the above code changes.

regards,
Ajin Cherian
Fujitsu Australia

Attachment Content-Type Size
v3-0001-Reset-synced-slots-when-a-standby-is-promoted.patch application/octet-stream 7.9 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2025-09-23 07:50:33 Fix incorrect function comment of stringToNodeInternal
Previous Message Vaibhav Jain 2025-09-23 07:39:34 Re: Fix overflow of nbatch