Re: Introduce XID age based replication slot invalidation
Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
From: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
To: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>,
John H <johnhyvr@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Date: 2026-03-20T16:10:00Z
Lists: pgsql-hackers
Attachments
- v1-0001-Add-XID-age-based-replication-slot-invalidation.patch (application/x-patch) patch v1-0001
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
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix the handling of two GUCs during upgrade.
- 72e6c08fea7c 19 (unreleased) cited