Re: Clear logical slot's 'synced' flag on promotion of standby - Mailing list pgsql-hackers

From Ashutosh Sharma
Subject Re: Clear logical slot's 'synced' flag on promotion of standby
Date
Msg-id CAE9k0PmA5zT3Uru6AXGf3BGBPPisFsdRTTyhNy6t9_wm1tcVeg@mail.gmail.com
Whole thread Raw
In response to Re: Clear logical slot's 'synced' flag on promotion of standby  (shveta malik <shveta.malik@gmail.com>)
Responses Re: Clear logical slot's 'synced' flag on promotion of standby
List pgsql-hackers
Hi,

On Thu, Sep 11, 2025 at 9:17 AM shveta malik <shveta.malik@gmail.com> wrote:
>
> On Tue, Sep 9, 2025 at 2:19 PM Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> >
> > Hi,
> >
> >
> > + * required resources. Clear any leftover 'synced' flags on replication
> > + * slots when in crash recovery on the primary. The DB_IN_CRASH_RECOVERY
> > + * state check ensures that this code is only reached when a standby
> > + * server crashes during promotion.
> >   */
> >   StartupReplicationSlots();
> > + if (ControlFile->state == DB_IN_CRASH_RECOVERY)
> >
> > I believe the primary server can also enter the DB_IN_CRASH_RECOVERY
> > state. For example, if the primary is already in crash recovery and
> > crashes again while in crash recovery, it will restart in the
> > DB_IN_CRASH_RECOVERY state, no?
> >
>
> Yes, good point. I think we can differentiate the two cases based on
> the timeline change. A regular primary won't have a timeline change,
> whereas a promoted standby that failed during promotion will show a
> timeline change immediately upon restart. Thoughts?

We already read the recovery signal files (standby.signal or
recovery.signal) at the start of StartupXLOG() via InitWalRecovery(),
which sets the StandbyModeRequested flag. Couldn’t we use this to
distinguish whether the server is a primary undergoing crash recovery
or a standby?

>
>
I attempted to
> simulate a scenario where a regular standby ends up in
> DB_IN_CRASH_RECOVERY after a crash, but I couldn't reproduce it. Do
> you know of any situation where this could happen? The absence of
> comments for these states makes it challenging to follow the flow.
>

The log message for "case DB_IN_CRASH_RECOVERY:" inside StartupXLOG
should indicate that the server has entered crash recovery, no? And..
If you still want the server to crash while in this state, you could
add your own PANIC or FATAL error message inside the startupxlog.

--
With Regards,
Ashutosh Sharma.



pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: Conflict detection for update_deleted in logical replication
Next
From: "Chiranmoy.Bhattacharya@fujitsu.com"
Date:
Subject: Re: [PATCH] Hex-coding optimizations using SVE on ARM.