pgsql: Wake primary_flush waiters after implicit WAL flushes

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Wake primary_flush waiters after implicit WAL flushes
Date: 2026-09-12 20:30:45
Message-ID: E1x5UN3-000000003qq-02gk@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Wake primary_flush waiters after implicit WAL flushes

XLogWrite() can advance the flush position when it finishes a WAL
segment, even if its caller requested only a write. When this happens
while AdvanceXLInsertBuffer() recycles a buffer, primary_flush waiters
are not notified and can sleep until an unrelated flush or checkpoint.

Track such progress with a process-local pending flag and perform the
wakeup after releasing WAL write and insertion locks, keeping
WaitLSNLock acquisition outside the contended WAL path. Add a
deterministic injection-point test that forces this path and inspects
the registration directly in shared memory.

Author: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Discussion: https://postgr.es/m/CABPTF7U0gW5%2B-4oL7-qdML-yerZxUb7ku4QXp7JxCYo0qyJ_Tw%40mail.gmail.com
Reviewed-by: Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d61f9c90f2ef96b38eceb592b63c688d74cf7611

Modified Files
--------------
src/backend/access/transam/xlog.c | 34 ++++++++
src/backend/access/transam/xlogwait.c | 3 +
src/backend/postmaster/walwriter.c | 3 +
src/test/recovery/t/049_wait_for_lsn.pl | 146 ++++++++++++++++++++++++++++++++
4 files changed, 186 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Alexander Korotkov 2026-09-12 20:30:50 pgsql: Prevent WAIT FOR LSN from deadlocking recovery on held locks
Previous Message Alexander Korotkov 2026-09-12 20:30:44 pgsql: Prevent WAIT FOR LSN from deadlocking recovery on held locks