Re: Timing issue in pg_basebackup

From: Kirill Reshke <reshkekirill(at)gmail(dot)com>
To: Jesper St John <jesper(at)stjohn(dot)se>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Timing issue in pg_basebackup
Date: 2026-10-20 21:11:32
Message-ID: CALdSSPj_M=6RLR0XpXKVr_NWiaVAhT7g7wRaMx_--3kKZpT0SA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, 19 Oct 2026 at 19:33, Jesper St John <jesper(at)stjohn(dot)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.

> 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?

NIT: comment in PrepareLogStreamer loses its meaning after code motion:

+ /* Get a second connection */
+ bgconn = GetConnection();

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

OK

--
Best regards,
Kirill Reshke

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-10-21 00:29:28 Re: BUG #19763: ManualBug2 NULL pointer dereference in make_build_data via examine_expression bypass of lookup_var_a
Previous Message Matheus Alcantara 2026-10-20 19:30:11 Re: BUG #19772: ERROR: corrupt MVNDistinct entry for GROUP BY c0, ROLLUP (abs(c0)) with ndistinct statistics