Re: Race conditions in logical decoding

From: Antonin Houska <ah(at)cybertec(dot)at>
To: Alvaro Herrera <alvherre(at)kurilemu(dot)de>
Cc: Rui Zhao <zhaorui126(at)gmail(dot)com>, Andres Freund <andres(at)anarazel(dot)de>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Subject: Re: Race conditions in logical decoding
Date: 2026-09-18 15:23:29
Message-ID: 12834.1789745009@localhost
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)kurilemu(dot)de> wrote:

> On 2026-Sep-18, Antonin Houska wrote:
>
> > Maybe I miss the point, but what's wrong about modifying the existing loop
> > that inverts the meaning of the ->xip array
> >
> > /*
> > * snapbuild.c builds transactions in an "inverted" manner, which means it
> > * stores committed transactions in ->xip, not ones in progress. Build a
> > * classical snapshot by marking all non-committed transactions as
> > * in-progress. This can be expensive.
> > */
> > for (xid = snap->xmin; NormalTransactionIdPrecedes(xid, snap->xmax);)
> > {
> > ...
> > }
> >
> > by calling XactLockTableWait() for each XID we find in the array (i.e. each
> > committed transaction)?
>
> Ah, you mean something like the attached quick POC? This does pass the
> two tests that Rui wrote, also attached. (I didn't test Zhijie's, which
> AFAICT is written to pass with the bug and fail without it.)

Yes, I mean checking if those transactions have really ended.

Regarding [1], perhaps the idea is to avoid calling XactLockTableWait() if the
transaction is no longer in procarray. I'm not sure it's a problem to call
that function (possibly many times) for transactions that are no longer
running. (GetRunningTransactionData() is not free either.)

And regarding the deadlock with synchronous replica, my understanding is that
we avoid it by waiting in SnapBuildInitialSnapshot() instead of in
SnapBuildBuildSnapshot().

[1] https://www.postgresql.org/message-id/CAHWVJhHXyLtS-8mdL9WhEWfsERb%3DFN7JdPD0GYAXgTmCnqbYGw%40mail.gmail.com

--
Antonin Houska
Web: https://www.cybertec-postgresql.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2026-09-18 15:52:12 Re: add list of major features to the v19 release notes
Previous Message David Geier 2026-09-18 15:09:11 Re: Use correct collation in pg_trgm