Re: pgsql: Implement WAIT FOR command

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pgsql: Implement WAIT FOR command
Date: 2026-01-26 23:33:50
Message-ID: 9533608f-f289-44bd-b881-9e5a73203c5b@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2026-01-26 23:33:55 Re: Parallel CREATE INDEX for GIN indexes
Previous Message Tomas Vondra 2026-01-26 23:32:28 Re: failed NUMA pages inquiry status: Operation not permitted

Browse pgsql-committers by date

  From Date Subject
Previous Message Tomas Vondra 2026-01-26 23:32:28 Re: failed NUMA pages inquiry status: Operation not permitted