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

From Bharath Rupireddy
Subject Re: Introduce XID age based replication slot invalidation
Date
Msg-id CALj2ACUmPbkcj4y4oeXvzUkBejG68QDtrFF7QHDC_qz2vQcTCg@mail.gmail.com
Whole thread Raw
In response to RE: Introduce XID age based replication slot invalidation  ("Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>)
Responses Re: Introduce XID age based replication slot invalidation
List pgsql-hackers
Hi John,

Thank you for sending in the rebased patch earlier. I will have some
cycles going forward and I would like to continue with this work.

Hi Kuroda-san,

Thank you for reviewing the patch.

On Fri, Sep 19, 2025 at 1:07 AM Hayato Kuroda (Fujitsu)
<kuroda.hayato@fujitsu.com> wrote:
>
> IIUC, the feature can directly avoid the wraparound issue than other
> invalidation mechanism. The motivation seems enough for me.

That's correct. When enabled, replication slots whose XID age exceeds
the configured value get invalidated before vacuum computes the XID
horizons. This ensures that slots which would otherwise prevent vacuum
from freezing heap tuples don't come in the way of XID wraparound
prevention.

> The patch currently attempts to invalidate once-per-autovacuum worker.
> We're wondering if it should attempt invalidation on a per-relation
> basis within the vacuum call itself. That would account for scenarios
> where the cost_delay or naptime is high between autovac executions.
>
> I have a concern that age calculation acquire the lock for XidGenLock thus
> performance can be affected. Do you have insights for it?

I made the following design choice: try invalidating only once per
vacuum cycle, not per table. While this keeps the cost of checking
(incl. the XidGenLock contention) for invalidation to a minimum when
there are a large number of tables and replication slots, it can be
less effective when individual tables/indexes are large. Invalidating
during checkpoints can help to some extent with the large table/index
cases. But I'm open to thoughts on this.

Please find the attached patch for further review. I fixed the XID age
calculation in ReplicationSlotIsXIDAged and adjusted the code
comments.

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

Attachment

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: pg_plan_advice
Next
From: Matheus Alcantara
Date:
Subject: Re: Use-after-free issue in postgres_fdw