pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Alexander Korotkov <akorotkov@postgresql.org>
Cc: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Subject: Re: pgsql: Implement WAIT FOR command
Date: Tue, 27 Jan 2026 01:33:50 +0200
Message-ID: <9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi> (raw)
In-Reply-To: <E1vGa4M-0058H1-2k@gemulon.postgresql.org>
References: <E1vGa4M-0058H1-2k@gemulon.postgresql.org>

On 05/11/2025 11:44, Alexander Korotkov wrote:
> Implement WAIT FOR command

Happened to just spot this:

> @@ -1831,20 +1832,30 @@ PerformWalRecovery(void)
>  			 */
>  			ApplyWalRecord(xlogreader, record, &replayTLI);
>  
>  			/* Exit loop if we reached inclusive recovery target */
>  			if (recoveryStopsAfter(xlogreader))
>  			{
>  				reachedRecoveryTarget = true;
>  				break;
>  			}
>  
> +			/*
> +			 * If we replayed an LSN that someone was waiting for then walk
> +			 * over the shared memory array and set latches to notify the
> +			 * waiters.
> +			 */
> +			if (waitLSNState &&
> +				(XLogRecoveryCtl->lastReplayedEndRecPtr >=
> +				 pg_atomic_read_u64(&waitLSNState->minWaitedLSN[WAIT_LSN_TYPE_REPLAY])))
> +				WaitLSNWakeup(WAIT_LSN_TYPE_REPLAY, XLogRecoveryCtl->lastReplayedEndRecPtr);
> +
>  			/* Else, try to fetch the next WAL record */
>  			record = ReadRecord(xlogprefetcher, LOG, false, replayTLI);
>  		} while (record != NULL);
>  
>  		/*
>  		 * end of main redo apply loop
>  		 */
>  
>  		if (reachedRecoveryTarget)
>  		{

I think that WaitLSNWakeup() call is a little misplaced. It's after the 
recoveryStopsAfter() call, so if recovery is paused right after the 
record, the waiters won't be woken up until recovery is continued. And I 
suppose if recovery is stopped and the server is promoted, the waiters 
will never be woken up, although I didn't verify that.

To fix, that should be moved to between the ApplyWalRecord() and 
recoveryStopsHere() calls.

- Heikki






view thread (2+ messages)

Message-ID: <9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi>
Permalink:  ../9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi/
Also on:    postgresql.org/message-id/9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: hlinnaka@iki.fi, akorotkov@postgresql.org, pgsql-hackers@postgresql.org
  Subject: Re: pgsql: Implement WAIT FOR command
  In-Reply-To: <9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi>

* 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