pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: Scott Ray <scott@scottray.io>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Masahiko Sawada <sawada.mshk@gmail.com>
Cc: Amit Kapila <amit.kapila16@gmail.com>
Cc: Zhijie Hou (Fujitsu) <houzj.fnst@fujitsu.com>
Cc: Kuroda, Hayato/黒田 隼人 <kuroda.hayato@fujitsu.com>
Cc: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Subject: Re: Recovery conflict resolution misses backends that import snapshots
Date: Mon, 27 Jul 2026 08:49:33 +0900
Message-ID: <amadDbubjWo_Jag1@paquier.xyz> (raw)
In-Reply-To: <QpAansP4iVg_ttSs9x81PFAptL2sqR3AS06u8Jksm3_bHJvUwQjHOocRajbxBc3iiLdf9ZMC6gtXjZsxdxvOmqp98hLZcZuWyBDuQxS6uZc=@scottray.io>
References: <QpAansP4iVg_ttSs9x81PFAptL2sqR3AS06u8Jksm3_bHJvUwQjHOocRajbxBc3iiLdf9ZMC6gtXjZsxdxvOmqp98hLZcZuWyBDuQxS6uZc=@scottray.io>

On Sat, Jul 25, 2026 at 11:03:52PM +0000, Scott Ray wrote:
> There is a silent bug in standby conflict resolution that can cause
> incorrect results.  In ResolveRecoveryConflictWithSnapshot, the standby
> calls GetConflictingVirtualXIDs once, then waits for each returned VXID
> to disappear.  However, after GetConflictingVirtualXIDs releases the
> ProcArrayLock, a backend may import a conflicting snapshot from one of
> the backends GetConflictingVirtualXIDs identified as conflicting.  The
> resulting VXID conflicts with recovery, but
> ResolveRecoveryConflictWithSnapshot doesn't know it has to wait for the
> new VXID to disappear before proceeding, so the standby removes tuple
> versions or index entries that the importing backend needs.

Hmm.  It looks like you are right here.  I am not the most fluent here
with this area of the code, so adding in CC a couple of folks who
could perhaps comment, being usually interested on these matters.

> The first attached patch adds a TAP test that fails deterministically
> on unpatched master.  The second makes
> ResolveRecoveryConflictWithSnapshot call GetConflictingVirtualXIDs
> until the result is empty, at which point importing a conflicting
> snapshot is impossible: acquiring a conflicting xmin requires a live,
> conflicting VXID as a source.

+	/*
+	 * Scan until no conflicting VXID remains.
[...]
+	for (;;)
+	{

Adding a code pattern that could potentially cause this code path to
loop infinitely is not what I would call a principled approach, I
would call it a risky one.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (8+ messages)  latest in thread

Message-ID: <amadDbubjWo_Jag1@paquier.xyz>
Permalink:  ../amadDbubjWo_Jag1@paquier.xyz/
Also on:    postgresql.org/message-id/amadDbubjWo_Jag1@paquier.xyz

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: michael@paquier.xyz, scott@scottray.io, sawada.mshk@gmail.com, amit.kapila16@gmail.com, houzj.fnst@fujitsu.com, kuroda.hayato@fujitsu.com, bertranddrouvot.pg@gmail.com
  Subject: Re: Recovery conflict resolution misses backends that import snapshots
  In-Reply-To: <amadDbubjWo_Jag1@paquier.xyz>
  References: <QpAansP4iVg_ttSs9x81PFAptL2sqR3AS06u8Jksm3_bHJvUwQjHOocRajbxBc3iiLdf9ZMC6gtXjZsxdxvOmqp98hLZcZuWyBDuQxS6uZc=@scottray.io> <amadDbubjWo_Jag1@paquier.xyz>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox