Hi,
On Mon, Aug 17, 2026 at 10:46 PM Amit Kapila <[email protected]> wrote:
>
> > > so is it okay to keep the same behaviour
> > > for both max_slot_xid_age and idle_replication_slot_timeout w.r.t
> > > synced slots? I am not sure if this is a real risk or just a
> > > theoretical possibility but wanted to bring it to your attention so
> > > that we can consider it.
> >
> > I believe this can happen in practice (as explained above). IMHO, XID
> > age based slot invalidation must invalidate the synced slot on the
> > standby (just like other invalidations except the idle-timeout based)
> > if its catalog_xmin is aged and blocking vacuum on the primary.
>
> Fair enough, then let's invalidate synced slots as well on standby due
> to xid_age
Thanks. I will post the new patches soon.
> but I think it is better to let users build some alerting
> system before these slots get invalidated. We can add a column similar
> to wal_status in pg_replication_slots which could help users to
> indicate that the particular slot is in danger of invalidation.
My initial thought is that one can derive such information using the
existing slot's xmin and catalog_xmin columns along with the
max_slot_xid_age GUC value, something like [1], and create alarms if
needed.
XID-age based replication slot invalidation doesn't have intermediate
phases like WAL-based invalidation does, so wal_status makes sense for
WAL-based invalidation but may not be as applicable here.
That said, I'm open to other thoughts on this.
> Additionally, for synced slots, we could add a LOG/WARNING when they
> are nearing invalidation as there are no direct consumers for the
> same.
That's an interesting idea. I see this as useful not just for XID-age
based invalidation but for slot invalidation in general. Having some
warning before a slot gets invalidated, something like when the
database approaches XID wraparound limits, whether built into core or
via a documented SQL query, would be nice to have. It's worth
discussing separately.
[1] For each replication slot, compute the age of whichever xid it
holds back (xmin or catalog_xmin) and show that age as a percentage of
max_slot_xid_age, so one can see how close each slot is to being
invalidated.
SELECT slot_name, slot_type, xmin, catalog_xmin,
greatest(age(xmin), age(catalog_xmin)) AS xid_age,
current_setting('max_slot_xid_age')::bigint AS xid_age_limit,
round(100.0 * greatest(age(xmin), age(catalog_xmin))
/ current_setting('max_slot_xid_age')::numeric, 0) AS pct_of_limit
FROM pg_replication_slots
WHERE current_setting('max_slot_xid_age')::bigint > 0
AND invalidation_reason IS NULL
ORDER BY xid_age DESC NULLS LAST;
slot_name | slot_type | xmin | catalog_xmin | xid_age | xid_age_limit
| pct_of_limit
-----------+-----------+------+--------------+---------+---------------+--------------
slot_1 | logical | | 695 | 900 | 1000
| 90
slot_2 | physical | 795 | | 800 | 1000
| 80
slot_3 | logical | | 1495 | 100 | 1000
| 10
slot_4 | physical | 1595 | | 0 | 1000
| 0
(4 rows)
--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com