Re: Introduce XID age based replication slot invalidation

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com>
Cc: Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>, SATYANARAYANA NARLAPURAM <satyanarlapuram(at)gmail(dot)com>, "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>, John H <johnhyvr(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Introduce XID age based replication slot invalidation
Date: 2026-04-01 21:21:13
Message-ID: CALj2ACV724Yr2=5Jun4XGQyGhvCiXo+7GXJUnybqf9SYqQA6gw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Apr 1, 2026 at 12:39 PM Masahiko Sawada <sawada(dot)mshk(at)gmail(dot)com> wrote:
>
> I've reviewed the v7 patch and have some review comments:

Thank you for reviewing the patch.

> +# Advance the given number of XIDs
> +sub advance_xids
> +{
> + my ($node, $nxids) = @_;
> + my $sql = join(";\n", ("SELECT pg_current_xact_id()") x $nxids);
> + $node->safe_psql('postgres', $sql);
> +}
>
> I think we can create a procedure on primary5 instance to consume XIDs
> as follow:
>
> $standby5->safe_psql(
> 'postgres',
> qq{CREATE PROCEDURE consume_xid(cnt int)
> AS \$\$
> DECLARE
> i int;
> BEGIN
> FOR i in 1..cnt LOOP
> EXECUTE 'SELECT pg_current_xact_id()';
> COMMIT;
> END LOOP;
> END;
> +\$\$
> LANGUAGE plpgsql;
> });

Agreed. Although the test timings don't improve (9 seconds on my dev
machine) after moving to the procedure vs. sending pg_current_xact_id
SQL statements, the procedure approach looks better and is more
consistent.

> ---
> +# Create a subscriber node
> +my $subscriber5 = PostgreSQL::Test::Cluster->new('subscriber5');
> +$subscriber5->init(allows_streaming => 'logical');
> +$subscriber5->start;
>
> Do we really need to create a subscriber for this test? I think we can
> simply create a logical slot on the primary5 and test the XID-age
> based slot invalidation.

Nice catch! Removed.

> ---
> I've attached a fixup patch to propose some cleanup and refactoring, including:
>
> - changes to invalidation errdetail message.
> - passing xidLimit instead of recentXid to simplify the invalidation logic.
> - documentation changes.
> - comment changes.

I took the above changes into v8 and fixed a typo in using xidLimit
instead of slotXidLimit.

Please find the attached v8 patches for further review. Thank you!

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

Attachment Content-Type Size
v8-0002-Add-more-tests-for-XID-age-slot-invalidation.patch application/x-patch 6.3 KB
v8-0001-Add-XID-age-based-replication-slot-invalidation.patch application/x-patch 30.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniil Davydov 2026-04-01 21:24:29 Re: POC: Parallel processing of indexes in autovacuum
Previous Message Zsolt Parragi 2026-04-01 21:12:58 Re: [oauth] Split and extend PGOAUTHDEBUG