Persist slot invalidations before publishing them

Поиск
Список
Период
Сортировка
Искать

Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi hackers,

while reviewing [1], I hit an issue due to the fact that an inactive replication
slot is marked invalid in shared memory before its new state is persisted.

If ReplicationSlotSave() errors before replacing the state file, the slot is
invalid in shared memory but still valid on disk. That sounds problematic as the
resource horizon computations could stop accounting for the slot, remove required
WAL or rows, and then an immediate restart would restore the old valid slot image.

The same issue exists in synchronize_one_slot(): it copies the invalidation from
the remote slot into the local synchronized slot before saving it. In that case,
a save error also prevents a direct retry because the next synchronization sees
the local slot as already invalid and skips it.

The InvalidatePossiblyObsoleteSlot() ordering seems to come from c6550776394e.
4ae08cd5fd19 later made those invalidations persistent but kept the same ordering.

PFA a patch series to $SUBJECT.

It introduces ReplicationSlotPersistInvalidation(), which creates an invalidated
copy of the acquired slot and writes it while the shared slot remains valid.

That means that a concurrent slot saver either writes the old valid state before
the invalidation operation, or waits and snapshots the invalid state after it has
been published. If the invalidated image can not be written, both the shared and
on disk states remain valid.

This is the same kind of idea used of effective_catalog_xmin and in 3741f2a09d52.

The patch series is organized that way:

0001: persist InvalidatePossiblyObsoleteSlot() invalidations before publishing
them.

Add ReplicationSlotPersistInvalidation(), which writes and fsyncs an invalidated
copy while the shared slot remains valid. Hold io_in_progress_lock until the
invalidation is published so checkpoints and other slot savers cannot persist
a stale image after publication.

It also adds an injection point and some tests.

0002: do the same for synchronize_one_slot().

It keeps the synchronized slot restart LSN when copying a WAL invalidation,
preserving the current behavior. It also recomputes the xmin and WAL horizons
once the invalidation is durable and visible.

It also adds some test.

Remarks:

1/ there is no new retry mechanism. A later checkpoint or synchronization
naturally retries because the shared slot remains valid after the error.

2/ the patches change neither the on disk slot format nor the ReplicationSlot
shared memory layout. It has been done that way to ease the back patching.

3/ I think 0001 should be backpatched down to 14. 14 and 15 would probably need
some adaptations though (I did not look in detail yet).

4/ 0002 should be backpatched down to 17, where failover slot synchronization was
introduced.


[1]: https://postgr.es/m/CALj2ACUi0LeqKzomuXNPFsekzuQ%2BXbWZ5RamnO6tDzG4i1-KLw%40mail.gmail.com

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
Rui Zhao <zhaorui126@gmail.com>
Дата:
Вложения:
Hi,

Thanks for v2. I made the save fail with the injection point of 0001,
and the slot comes out of it fine: still valid, released by the
checkpointer, and I can drop it. On master the same failure leaves it
invalid but still owned by the checkpointer, and the next checkpoint
does not fix that:

 active|active_pid|invalidation_reason|restart_lsn|wal_status
 t|259023|wal_removed||lost

 SELECT pg_drop_replication_slot('target_slot');
 ERROR:  replication slot "target_slot" is active for PID 259023

> If a second invalidator reaches the same slot in that window (say a
> restartpoint enforcing max_slot_wal_keep_size while startup is replaying
> a wal_level change, or the other way round), it seems it would take the
> "slot is in use" path, so startup might send a recovery conflict to
> active_pid, or another process a SIGTERM. What do you think?

Both happen, and the SIGTERM shuts the standby down. 0003 makes the
second invalidator wait for the first one instead, and adds a test with
the two processes in both orders.

The standby has max_slot_wal_keep_size = 1MB, a logical slot 8 segments
of 1MB behind, and the injection point of 0001 attached with 'wait' for
that slot. The primary is restarted with wal_level = replica, so that the
startup process invalidates the slot, and once it waits at the injection
point, CHECKPOINT on the standby:

 checkpointer LOG:  restartpoint starting: fast wait
 checkpointer LOG:  terminating process 378422 to release replication
slot "startup_first"
 checkpointer DETAIL:  The slot's restart_lsn 0/012002D0 exceeds the
limit by 7339312 bytes.
 startup LOG:  invalidating obsolete replication slot "startup_first"
 postmaster LOG:  startup process (PID 378422) exited with exit code 1
 postmaster LOG:  terminating any other active server processes
 postmaster LOG:  shutting down due to startup process failure

The other way round, the startup process finds the slot held by the
checkpointer and sends it a recovery conflict. The checkpointer errors
out at its next CHECK_FOR_INTERRUPTS(), and the startup process then
invalidates the slot itself:

 startup LOG:  terminating process 378420 to release replication slot
"checkpointer_first"
 checkpointer ERROR:  canceling statement due to conflict with recovery
 client backend ERROR:  checkpoint request failed
 startup LOG:  invalidating obsolete replication slot "checkpointer_first"

On master the slot is marked invalid under the spinlock at the moment it
is claimed, so the second invalidator sees the invalidation and does
nothing.

0003 takes the slot's io_in_progress_lock before looking at the slot,
and holds it from claiming the slot until the invalidation is published;
0001 holds it for the write only. Whoever comes second then sees either
an invalidated slot or one nobody is working on, and only signals a
process that really uses the slot. If the lock is not free, the function
drops ReplicationSlotControlLock, waits for it, and starts over, the same
way it does around the condition variable sleep. The test fails on v2 as
above and passes with 0003.

The side effects of 0003, as far as I can see:

(a) The second invalidator now waits (wait event ReplicationSlotIO)
instead of signalling; on master it never waited. The wait is one write
and fsync of the slot's state file, and only when two processes go for
the same slot at the same time.

(b) Every pass over the slots now takes and releases each in-use slot's
io_in_progress_lock once. A checkpoint's pass over N valid physical
slots, median of 60 checkpoints:

 N     v2         0003
 10    1.5 us     1.6 us
 100   7.2 us     9.0 us

A pass that finds a slot being written waits for that write, without
ReplicationSlotControlLock.

(c) The two locks cannot deadlock: no holder of an io_in_progress_lock
takes ReplicationSlotControlLock, since the callers of SaveSlotToPath()
hold ReplicationSlotAllocationLock at most, and the slot is not in use
yet when CreateSlotOnDisk() writes it. The second invalidator holds
nothing while it waits. Nothing changes for a slot that is really in use:
a walsender's slot, or a temporary slot of an idle session, is signalled
as before.

(d) Not covered: synchronize_one_slot() acquires the slot before it
takes the lock, so a restartpoint that looks at the slot in between still
terminates the slot sync worker. Master has the same window, between
acquiring the slot and publishing; closing it would take a flag in the
slot's shared memory.

I think 0003 is small enough to be backpatched with 0001.

Regards,
Rui

Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi JoongHyuk,

On Sun, Sep 13, 2026 at 07:31:57PM +0900, JoongHyuk Shin wrote:
> Hi Bertrand,
> 
> I read v2 and have a question about the window the new ordering opens
> between two invalidators.

Thanks for looking at it!

> If a second invalidator reaches the
> same slot in that window (say a restartpoint enforcing
> max_slot_wal_keep_size while startup is replaying a wal_level change, or
> the other way round), it seems it would take the "slot is in use" path,
> so startup might send a recovery conflict to active_pid, or another
> process a SIGTERM. What do you think?

You're right, v2 could treat the first invalidator as a regular slot user and
terminate it.

Rui, thanks for the patch! I've incorporated its locking approach and test coverage
in v3, with some adjustments around error cleanup.

Please find v3 attached.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Sep 22, 2026 at 1:58 PM Bertrand Drouvot
 wrote:
>
> Hi JoongHyuk,
>
> On Sun, Sep 13, 2026 at 07:31:57PM +0900, JoongHyuk Shin wrote:
> > Hi Bertrand,
> >
> > I read v2 and have a question about the window the new ordering opens
> > between two invalidators.
>
> Thanks for looking at it!
>
> > If a second invalidator reaches the
> > same slot in that window (say a restartpoint enforcing
> > max_slot_wal_keep_size while startup is replaying a wal_level change, or
> > the other way round), it seems it would take the "slot is in use" path,
> > so startup might send a recovery conflict to active_pid, or another
> > process a SIGTERM. What do you think?
>
> You're right, v2 could treat the first invalidator as a regular slot user and
> terminate it.
>
> Rui, thanks for the patch! I've incorporated its locking approach and test coverage
> in v3, with some adjustments around error cleanup.
>
> Please find v3 attached.
>

I had a look at 002 to review slotsync path, I had one concern:

+ /*
+ * A failed invalidation can still hold the slot's I/O lock. Release it
+ * before slot cleanup acquires ReplicationSlotAllocationLock, which
+ * checkpoints hold while acquiring slot I/O locks.
+ */
+ LWLockReleaseAll();
+

Could it be problematic to call LWLockReleaseAll() inside a localized
error cleanup callback (PG_ENSURE_ERROR_CLEANUP) rather than waiting
for AbortTransaction or proc_exit? Since the goal is just to avoid
deadlock with the Checkpointer, shouldn't we explicitly release that
one specific lock?
if (MyReplicationSlot != NULL &&
LWLockHeldByMe(&MyReplicationSlot->io_in_progress_lock))
{
     LWLockRelease(&MyReplicationSlot->io_in_progress_lock);
 }

I don't have an exact scenario to worry about, but it seems like
overkill. Thoughts?

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Tue, Sep 22, 2026 at 03:46:55PM +0530, shveta malik wrote:
> I had a look at 002 to review slotsync path,

Thanks for looking at it!

> + /*
> + * A failed invalidation can still hold the slot's I/O lock. Release it
> + * before slot cleanup acquires ReplicationSlotAllocationLock, which
> + * checkpoints hold while acquiring slot I/O locks.
> + */
> + LWLockReleaseAll();
> +
> 
> Could it be problematic to call LWLockReleaseAll() inside a localized
> error cleanup callback (PG_ENSURE_ERROR_CLEANUP) rather than waiting
> for AbortTransaction or proc_exit? Since the goal is just to avoid
> deadlock with the Checkpointer, shouldn't we explicitly release that
> one specific lock?
> if (MyReplicationSlot != NULL &&
> LWLockHeldByMe(&MyReplicationSlot->io_in_progress_lock))
> {
>      LWLockRelease(&MyReplicationSlot->io_in_progress_lock);
>  }
> 
> I don't have an exact scenario to worry about, but it seems like
> overkill. Thoughts?

Yeah, it's probably better to be specific here.

One concern with the proposed check is that all existing uses of LWLockHeldByMe()
appear to be for assertions or debugging (as documented on top of LWLockHeldByMe()).

Also, releasing an LWLock after ERROR requires restoring the interrupt holdoff
expected by LWLockRelease().

Another possibility would be to make ReplicationSlotPersistInvalidation() always
leave the caller acquired I/O lock held. Slotsync could then release that specific
lock in a PG_CATCH() block, something like:

"
  PG_CATCH();
  {
        HOLD_INTERRUPTS();
        LWLockRelease(&slot->io_in_progress_lock);
        PG_RE_THROW();
  }
  PG_END_TRY();

  LWLockRelease(&slot->io_in_progress_lock);
"

This would avoid both LWLockReleaseAll() and using LWLockHeldByMe() for normal
control flow. Does that sound preferable?

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Wed, Sep 23, 2026 at 11:37 AM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Tue, Sep 22, 2026 at 03:46:55PM +0530, shveta malik wrote:
> > I had a look at 002 to review slotsync path,
>
> Thanks for looking at it!
>
> > + /*
> > + * A failed invalidation can still hold the slot's I/O lock. Release it
> > + * before slot cleanup acquires ReplicationSlotAllocationLock, which
> > + * checkpoints hold while acquiring slot I/O locks.
> > + */
> > + LWLockReleaseAll();
> > +
> >
> > Could it be problematic to call LWLockReleaseAll() inside a localized
> > error cleanup callback (PG_ENSURE_ERROR_CLEANUP) rather than waiting
> > for AbortTransaction or proc_exit? Since the goal is just to avoid
> > deadlock with the Checkpointer, shouldn't we explicitly release that
> > one specific lock?
> > if (MyReplicationSlot != NULL &&
> > LWLockHeldByMe(&MyReplicationSlot->io_in_progress_lock))
> > {
> >      LWLockRelease(&MyReplicationSlot->io_in_progress_lock);
> >  }
> >
> > I don't have an exact scenario to worry about, but it seems like
> > overkill. Thoughts?
>
> Yeah, it's probably better to be specific here.
>
> One concern with the proposed check is that all existing uses of LWLockHeldByMe()
> appear to be for assertions or debugging (as documented on top of LWLockHeldByMe()).

Oh Okay, I missed this point earlier.

> Also, releasing an LWLock after ERROR requires restoring the interrupt holdoff
> expected by LWLockRelease().

Okay.

> Another possibility would be to make ReplicationSlotPersistInvalidation() always
> leave the caller acquired I/O lock held. Slotsync could then release that specific
> lock in a PG_CATCH() block, something like:

Yes, I agree. I find this approach much better for 2 reasons:

1) The caller has better control over the lock, which makes sense
since it is the one acquiring it.
2)  It makes the code much more understandable. Earlier, it took me a
while to figure out exactly where the io_in_progress_lock was getting
released, especially looking at the slotsync patch where it was
acquired right before calling ReplicationSlotPersistInvalidation().

> "
>   PG_CATCH();
>   {
>         HOLD_INTERRUPTS();
>         LWLockRelease(&slot->io_in_progress_lock);
>         PG_RE_THROW();
>   }
>   PG_END_TRY();
>
>   LWLockRelease(&slot->io_in_progress_lock);
> "
>
> This would avoid both LWLockReleaseAll() and using LWLockHeldByMe() for normal
> control flow. Does that sound preferable?

Yes.

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Wed, Sep 23, 2026 at 12:00:39PM +0530, shveta malik wrote:
> On Wed, Sep 23, 2026 at 11:37 AM Bertrand Drouvot
>  wrote:
> >
> > Another possibility would be to make ReplicationSlotPersistInvalidation() always
> > leave the caller acquired I/O lock held. Slotsync could then release that specific
> > lock in a PG_CATCH() block, something like:
> 
> Yes, I agree. I find this approach much better for 2 reasons:
> 
> 1) The caller has better control over the lock, which makes sense
> since it is the one acquiring it.
> 2)  It makes the code much more understandable. Earlier, it took me a
> while to figure out exactly where the io_in_progress_lock was getting
> released, especially looking at the slotsync patch where it was
> acquired right before calling ReplicationSlotPersistInvalidation().
> 
> > "
> >   PG_CATCH();
> >   {
> >         HOLD_INTERRUPTS();
> >         LWLockRelease(&slot->io_in_progress_lock);
> >         PG_RE_THROW();
> >   }
> >   PG_END_TRY();
> >
> >   LWLockRelease(&slot->io_in_progress_lock);
> > "
> >
> > This would avoid both LWLockReleaseAll() and using LWLockHeldByMe() for normal
> > control flow. Does that sound preferable?
> 
> Yes.

Thanks! Done that way in v4 attached.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
Вложения:
On Wed, Sep 23, 2026 at 2:08 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Wed, Sep 23, 2026 at 12:00:39PM +0530, shveta malik wrote:
> > On Wed, Sep 23, 2026 at 11:37 AM Bertrand Drouvot
> >  wrote:
> > >
> > > Another possibility would be to make ReplicationSlotPersistInvalidation() always
> > > leave the caller acquired I/O lock held. Slotsync could then release that specific
> > > lock in a PG_CATCH() block, something like:
> >
> > Yes, I agree. I find this approach much better for 2 reasons:
> >
> > 1) The caller has better control over the lock, which makes sense
> > since it is the one acquiring it.
> > 2)  It makes the code much more understandable. Earlier, it took me a
> > while to figure out exactly where the io_in_progress_lock was getting
> > released, especially looking at the slotsync patch where it was
> > acquired right before calling ReplicationSlotPersistInvalidation().
> >
> > > "
> > >   PG_CATCH();
> > >   {
> > >         HOLD_INTERRUPTS();
> > >         LWLockRelease(&slot->io_in_progress_lock);
> > >         PG_RE_THROW();
> > >   }
> > >   PG_END_TRY();
> > >
> > >   LWLockRelease(&slot->io_in_progress_lock);
> > > "
> > >
> > > This would avoid both LWLockReleaseAll() and using LWLockHeldByMe() for normal
> > > control flow. Does that sound preferable?
> >
> > Yes.
>
> Thanks! Done that way in v4 attached.
>

Can we create the helper function for this logic as it is not core to
the sync-function. Please use the attached patch if you agree, and
feel free to change comments as you see apt.

This approach is better for one more reason: v3 was only releasing the
I/O lock locally during the API call (via slotsync_failure_callback),
leaving the slot-sync worker to rely on top-level proc_exit perhaps.
Current approach ensures consistent lock lifecycle handling for both
the worker and the API.

thanks
Shhveta

Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Wed, Sep 23, 2026 at 04:07:02PM +0530, shveta malik wrote:
> Can we create the helper function for this logic as it is not core to
> the sync-function. Please use the attached patch if you agree, and
> feel free to change comments as you see apt.

I was initially a bit skeptical about adding a helper with only one caller, as it
seemed to just move the PG_TRY() block elsewhere without reducing duplication.

On second thought, I agree it makes sense here, as it keeps the lock acquisition
and required ERROR cleanup ordering together. There are also similar "one caller"
helpers wrapping PG_TRY() blocks, such as start_table_sync() and start_sequence_sync().

+static void
+persist_slot_invalidation(ReplicationSlot *slot, ReplicationSlotInvalidationCause cause)
+{

I changed it slightly to derive slot from MyReplicationSlot, ensuring that the I/O
lock belongs to the same slot that ReplicationSlotPersistInvalidation() and
and ReplicationSlotRelease() are using. This is also consistent with other operations
on the currently acquired slot.

Please find v5 attached.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Wed, Sep 23, 2026 at 9:35 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Wed, Sep 23, 2026 at 04:07:02PM +0530, shveta malik wrote:
> > Can we create the helper function for this logic as it is not core to
> > the sync-function. Please use the attached patch if you agree, and
> > feel free to change comments as you see apt.
>
> I was initially a bit skeptical about adding a helper with only one caller, as it
> seemed to just move the PG_TRY() block elsewhere without reducing duplication.
>
> On second thought, I agree it makes sense here, as it keeps the lock acquisition
> and required ERROR cleanup ordering together. There are also similar "one caller"
> helpers wrapping PG_TRY() blocks, such as start_table_sync() and start_sequence_sync().
>
> +static void
> +persist_slot_invalidation(ReplicationSlot *slot, ReplicationSlotInvalidationCause cause)
> +{
>
> I changed it slightly to derive slot from MyReplicationSlot, ensuring that the I/O
> lock belongs to the same slot that ReplicationSlotPersistInvalidation() and
> and ReplicationSlotRelease() are using. This is also consistent with other operations
> on the currently acquired slot.

Yes, that makes sense.

> Please find v5 attached.

Code changes looks good to me. Regarding the test, I have one trivial
comment: I think we should cover all the cases:

a) Failed sync: Memory is NOT updated.
b) Successful sync: Memory IS updated.
c) Server restart: Memory is STILL updated (because it was recovered
from disk).

I think b) is not covered. It will be good to check the memory state
before standby-stop here:

$standby->safe_psql('postgres', 'SELECT pg_sync_replication_slots()');

$standby->stop('immediate');
$standby->start;

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
I had a look at patch001 as well.  I have 2 questions:

1)
Would it be better to use a PG_TRY/PG_CATCH block in patch 001,
similar to patch 002? Currently, the slot is released via
PG_ENSURE_ERROR_CLEANUP, while we rely on top-level error cleanup for
lock-release. Using TRY/CATCH would let us explicitly release both the
slot and I/O lock together, making the error handling consistent
across both patches. We could even reuse persist_slot_invalidation()
with a small change to pass update_inactive_since from the caller.

2)
+ /* Let caller know */
+ invalidated = true;
+ LWLockRelease(&s->io_in_progress_lock);
  ReplicationSlotRelease();

Wouldn't it be better (and safer) to release the slot before releasing
the I/O lock?

Currently, concurrent invalidators are protected by the
'invalidation_cause == RS_INVAL_NONE' check after acquiring the lock.
But releasing the slot first would close this race window entirely. It
would also make the order consistent with Patch 002 and the
error-handling flow in Patch 001 itself.

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Thu, Sep 24, 2026 at 10:55:03AM +0530, shveta malik wrote:
> I had a look at patch001 as well.  I have 2 questions:
> 
> 1)
> Would it be better to use a PG_TRY/PG_CATCH block in patch 001,
> similar to patch 002? Currently, the slot is released via
> PG_ENSURE_ERROR_CLEANUP, while we rely on top-level error cleanup for
> lock-release. Using TRY/CATCH would let us explicitly release both the
> slot and I/O lock together, making the error handling consistent
> across both patches. We could even reuse persist_slot_invalidation()
> with a small change to pass update_inactive_since from the caller.

Yeah, makes sense. I changed 0001 to use PG_TRY/PG_CATCH and moved the common
cleanup into ReplicationSlotPersistInvalidation(), with update_inactive_since
passed by the caller.

The I/O lock is still acquired by each caller because 0001 must hold it before
claiming the inactive slot to serialize concurrent internal invalidators.

> 2)
> + /* Let caller know */
> + invalidated = true;
> + LWLockRelease(&s->io_in_progress_lock);
>   ReplicationSlotRelease();
> 
> Wouldn't it be better (and safer) to release the slot before releasing
> the I/O lock?
> 
> Currently, concurrent invalidators are protected by the
> 'invalidation_cause == RS_INVAL_NONE' check after acquiring the lock.
> But releasing the slot first would close this race window entirely. It
> would also make the order consistent with Patch 002 and the
> error-handling flow in Patch 001 itself.

The current ordering should be safe because the invalidation has already been
published, so a concurrent invalidator exits before considering active_proc.

That said, I agree that releasing the slot first means this ordering no longer
relies on that check and makes the success and error paths consistent. So, done
in the attached.

It also adds the check you suggested for the synchronized slot's shared memory
state after a successful synchronization.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Thu, Sep 24, 2026 at 3:11 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Thu, Sep 24, 2026 at 10:55:03AM +0530, shveta malik wrote:
> > I had a look at patch001 as well.  I have 2 questions:
> >
> > 1)
> > Would it be better to use a PG_TRY/PG_CATCH block in patch 001,
> > similar to patch 002? Currently, the slot is released via
> > PG_ENSURE_ERROR_CLEANUP, while we rely on top-level error cleanup for
> > lock-release. Using TRY/CATCH would let us explicitly release both the
> > slot and I/O lock together, making the error handling consistent
> > across both patches. We could even reuse persist_slot_invalidation()
> > with a small change to pass update_inactive_since from the caller.
>
> Yeah, makes sense. I changed 0001 to use PG_TRY/PG_CATCH and moved the common
> cleanup into ReplicationSlotPersistInvalidation(), with update_inactive_since
> passed by the caller.
>
> The I/O lock is still acquired by each caller because 0001 must hold it before
> claiming the inactive slot to serialize concurrent internal invalidators.

Yes, makes sense.

> > 2)
> > + /* Let caller know */
> > + invalidated = true;
> > + LWLockRelease(&s->io_in_progress_lock);
> >   ReplicationSlotRelease();
> >
> > Wouldn't it be better (and safer) to release the slot before releasing
> > the I/O lock?
> >
> > Currently, concurrent invalidators are protected by the
> > 'invalidation_cause == RS_INVAL_NONE' check after acquiring the lock.
> > But releasing the slot first would close this race window entirely. It
> > would also make the order consistent with Patch 002 and the
> > error-handling flow in Patch 001 itself.
>
> The current ordering should be safe because the invalidation has already been
> published, so a concurrent invalidator exits before considering active_proc.

Oh I see. I missed this point earlier.

> That said, I agree that releasing the slot first means this ordering no longer
> relies on that check and makes the success and error paths consistent. So, done
> in the attached.
>
> It also adds the check you suggested for the synchronized slot's shared memory
> state after a successful synchronization.
>

Thanks for addressing comments. A few concerns on 001:

1)

In SaveSlotToPath(), should we add an 'Assert(cp.slotdata.restart_lsn
== InvalidXLogRecPtr)' at the end for the 'if (clear_restart_lsn)'
case?

                slot->data.invalidated = invalidation_cause;
                if (clear_restart_lsn)
+               {
+                       Assert(cp.slotdata.restart_lsn == InvalidXLogRecPtr);
                        slot->data.restart_lsn = InvalidXLogRecPtr;
+               }

While slot->last_saved_restart_lsn correctly inherits
cp.slotdata.restart_lsn on the next line, adding this Assert
guarantees that the removed logic from
InvalidatePossiblyObsoleteSlot() was successfully compensated for in
the on-disk struct before we propagate it to shared memory. It is not
mandatory, but it would be good to have.

2)
+ Assert(update_inactive_since || slot->data.persistency == RS_PERSISTENT);

In ReplicationSlotReleaseInternal(), I didn’t quite understand the
reasoning behind above Assert.  Does this mean that when the caller
passes update_inactive_since=true, the slot can even be temporary,
whereas if we are not updating inactive_since, the slot must be
persistent?

Is this based on the fact that slotsync passes update_inactive_since =
true and can have a temporary slot here? If so, that is not very clear
from the Assert itself. If we want to retain this check, should we
instead move the 'update_inactive_since ||' part to patch 002? IIUC,
patch 001 seems to strictly require RS_PERSISTENT. Let me know if I
understand it wrong.

I’m not sure what else we can do to make this clearer, but I think at
least a comment explaining why a temporary slot is allowed in this
case (update_inactive_since=true) would help.

3)
Another doubt I have is that with above Assert, when
update_inactive_since is TRUE, we are even allowing RS_EPHEMERAL
slots. However, ReplicationSlotPersistInvalidation() explicitly
disallows them in patch002 with:

Assert(slot->data.persistency != RS_EPHEMERAL);

Both checks are not in sync.

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Fri, Sep 25, 2026 at 09:38:27AM +0530, shveta malik wrote:
> On Thu, Sep 24, 2026 at 3:11 PM Bertrand Drouvot
>  wrote:
> >
> 
> Thanks for addressing comments. A few concerns on 001:

Thanks for looking at it!

> 1)
> 
> In SaveSlotToPath(), should we add an 'Assert(cp.slotdata.restart_lsn
> == InvalidXLogRecPtr)' at the end for the 'if (clear_restart_lsn)'
> case?
> 
>                 slot->data.invalidated = invalidation_cause;
>                 if (clear_restart_lsn)
> +               {
> +                       Assert(cp.slotdata.restart_lsn == InvalidXLogRecPtr);
>                         slot->data.restart_lsn = InvalidXLogRecPtr;
> +               }
> 
> While slot->last_saved_restart_lsn correctly inherits
> cp.slotdata.restart_lsn on the next line, adding this Assert
> guarantees that the removed logic from
> InvalidatePossiblyObsoleteSlot() was successfully compensated for in
> the on-disk struct before we propagate it to shared memory. It is not
> mandatory, but it would be good to have.

I’m not sure this assertion adds much, since cp.slotdata.restart_lsn is explicitly
cleared above and is not modified afterward.

> 2)
> + Assert(update_inactive_since || slot->data.persistency == RS_PERSISTENT);
> 
> In ReplicationSlotReleaseInternal(), I didn’t quite understand the
> reasoning behind above Assert.  Does this mean that when the caller
> passes update_inactive_since=true, the slot can even be temporary,
> whereas if we are not updating inactive_since, the slot must be
> persistent?

Yes. In fact, with update_inactive_since=true it can also be ephemeral, since
ReplicationSlotRelease() uses that value for the ordinary release path.

This is not specific to slotsync. The false case is introduced by 0001 and is
only used to preserve inactive_since when rolling back ownership of an inactive
persistent slot.

Maybe the following comment would make that clearer?

"
  /*
   * Skipping the inactive_since update is only needed when undoing the
   * internal acquisition of an inactive persistent slot after an ERROR.
   */
"

> 3)
> Another doubt I have is that with above Assert, when
> update_inactive_since is TRUE, we are even allowing RS_EPHEMERAL
> slots. However, ReplicationSlotPersistInvalidation() explicitly
> disallows them in patch002 with:
> 
> Assert(slot->data.persistency != RS_EPHEMERAL);
> 
> Both checks are not in sync.

I think they apply to different scopes. ReplicationSlotReleaseInternal() is the
general release implementation, so update_inactive_since=true imposes no
persistency restriction. In particular, an ephemeral slot is dropped by that
path.

ReplicationSlotPersistInvalidation() has a narrower contract and is only
intended for persistent or temporary slots. That said, maybe its Assert could
express all the supported combinations more clearly?

"
  Assert(slot->data.persistency == RS_PERSISTENT ||
         (slot->data.persistency == RS_TEMPORARY &&
          update_inactive_since));
"

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
Rui Zhao <zhaorui126@gmail.com>
Дата:
On 2026-Sep-25 at 05:54 UTC, Bertrand Drouvot wrote:
> ReplicationSlotPersistInvalidation() has a narrower contract and is only
> intended for persistent or temporary slots.

Since this function also handles temporary slots, could we qualify
the following sentence in 0002's commit message?

> A failed save now leaves the local slot valid, allowing the next
> synchronization to retry.

Could we change that to:

    A failed save now leaves a persistent local slot valid, allowing the
    next synchronization to retry.

I suggest adding "persistent" because SQL error cleanup deletes
temporary synchronized slots. In my v6 test:

1. I ran pg_sync_replication_slots() on the standby. The local
   pending_slot remained temporary because the primary slot's
   restart_lsn was behind the standby slot's restart_lsn.

2. While that call was still running, I made
   pg_replslot/pending_slot/state.tmp a directory on the standby, then
   invalidated pending_slot on the primary (wal_removed).
   Synchronization then tried to save that invalidation on the standby.
   The save failed with "File exists", and error cleanup deleted the
   temporary slot.

3. I called pg_sync_replication_slots() again in the same connection.
   It completed without error but did not recreate pending_slot because
   the primary slot was already invalidated.

Regards,
Rui


Re: Persist slot invalidations before publishing them

От:
Zhijie Hou <houzhijie22@gmail.com>
Дата:
Hi,

On Thu, Sep 24, 2026 at 5:41 PM Bertrand Drouvot
 wrote:
> On Thu, Sep 24, 2026 at 10:55:03AM +0530, shveta malik wrote:
> > 2)
> > + /* Let caller know */
> > + invalidated = true;
> > + LWLockRelease(&s->io_in_progress_lock);
> >   ReplicationSlotRelease();
> >
> > Wouldn't it be better (and safer) to release the slot before releasing
> > the I/O lock?
> >
> > Currently, concurrent invalidators are protected by the
> > 'invalidation_cause == RS_INVAL_NONE' check after acquiring the lock.
> > But releasing the slot first would close this race window entirely. It
> > would also make the order consistent with Patch 002 and the
> > error-handling flow in Patch 001 itself.
>
> The current ordering should be safe because the invalidation has already been
> published, so a concurrent invalidator exits before considering active_proc.
>
> That said, I agree that releasing the slot first means this ordering no longer
> relies on that check and makes the success and error paths consistent. So, done
> in the attached.
>
> It also adds the check you suggested for the synchronized slot's shared memory
> state after a successful synchronization.

Thanks for updating the patches.

When reading the patches, the part that feels heavy to me is the serialization
machinery added to InvalidatePossiblyObsoleteSlot() for the two-invalidator
race - the conditional acquire of io_in_progress_lock, dropping
ReplicationSlotControlLock to wait, and the restart of the loop - plus the
caller-owns-the-io-lock contract that ReplicationSlotPersistInvalidation()
imposes on both call sites. I understand why it's needed once claim and publish
stop being atomic (the SIGTERM that kills the startup process and shuts down
the standby is nasty), but I wonder if we can avoid making them non-atomic in
the first place.

You mentioned effective_catalog_xmin, and there are similar shadow fields like
last_saved_restart_lsn. What about the same style here: keep the claim exactly
as on master - active_proc and data.invalidated set in one spinlock section -
and add a pure in-memory boolean, say invalidation_durable, set only at the
point the invalid image has actually been written and fsynced (the tail of
SaveSlotToPath(), keyed off the image just written. All consumer references to
data.invalidated (horizon computations, pg_replication_slots, slotsync's
skip/drop decisions) would consult the new flag instead; the invalidators'
mutual-exclusion check and the acquire path keep reading the cause as today.

The new flag can be added to the padding space, so there is no change in the
size of ReplicationSlot.

I'm not insisting that we change the approach, just wanted to share an
alternative for discussion.

Best Regards,
Zhijie Hou


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Sun, Sep 27, 2026 at 10:10:33PM +0800, Zhijie Hou wrote:
> When reading the patches,

Thanks for looking at it!

> the part that feels heavy to me is the serialization
> machinery added to InvalidatePossiblyObsoleteSlot() for the two-invalidator
> race - the conditional acquire of io_in_progress_lock, dropping
> ReplicationSlotControlLock to wait, and the restart of the loop - plus the
> caller-owns-the-io-lock contract that ReplicationSlotPersistInvalidation()
> imposes on both call sites.

That might look heavy but I don't think this pattern is unusual: SLRU uses the
same general lock, wait, and recheck pattern, and InvalidatePossiblyObsoleteSlot()
already follows that model when waiting on active_cv.

> You mentioned effective_catalog_xmin, and there are similar shadow fields like
> last_saved_restart_lsn. What about the same style here: keep the claim exactly
> as on master - active_proc and data.invalidated set in one spinlock section -
> and add a pure in-memory boolean, say invalidation_durable, set only at the
> point the invalid image has actually been written and fsynced (the tail of
> SaveSlotToPath(), keyed off the image just written. All consumer references to
> data.invalidated (horizon computations, pg_replication_slots, slotsync's
> skip/drop decisions) would consult the new flag instead; the invalidators'
> mutual-exclusion check and the acquire path keep reading the cause as today.

I'm not sure the alternative is lighter overall. It moves the complexity into
a new intermediate slot state and requires each consumer of data.invalidated to
decide whether it should also check invalidation_durable.

> The new flag can be added to the padding space, so there is no change in the
> size of ReplicationSlot.

Yeah that look ok if, for example, we place it here:

(gdb) ptype /o struct ReplicationSlot
/* offset      |    size */  type = struct ReplicationSlot {
/*      0      |       1 */    slock_t mutex;
/*      1      |       1 */    _Bool in_use;
/* XXX  2-byte hole      */
/*      4      |       4 */    ProcNumber active_proc;
/*      8      |       1 */    _Bool just_dirtied;
/*      9      |       1 */    _Bool dirty;
/* XXX  2-byte hole      */
/*     12      |       4 */    TransactionId effective_xmin;
.
.
.

My concern is that data.invalidated would then have two roles depending on
invalidation_durable. Invalidators and the acquisition path would treat a value
other than RS_INVAL_NONE as an invalidation, while other consumers would do so
only once invalidation_durable is set.

That could be an issue for existing extensions on back branches. An extension
could treat the slot as invalid while core consumers gated by invalidation_durable
still treat the invalidation as not effective. So, although the ABI layout would
be preserved, the semantics of an existing field would change.

Thoughts?

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Sep 28, 2026 at 1:16 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Sun, Sep 27, 2026 at 10:10:33PM +0800, Zhijie Hou wrote:
> > When reading the patches,
>
> Thanks for looking at it!
>
> > the part that feels heavy to me is the serialization
> > machinery added to InvalidatePossiblyObsoleteSlot() for the two-invalidator
> > race - the conditional acquire of io_in_progress_lock, dropping
> > ReplicationSlotControlLock to wait, and the restart of the loop - plus the
> > caller-owns-the-io-lock contract that ReplicationSlotPersistInvalidation()
> > imposes on both call sites.
>
> That might look heavy but I don't think this pattern is unusual: SLRU uses the
> same general lock, wait, and recheck pattern, and InvalidatePossiblyObsoleteSlot()
> already follows that model when waiting on active_cv.
>
> > You mentioned effective_catalog_xmin, and there are similar shadow fields like
> > last_saved_restart_lsn. What about the same style here: keep the claim exactly
> > as on master - active_proc and data.invalidated set in one spinlock section -
> > and add a pure in-memory boolean, say invalidation_durable, set only at the
> > point the invalid image has actually been written and fsynced (the tail of
> > SaveSlotToPath(), keyed off the image just written. All consumer references to
> > data.invalidated (horizon computations, pg_replication_slots, slotsync's
> > skip/drop decisions) would consult the new flag instead; the invalidators'
> > mutual-exclusion check and the acquire path keep reading the cause as today.
>
> I'm not sure the alternative is lighter overall. It moves the complexity into
> a new intermediate slot state and requires each consumer of data.invalidated to
> decide whether it should also check invalidation_durable.
>
> > The new flag can be added to the padding space, so there is no change in the
> > size of ReplicationSlot.
>
> Yeah that look ok if, for example, we place it here:
>
> (gdb) ptype /o struct ReplicationSlot
> /* offset      |    size */  type = struct ReplicationSlot {
> /*      0      |       1 */    slock_t mutex;
> /*      1      |       1 */    _Bool in_use;
> /* XXX  2-byte hole      */
> /*      4      |       4 */    ProcNumber active_proc;
> /*      8      |       1 */    _Bool just_dirtied;
> /*      9      |       1 */    _Bool dirty;
> /* XXX  2-byte hole      */
> /*     12      |       4 */    TransactionId effective_xmin;
> .
> .
> .
>
> My concern is that data.invalidated would then have two roles depending on
> invalidation_durable. Invalidators and the acquisition path would treat a value
> other than RS_INVAL_NONE as an invalidation, while other consumers would do so
> only once invalidation_durable is set.
>
> That could be an issue for existing extensions on back branches. An extension
> could treat the slot as invalid while core consumers gated by invalidation_durable
> still treat the invalidation as not effective. So, although the ABI layout would
> be preserved, the semantics of an existing field would change.
>
> Thoughts?

I think the new approach could make the code significantly more
fragile and could lead to silent system corruption if not handled
carefully. For example, we could hit a case where logical decoding is
disabled on seeing the last invalidated slot and WALs are removed, but
then the fsync to disk fails. This would make the system completely
unrecoverable (system startup would fail because logical decoding was
disabled while a valid slot is still present on disk). Although we
will theoretically change all readers of invalidated to also consult
the shadow flag, my point is that a single missed check would result
in an unrecoverable state.

And not just existing extensions but even future ones could easily
fall into this exact trap by missing just one check.

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Fri, Sep 25, 2026 at 05:54:41AM +0000, Bertrand Drouvot wrote:
> Hi,
> 
> On Fri, Sep 25, 2026 at 09:38:27AM +0530, shveta malik wrote:
> > On Thu, Sep 24, 2026 at 3:11 PM Bertrand Drouvot
> >  wrote:
> > >
> > 
> > Thanks for addressing comments. A few concerns on 001:
> 
> Thanks for looking at it!
> 
> > 1)
> > 
> > In SaveSlotToPath(), should we add an 'Assert(cp.slotdata.restart_lsn
> > == InvalidXLogRecPtr)' at the end for the 'if (clear_restart_lsn)'
> > case?
> > 
> >                 slot->data.invalidated = invalidation_cause;
> >                 if (clear_restart_lsn)
> > +               {
> > +                       Assert(cp.slotdata.restart_lsn == InvalidXLogRecPtr);
> >                         slot->data.restart_lsn = InvalidXLogRecPtr;
> > +               }
> > 
> > While slot->last_saved_restart_lsn correctly inherits
> > cp.slotdata.restart_lsn on the next line, adding this Assert
> > guarantees that the removed logic from
> > InvalidatePossiblyObsoleteSlot() was successfully compensated for in
> > the on-disk struct before we propagate it to shared memory. It is not
> > mandatory, but it would be good to have.
> 
> I’m not sure this assertion adds much, since cp.slotdata.restart_lsn is explicitly
> cleared above and is not modified afterward.
> 
> > 2)
> > + Assert(update_inactive_since || slot->data.persistency == RS_PERSISTENT);
> > 
> > In ReplicationSlotReleaseInternal(), I didn’t quite understand the
> > reasoning behind above Assert.  Does this mean that when the caller
> > passes update_inactive_since=true, the slot can even be temporary,
> > whereas if we are not updating inactive_since, the slot must be
> > persistent?
> 
> Yes. In fact, with update_inactive_since=true it can also be ephemeral, since
> ReplicationSlotRelease() uses that value for the ordinary release path.
> 
> This is not specific to slotsync. The false case is introduced by 0001 and is
> only used to preserve inactive_since when rolling back ownership of an inactive
> persistent slot.
> 
> Maybe the following comment would make that clearer?
> 
> "
>   /*
>    * Skipping the inactive_since update is only needed when undoing the
>    * internal acquisition of an inactive persistent slot after an ERROR.
>    */
> "
> 
> > 3)
> > Another doubt I have is that with above Assert, when
> > update_inactive_since is TRUE, we are even allowing RS_EPHEMERAL
> > slots. However, ReplicationSlotPersistInvalidation() explicitly
> > disallows them in patch002 with:
> > 
> > Assert(slot->data.persistency != RS_EPHEMERAL);
> > 
> > Both checks are not in sync.
> 
> I think they apply to different scopes. ReplicationSlotReleaseInternal() is the
> general release implementation, so update_inactive_since=true imposes no
> persistency restriction. In particular, an ephemeral slot is dropped by that
> path.
> 
> ReplicationSlotPersistInvalidation() has a narrower contract and is only
> intended for persistent or temporary slots. That said, maybe its Assert could
> express all the supported combinations more clearly?
> 
> "
>   Assert(slot->data.persistency == RS_PERSISTENT ||
>          (slot->data.persistency == RS_TEMPORARY &&
>           update_inactive_since));
> "
> 

The patch needed a rebase, so at the same time I went ahead with the proposed
changes above (plus the one in the commit message suggested by Rui in [1]).

[1]: https://postgr.es/m/CAHWVJhHNt2vUs6xBPZ9c%2Bsh1HjLroC032%2BqKjN%2B_qh%2Bbvc_M4Q%40mail.gmail.com

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
Вложения:
On Fri, Sep 25, 2026 at 11:24 AM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Fri, Sep 25, 2026 at 09:38:27AM +0530, shveta malik wrote:
> > On Thu, Sep 24, 2026 at 3:11 PM Bertrand Drouvot
> >  wrote:
> > >
> >
> > Thanks for addressing comments. A few concerns on 001:
>
> Thanks for looking at it!
>
> > 1)
> >
> > In SaveSlotToPath(), should we add an 'Assert(cp.slotdata.restart_lsn
> > == InvalidXLogRecPtr)' at the end for the 'if (clear_restart_lsn)'
> > case?
> >
> >                 slot->data.invalidated = invalidation_cause;
> >                 if (clear_restart_lsn)
> > +               {
> > +                       Assert(cp.slotdata.restart_lsn == InvalidXLogRecPtr);
> >                         slot->data.restart_lsn = InvalidXLogRecPtr;
> > +               }
> >
> > While slot->last_saved_restart_lsn correctly inherits
> > cp.slotdata.restart_lsn on the next line, adding this Assert
> > guarantees that the removed logic from
> > InvalidatePossiblyObsoleteSlot() was successfully compensated for in
> > the on-disk struct before we propagate it to shared memory. It is not
> > mandatory, but it would be good to have.
>
> I’m not sure this assertion adds much, since cp.slotdata.restart_lsn is explicitly
> cleared above and is not modified afterward.
>
> > 2)
> > + Assert(update_inactive_since || slot->data.persistency == RS_PERSISTENT);
> >
> > In ReplicationSlotReleaseInternal(), I didn’t quite understand the
> > reasoning behind above Assert.  Does this mean that when the caller
> > passes update_inactive_since=true, the slot can even be temporary,
> > whereas if we are not updating inactive_since, the slot must be
> > persistent?
>
> Yes. In fact, with update_inactive_since=true it can also be ephemeral, since
> ReplicationSlotRelease() uses that value for the ordinary release path.
>
> This is not specific to slotsync. The false case is introduced by 0001 and is
> only used to preserve inactive_since when rolling back ownership of an inactive
> persistent slot.
>
> Maybe the following comment would make that clearer?
>
> "
>   /*
>    * Skipping the inactive_since update is only needed when undoing the
>    * internal acquisition of an inactive persistent slot after an ERROR.
>    */
> "
>
> > 3)
> > Another doubt I have is that with above Assert, when
> > update_inactive_since is TRUE, we are even allowing RS_EPHEMERAL
> > slots. However, ReplicationSlotPersistInvalidation() explicitly
> > disallows them in patch002 with:
> >
> > Assert(slot->data.persistency != RS_EPHEMERAL);
> >
> > Both checks are not in sync.
>
> I think they apply to different scopes. ReplicationSlotReleaseInternal() is the
> general release implementation, so update_inactive_since=true imposes no
> persistency restriction. In particular, an ephemeral slot is dropped by that
> path.
>
> ReplicationSlotPersistInvalidation() has a narrower contract and is only
> intended for persistent or temporary slots. That said, maybe its Assert could
> express all the supported combinations more clearly?
>
> "
>   Assert(slot->data.persistency == RS_PERSISTENT ||
>          (slot->data.persistency == RS_TEMPORARY &&
>           update_inactive_since));
> "

Bertrand, I will come to this Assert soon. First I would like to
think/discuss if we can get rid of passing the 'update_inactive_since'
boolean altogether. Currently, we need it mainly for two reasons:

a) ReplicationSlotRelease() does not know when it should update
inactive_since and when it should skip it.
b) The slot-skip and other invalidation flows currently behave differently.

We could eliminate the second difference by making the logic same for
both the flows. I don't think there is any harm in skipping the
'inactive_since' update for the slot-sync's
slot-invalidation-persist's error case as well. We never use
'inactive_since' to invalidate idle synced slots (see
CanInvalidateIdleSlot()). And  'inactive_since' only matters for
synced slots after standby promotion, when it is reset for all synced
slots by update_synced_slots_inactive_since() from ShutDownSlotSync()
(promotion's flow). So I don't think we need to maintain separate
logic for this rare error case. If really needed in the future, we
could still preserve the current behavior IsSyncingReplicationSlots()
check in ReplicationSlotRelease(), but I don't think it is worth the
extra complexity.

That leaves us with just handling the failed-invalidation case where
ReplicationSlotRelease() need to avoid update of inactive_since. How
about using a static flag for this? We can set it in the CATCH block
of ReplicationSlotPersistInvalidation() before calling
ReplicationSlotRelease().

With this approach, both flows can use ReplicationSlotRelease() in the
same way and we don't need to split the logic into
ReplicationSlotReleaseInternal() either. I have attached a sample
patch. Please let me know your thoughts.

Attached patch applies atop v7-002.

thanks
Shveta

Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Tue, Sep 29, 2026 at 11:07:34AM +0530, shveta malik wrote:
> >
> Bertrand, I will come to this Assert soon. First I would like to
> think/discuss if we can get rid of passing the 'update_inactive_since'
> boolean altogether. Currently, we need it mainly for two reasons:
> 
> a) ReplicationSlotRelease() does not know when it should update
> inactive_since and when it should skip it.
> b) The slot-skip and other invalidation flows currently behave differently.
> 
> We could eliminate the second difference by making the logic same for
> both the flows. I don't think there is any harm in skipping the
> 'inactive_since' update for the slot-sync's
> slot-invalidation-persist's error case as well. We never use
> 'inactive_since' to invalidate idle synced slots (see
> CanInvalidateIdleSlot()). And  'inactive_since' only matters for
> synced slots after standby promotion, when it is reset for all synced
> slots by update_synced_slots_inactive_since() from ShutDownSlotSync()
> (promotion's flow). So I don't think we need to maintain separate
> logic for this rare error case. If really needed in the future, we
> could still preserve the current behavior IsSyncingReplicationSlots()
> check in ReplicationSlotRelease(), but I don't think it is worth the
> extra complexity.

Yeah, that makes sense. This is a rare error path, so I agree that it is not
worth the extra complexity.

> That leaves us with just handling the failed-invalidation case where
> ReplicationSlotRelease() need to avoid update of inactive_since. How
> about using a static flag for this? We can set it in the CATCH block
> of ReplicationSlotPersistInvalidation() before calling
> ReplicationSlotRelease().
> 
> With this approach, both flows can use ReplicationSlotRelease() in the
> same way and we don't need to split the logic into
> ReplicationSlotReleaseInternal() either. I have attached a sample
> patch. Please let me know your thoughts.

The static flag looks safe, but I wonder if it wouldn't be clearer to keep
ReplicationSlotReleaseInternal() and call it with false from the error path?

That would still allow us to remove update_inactive_since from
ReplicationSlotPersistInvalidation() and its callers, while keeping the
exceptional release behavior explicit.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Sep 29, 2026 at 1:59 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Tue, Sep 29, 2026 at 11:07:34AM +0530, shveta malik wrote:
> > >
> > Bertrand, I will come to this Assert soon. First I would like to
> > think/discuss if we can get rid of passing the 'update_inactive_since'
> > boolean altogether. Currently, we need it mainly for two reasons:
> >
> > a) ReplicationSlotRelease() does not know when it should update
> > inactive_since and when it should skip it.
> > b) The slot-skip and other invalidation flows currently behave differently.
> >
> > We could eliminate the second difference by making the logic same for
> > both the flows. I don't think there is any harm in skipping the
> > 'inactive_since' update for the slot-sync's
> > slot-invalidation-persist's error case as well. We never use
> > 'inactive_since' to invalidate idle synced slots (see
> > CanInvalidateIdleSlot()). And  'inactive_since' only matters for
> > synced slots after standby promotion, when it is reset for all synced
> > slots by update_synced_slots_inactive_since() from ShutDownSlotSync()
> > (promotion's flow). So I don't think we need to maintain separate
> > logic for this rare error case. If really needed in the future, we
> > could still preserve the current behavior IsSyncingReplicationSlots()
> > check in ReplicationSlotRelease(), but I don't think it is worth the
> > extra complexity.
>
> Yeah, that makes sense. This is a rare error path, so I agree that it is not
> worth the extra complexity.
>
> > That leaves us with just handling the failed-invalidation case where
> > ReplicationSlotRelease() need to avoid update of inactive_since. How
> > about using a static flag for this? We can set it in the CATCH block
> > of ReplicationSlotPersistInvalidation() before calling
> > ReplicationSlotRelease().
> >
> > With this approach, both flows can use ReplicationSlotRelease() in the
> > same way and we don't need to split the logic into
> > ReplicationSlotReleaseInternal() either. I have attached a sample
> > patch. Please let me know your thoughts.
>
> The static flag looks safe, but I wonder if it wouldn't be clearer to keep
> ReplicationSlotReleaseInternal() and call it with false from the error path?
>
> That would still allow us to remove update_inactive_since from
> ReplicationSlotPersistInvalidation() and its callers, while keeping the
> exceptional release behavior explicit.
>

Okay, works for me.

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Ashutosh Sharma <ashu.coek88@gmail.com>
Дата:
Hi,

On Mon, Sep 28, 2026 at 9:16 PM Bertrand Drouvot
 wrote:
>
> The patch needed a rebase, so at the same time I went ahead with the proposed
> changes above (plus the one in the commit message suggested by Rui in [1]).
>

Thanks for reporting the problem and providing a patch for it. The
approach looks good to me, but I have a few comments to share:

1)

The normal replication slot update pattern is:

SpinLockAcquire(&slot->mutex);
slot->data.some_field = new_value;
SpinLockRelease(&slot->mutex);

ReplicationSlotMarkDirty();
ReplicationSlotSave();

i.e. we first update the slot in memory and then persist the changes
to disk. This is an exception where we need to persist the change to
disk before publishing it in memory.

I think it would be good to add a comment above
InvalidatePossiblyObsoleteSlot() explaining the reason for this change
in the usual slot update pattern.

--

2)

+ {
+ SaveSlotToPath(slot, path, ERROR, cause, clear_restart_lsn);
+ }

Do we need to pass clear_restart_lsn here? Cause can be used to
determine the restart lsn value later, no?

--

3)

The current patch changes the interface for SaveSlotToPath() (), isn't
it possible to keep it unchanged, that would probably also reduce some
amount of complexity. How about renaming the extended implementation
to SaveSlotToPathInternal() and have SaveSlotToPath() call it with
RS_INVAL_NONE and false. This avoids exposing invalidation specific
arguments to normal save callers. See below:

static void
SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
{
SaveSlotToPathInternal(slot, dir, elevel, RS_INVAL_NONE, false);
}

For slot invalidation, add a dedicated SaveInvalidatedSlotToPath()
wrapper that calls SaveSlotToPathInternal() with the required
invalidation state.

static void
SaveInvalidatedSlotToPath(ReplicationSlot *slot, const char *dir,
 ReplicationSlotInvalidationCause cause,
 bool clear_restart_lsn)
{
Assert(cause != RS_INVAL_NONE);
Assert(LWLockHeldByMeInMode(&slot->io_in_progress_lock, LW_EXCLUSIVE));

SaveSlotToPathInternal(slot, dir, ERROR, cause, clear_restart_lsn);
}

--
With Regards,
Ashutosh Sharma.


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Wed, Sep 30, 2026 at 09:08:41AM +0530, shveta malik wrote:
> On Tue, Sep 29, 2026 at 1:59 PM Bertrand Drouvot
>  wrote:
> >
> > The static flag looks safe, but I wonder if it wouldn't be clearer to keep
> > ReplicationSlotReleaseInternal() and call it with false from the error path?
> >
> > That would still allow us to remove update_inactive_since from
> > ReplicationSlotPersistInvalidation() and its callers, while keeping the
> > exceptional release behavior explicit.
> >
> 
> Okay, works for me.

Thanks, done that way in the attached.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Wed, Sep 30, 2026 at 03:50:30PM +0530, Ashutosh Sharma wrote:
> Hi,
> 
> On Mon, Sep 28, 2026 at 9:16 PM Bertrand Drouvot
>  wrote:
> >
> > The patch needed a rebase, so at the same time I went ahead with the proposed
> > changes above (plus the one in the commit message suggested by Rui in [1]).
> >
> 
> Thanks for reporting the problem and providing a patch for it. The
> approach looks good to me, but I have a few comments to share:

Thanks for looking at it!

> 
> I think it would be good to add a comment above
> InvalidatePossiblyObsoleteSlot() explaining the reason for this change
> in the usual slot update pattern.

What about something like?

"
Unlike normal replication slot updates, persist the invalidation before
publishing it in shared memory. Publishing it first could allow resource
horizon computations to remove resources required by the slot before the
invalidation reaches disk. If saving then failed, a restart could restore
the old valid slot. Keeping the shared slot valid until the invalidated
image is durable avoids that state.
"

> 
> 2)
> 
> + {
> + SaveSlotToPath(slot, path, ERROR, cause, clear_restart_lsn);
> + }
> 
> Do we need to pass clear_restart_lsn here? Cause can be used to
> determine the restart lsn value later, no?

I don't think so. InvalidatePossiblyObsoleteSlot() clears restart_lsn for
RS_INVAL_WAL_REMOVED, while slotsync must preserve the local restart_lsn
when copying the same invalidation cause. So the cause alone is not enough to
determine the desired behavior.

> 3)
> 
> The current patch changes the interface for SaveSlotToPath() (), isn't
> it possible to keep it unchanged, that would probably also reduce some
> amount of complexity.

Yeah, that seems worthwhile. I'll change it that way.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
Ashutosh Sharma <ashu.coek88@gmail.com>
Дата:
Hi,

On Sun, Oct 4, 2026 at 11:30 AM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Wed, Sep 30, 2026 at 03:50:30PM +0530, Ashutosh Sharma wrote:
> > Hi,
> >
> > On Mon, Sep 28, 2026 at 9:16 PM Bertrand Drouvot
> >  wrote:
> > >
> > > The patch needed a rebase, so at the same time I went ahead with the proposed
> > > changes above (plus the one in the commit message suggested by Rui in [1]).
> > >
> >
> > Thanks for reporting the problem and providing a patch for it. The
> > approach looks good to me, but I have a few comments to share:
>
> Thanks for looking at it!
>
> >
> > I think it would be good to add a comment above
> > InvalidatePossiblyObsoleteSlot() explaining the reason for this change
> > in the usual slot update pattern.
>
> What about something like?
>
> "
> Unlike normal replication slot updates, persist the invalidation before
> publishing it in shared memory. Publishing it first could allow resource
> horizon computations to remove resources required by the slot before the
> invalidation reaches disk. If saving then failed, a restart could restore
> the old valid slot. Keeping the shared slot valid until the invalidated
> image is durable avoids that state.
> "

Looks clear to me.

>
> >
> > 2)
> >
> > + {
> > + SaveSlotToPath(slot, path, ERROR, cause, clear_restart_lsn);
> > + }
> >
> > Do we need to pass clear_restart_lsn here? Cause can be used to
> > determine the restart lsn value later, no?
>
> I don't think so. InvalidatePossiblyObsoleteSlot() clears restart_lsn for
> RS_INVAL_WAL_REMOVED, while slotsync must preserve the local restart_lsn
> when copying the same invalidation cause. So the cause alone is not enough to
> determine the desired behavior.
>

Okay got it, then it does make sense to have this clear restart lsn flag.

> > 3)
> >
> > The current patch changes the interface for SaveSlotToPath() (), isn't
> > it possible to keep it unchanged, that would probably also reduce some
> > amount of complexity.
>
> Yeah, that seems worthwhile. I'll change it that way.
>

Thanks. I'll review again once the updated patch is posted.

--
With Regards,
Ashutosh Sharma.


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> Thanks. I'll review again once the updated patch is posted.

Thanks! Here it is.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> > Thanks. I'll review again once the updated patch is posted.
>
> Thanks! Here it is.
>

Since we have now modularized this further by introducing
SaveSlotToPathInternal() and SaveInvalidatedSlotToPath(), can we make
SaveSlotToPathInternal() consistent across both flows with respect to
lock acquisition and release?

We could have SaveSlotToPath() acquire and release the lock,
preferably within a PG_TRY/PG_CATCH block. Additionally, the
'was_dirty' check can also be moved up into SaveSlotToPath(), since
SaveInvalidatedSlotToPath() always forces a write and doesn't need the
check.

This way, SaveSlotToPath() would acquire the lock only when the slot
is dirty, and SaveSlotToPathInternal() would not need to handle lock
acquisition/release based on the 'cause' argument. This would also let
us remove the multiple if blocks that currently check the 'cause' and
release the lock. Thoughts?

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Tue, Oct 06, 2026 at 10:25:35AM +0530, shveta malik wrote:
> On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot
>  wrote:
> >
> > Hi,
> >
> > On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> > > Thanks. I'll review again once the updated patch is posted.
> >
> > Thanks! Here it is.
> >
> 
> Since we have now modularized this further by introducing
> SaveSlotToPathInternal() and SaveInvalidatedSlotToPath(), can we make
> SaveSlotToPathInternal() consistent across both flows with respect to
> lock acquisition and release?
> 
> We could have SaveSlotToPath() acquire and release the lock,
> preferably within a PG_TRY/PG_CATCH block. Additionally, the
> 'was_dirty' check can also be moved up into SaveSlotToPath(), since
> SaveInvalidatedSlotToPath() always forces a write and doesn't need the
> check.
> 
> This way, SaveSlotToPath() would acquire the lock only when the slot
> is dirty, and SaveSlotToPathInternal() would not need to handle lock
> acquisition/release based on the 'cause' argument. This would also let
> us remove the multiple if blocks that currently check the 'cause' and
> release the lock. Thoughts?

Thanks for the proposal!

I looked at it, but I think that it makes ordinary save errors get reported while
holding io_in_progress_lock. In particular, the LOG path would perform logging
and check for interrupts before releasing the lock.

As this is meant to be backpatched, I'm not sure it's worth changing the existing
behavior as part of this fix. The proposed cleanup could be considered separately
on HEAD as a follow up patch though.

What do you think?

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
Ashutosh Sharma <ashu.coek88@gmail.com>
Дата:
Hi,

On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> > Thanks. I'll review again once the updated patch is posted.
>
> Thanks! Here it is.

Thanks, the attached patch looks good overall. I only have a couple of
concerns as of now, feel free to disregard them if you do not think
they are worth addressing.

1) Although assertions are useful, some appear redundant across the
three layers of the slot invalidation path:

- cause != RS_INVAL_NONE is asserted in both
ReplicationSlotPersistInvalidation() and SaveInvalidatedSlotToPath().
- I/O lock ownership is asserted in those two functions and
conditionally in SaveSlotToPathInternal().
- The clear_restart_lsn constraint is asserted in both the public and
internal functions.
- cause == RS_INVAL_NONE || elevel >= ERROR is already guaranteed by
the wrapper functions, since SaveInvalidatedSlotToPath() always passes
ERROR.

I think some of these assertions could be removed, particularly the
following ones:

static void
SaveInvalidatedSlotToPath(ReplicationSlot *slot, const char *dir,
                          ReplicationSlotInvalidationCause cause,
                          bool clear_restart_lsn)
{
    Assert(cause != RS_INVAL_NONE);
    Assert(LWLockHeldByMeInMode(&slot->io_in_progress_lock, LW_EXCLUSIVE));

--

2) SaveSlotToPathInternal() currently has several conditional branches
distinguishing between the normal-save and invalidation-save paths. It
might be worth considering whether this distinction can be simplified,
making the function easier to follow.

Other than these points, the current patch set looks good to me. I
will spend some more time reviewing it and report back if I find
anything else worth mentioning.

--
With Regards,
Ashutosh Sharma.


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Hi,

On Tue, Oct 06, 2026 at 03:46:24PM +0530, Ashutosh Sharma wrote:
> Hi,
> 
> On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot
>  wrote:
> >
> > Hi,
> >
> > On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> > > Thanks. I'll review again once the updated patch is posted.
> >
> > Thanks! Here it is.
> 
> Thanks, the attached patch looks good overall.

Thanks for looking at it!

> I only have a couple of
> concerns as of now, feel free to disregard them if you do not think
> they are worth addressing.
> 
> 1) Although assertions are useful, some appear redundant across the
> three layers of the slot invalidation path:
> 
> - cause != RS_INVAL_NONE is asserted in both
> ReplicationSlotPersistInvalidation() and SaveInvalidatedSlotToPath().
> - I/O lock ownership is asserted in those two functions and
> conditionally in SaveSlotToPathInternal().
> - The clear_restart_lsn constraint is asserted in both the public and
> internal functions.
> - cause == RS_INVAL_NONE || elevel >= ERROR is already guaranteed by
> the wrapper functions, since SaveInvalidatedSlotToPath() always passes
> ERROR.
> 
> I think some of these assertions could be removed, particularly the
> following ones:
> 
> static void
> SaveInvalidatedSlotToPath(ReplicationSlot *slot, const char *dir,
>                           ReplicationSlotInvalidationCause cause,
>                           bool clear_restart_lsn)
> {
>     Assert(cause != RS_INVAL_NONE);
>     Assert(LWLockHeldByMeInMode(&slot->io_in_progress_lock, LW_EXCLUSIVE));

I'm inclined to keep them. They check the preconditions at different layers.
There are similar caller/callee examples in the tree, for example:

SnapBuildSnapDecRefcount() / SnapBuildFreeSnapshot()
MemoryContextReset() / MemoryContextResetOnly()
MemoryContextDelete() / MemoryContextDeleteOnly()
SyncRepWakeQueue() / SyncRepQueueIsOrderedByLSN()

In particular, the cause assertion prevents RS_INVAL_NONE from reaching the regular
save path and trying to acquire the lock already held by the caller.

> 
> 2) SaveSlotToPathInternal() currently has several conditional branches
> distinguishing between the normal-save and invalidation-save paths. It
> might be worth considering whether this distinction can be simplified,
> making the function easier to follow.

I replied to a similar suggestion from Shveta in [1].

> Other than these points, the current patch set looks good to me. I
> will spend some more time reviewing it and report back if I find
> anything else worth mentioning.

Thanks!

[1]: https://www.postgresql.org/message-id/asSkN5GOEOKQZs9w%40bdtpg

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Re: Persist slot invalidations before publishing them

От:
shveta malik <shveta.malik@gmail.com>
Дата:
On Tue, Oct 6, 2026 at 1:03 PM Bertrand Drouvot
 wrote:
>
> Hi,
>
> On Tue, Oct 06, 2026 at 10:25:35AM +0530, shveta malik wrote:
> > On Mon, Oct 5, 2026 at 6:54 PM Bertrand Drouvot
> >  wrote:
> > >
> > > Hi,
> > >
> > > On Mon, Oct 05, 2026 at 03:22:53PM +0530, Ashutosh Sharma wrote:
> > > > Thanks. I'll review again once the updated patch is posted.
> > >
> > > Thanks! Here it is.
> > >
> >
> > Since we have now modularized this further by introducing
> > SaveSlotToPathInternal() and SaveInvalidatedSlotToPath(), can we make
> > SaveSlotToPathInternal() consistent across both flows with respect to
> > lock acquisition and release?
> >
> > We could have SaveSlotToPath() acquire and release the lock,
> > preferably within a PG_TRY/PG_CATCH block. Additionally, the
> > 'was_dirty' check can also be moved up into SaveSlotToPath(), since
> > SaveInvalidatedSlotToPath() always forces a write and doesn't need the
> > check.
> >
> > This way, SaveSlotToPath() would acquire the lock only when the slot
> > is dirty, and SaveSlotToPathInternal() would not need to handle lock
> > acquisition/release based on the 'cause' argument. This would also let
> > us remove the multiple if blocks that currently check the 'cause' and
> > release the lock. Thoughts?
>
> Thanks for the proposal!
>
> I looked at it, but I think that it makes ordinary save errors get reported while
> holding io_in_progress_lock. In particular, the LOG path would perform logging
> and check for interrupts before releasing the lock.

I considered this when posting the comment, but then thought that the
other flow, 'SaveInvalidatedSlotToPath' is no different and has the
same limitations. Thus, I thought it should be okay if both flows
share the same logic (and limitations too).
But on re-thinking, I think you are worried about the flow from
CheckPointReplicationSlots() which only logs issues instead of
erroring out. I see your point now.

>
> As this is meant to be backpatched, I'm not sure it's worth changing the existing
> behavior as part of this fix. The proposed cleanup could be considered separately
> on HEAD as a follow up patch though.
>
> What do you think?
>

Okay, works for me.

thanks
Shveta


Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Wed, Oct 07, 2026 at 09:33:24AM +0530, shveta malik wrote:
> On Tue, Oct 6, 2026 at 1:03 PM Bertrand Drouvot
>  wrote:
> >
> > I looked at it, but I think that it makes ordinary save errors get reported while
> > holding io_in_progress_lock. In particular, the LOG path would perform logging
> > and check for interrupts before releasing the lock.
> 
> I considered this when posting the comment, but then thought that the
> other flow, 'SaveInvalidatedSlotToPath' is no different and has the
> same limitations. Thus, I thought it should be okay if both flows
> share the same logic (and limitations too).
> But on re-thinking, I think you are worried about the flow from
> CheckPointReplicationSlots() which only logs issues instead of
> erroring out. I see your point now.

Yeah that's the case I had in mind.

> > As this is meant to be backpatched, I'm not sure it's worth changing the existing
> > behavior as part of this fix. The proposed cleanup could be considered separately
> > on HEAD as a follow up patch though.
> >
> > What do you think?
> >
> 
> Okay, works for me.

PFA a mandatory rebase due to conflicts in test/recovery/meson.build.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Re: Persist slot invalidations before publishing them

От:
Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Дата:
Вложения:
Hi,

On Fri, Oct 09, 2026 at 06:03:20AM +0000, Bertrand Drouvot wrote:
> 
> PFA a mandatory rebase due to conflicts in test/recovery/meson.build.

PFA a mandatory rebase for the same reason as above.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
FAQ