Re: Introduce XID age and inactive timeout based replication slot invalidation - Mailing list pgsql-hackers

From Nisha Moond
Subject Re: Introduce XID age and inactive timeout based replication slot invalidation
Date
Msg-id CABdArM7YdCZKYoHakPE7LUe7cCdvS+447mGnVNxcq3jdSnjdvA@mail.gmail.com
Whole thread Raw
In response to Re: Introduce XID age and inactive timeout based replication slot invalidation  (vignesh C <vignesh21@gmail.com>)
List pgsql-hackers
On Mon, Jan 13, 2025 at 12:22 PM vignesh C <vignesh21@gmail.com> wrote:
>
> On Thu, 2 Jan 2025 at 15:57, Nisha Moond <nisha.moond412@gmail.com> wrote:
> >
> > Thank you for your feedback! Please find the v59 patch set addressing
> > all the comments.
> > Note: There are no new changes in patch-0001.
>
> Few comments:
> 1) I felt we should not invalidate the slots for which has no
> effective xmin set as they will not be holding the WAL files from
> deletion. This can happen when user created slots with
> immediately_reserve as false and lsn will be actually reserved only
> after the first connection from a streaming replication client:
> +static inline bool
> +CanInvalidateIdleSlot(ReplicationSlot *s)
> +{
> +       return (idle_replication_slot_timeout_mins > 0 &&
> +                       s->inactive_since > 0 &&
> +                       !(RecoveryInProgress() && s->data.synced));
> +}
>

IIUC, for both logical and physical replication slots, the effective
xmin remains NULL until the respective nodes establish their first
connection. However, logical slots always reserve WAL immediately,
whereas physical slots do not unless immediately_reserve=true is set.
To avoid unnecessary slot invalidation for slots that are not
reserving WAL when created, it might be better to check the
restart_lsn instead of effective_xmin. If restart_lsn is invalid for a
slot, it indicates that WAL is not reserved for the slot, and we can
safely skip invalidation due to idle_timeout for such slots. This
logic has been implemented in v60.

--
Thanks,
Nisha



pgsql-hackers by date:

Previous
From: Zhang Mingli
Date:
Subject: Re: Inquiry About Determining Parallel Plans for REFRESH MATERIALIZED VIEW
Next
From: Shinya Kato
Date:
Subject: Re: [PATCH] New predefined role pg_manage_extensions