pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jesper St John <jesper@stjohn.se>
To: Kirill Reshke <reshkekirill@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Timing issue in pg_basebackup
Date: Wed, 21 Oct 2026 19:16:18 +0200
Message-ID: <4417791388e8f1df20f64013e944be8e@stjohn.se> (raw)
In-Reply-To: <CALdSSPj_M=6RLR0XpXKVr_NWiaVAhT7g7wRaMx_--3kKZpT0SA@mail.gmail.com>
References: <ddfa03dcf26f366ae493e8cc41bd479a@stjohn.se>
	<CALdSSPj_M=6RLR0XpXKVr_NWiaVAhT7g7wRaMx_--3kKZpT0SA@mail.gmail.com>

On 2026-10-20 23:11, Kirill Reshke wrote:
> On Mon, 19 Oct 2026 at 19:33, Jesper St John <jesper@stjohn.se> wrote:
>> 
>> Hey!
>> 
>> I recently came across this issue when running pg_basebackup from 2
>> nodes at the same time through ansible. One of the nodes sometimes
>> reported: "requested WAL segment ... has already been removed". Tested
>> on v16, v17 and v18. The workaround was running them in sequence or
>> pause between runs.
>> 
>> It looks like there's a timing issue here:
>> 1. Backup A starts and runs a checkpoint - needs WAL from segment 2.
>> 2. Backup A hasn't reserved that WAL yet.
>> 3. Backup B starts and runs a checkpoint (or anyone runs a checkpoint) 
>> -
>> deletes segment 2.
>> 4. Backup A asks for segment 2, which is gone, and fails.
> 
> Hi!
> Looks like this is a real issue.

Thanks for looking into it.

> 
>> I've included a patch that moves the replication slot handing to run
>> before the backup part as a separate function.
>> 
>> Some possible caveats already:
>> * Since moving the slot creation, we might run in to trouble if for
>> example, --checkpoint=spread is used since the slot is open for 
>> longer.
>> * If any error arises in the backup part, now there will be a 
>> lingering
>> slot when previously no slot was created.
> 
> lingering slots looks like a real regression here. can we remove them
> when basebackup client disconnects?

A lingering slot could also happen today - only with this patch there's 
a higher risk of it happening.

Would some cleanup code in a function and use it with atexit() work?

> 
> NIT: comment in PrepareLogStreamer loses its meaning after code motion:
> 
> + /* Get a second connection */
> + bgconn = GetConnection();
> 

I've moved the code to its own function - the comment were there 
already.


> 
>> *** DISCLAIMER ***
>> I've used an LLM to help me write the test - I'm rubbish at Perl.
> 
> OK






view thread (11+ messages)  latest in thread

Message-ID: <4417791388e8f1df20f64013e944be8e@stjohn.se>
Permalink:  ../4417791388e8f1df20f64013e944be8e@stjohn.se/
Also on:    postgresql.org/message-id/4417791388e8f1df20f64013e944be8e@stjohn.se

 · 

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-bugs@postgresql.org
  Cc: jesper@stjohn.se, reshkekirill@gmail.com
  Subject: Re: Timing issue in pg_basebackup
  In-Reply-To: <4417791388e8f1df20f64013e944be8e@stjohn.se>
  References: <ddfa03dcf26f366ae493e8cc41bd479a@stjohn.se> <CALdSSPj_M=6RLR0XpXKVr_NWiaVAhT7g7wRaMx_--3kKZpT0SA@mail.gmail.com> <4417791388e8f1df20f64013e944be8e@stjohn.se>

* 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