Add infrastructure for efficient LSN waiting
Alexander Korotkov <akorotkov@postgresql.org>
Author:
Alexander Korotkov <akorotkov@postgresql.org>
Date: 2025-11-05T09:44:13Z
Releases:
19 (unreleased)
Add infrastructure for efficient LSN waiting Implement a new facility that allows processes to wait for WAL to reach specific LSNs, both on primary (waiting for flush) and standby (waiting for replay) servers. The implementation uses shared memory with per-backend information organized into pairing heaps, allowing O(1) access to the minimum waited LSN. This enables fast-path checks: after replaying or flushing WAL, the startup process or WAL writer can quickly determine if any waiters need to be awakened. Key components: - New xlogwait.c/h module with WaitForLSNReplay() and WaitForLSNFlush() - Separate pairing heaps for replay and flush waiters - WaitLSN lightweight lock for coordinating shared state - Wait events WAIT_FOR_WAL_REPLAY and WAIT_FOR_WAL_FLUSH for monitoring This infrastructure can be used by features that need to wait for WAL operations to complete. Discussion: https://www.postgresql.org/message-id/flat/CAPpHfdsjtZLVzxjGT8rJHCYbM0D5dwkO+BBjcirozJ6nYbOW8Q@mail.gmail.com Discussion: https://www.postgresql.org/message-id/flat/CABPTF7UNft368x-RgOXkfj475OwEbp%2BVVO-wEXz7StgjD_%3D6sw%40mail.gmail.com Author: Kartyshov Ivan <i.kartyshov@postgrespro.ru> Author: Alexander Korotkov <aekorotkov@gmail.com> Author: Xuneng Zhou <xunengzhou@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Reviewed-by: Peter Eisentraut <peter.eisentraut@enterprisedb.com> Reviewed-by: Dilip Kumar <dilipbalaut@gmail.com> Reviewed-by: Amit Kapila <amit.kapila16@gmail.com> Reviewed-by: Alexander Lakhin <exclusion@gmail.com> Reviewed-by: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com> Reviewed-by: Euler Taveira <euler@eulerto.com> Reviewed-by: Heikki Linnakangas <hlinnaka@iki.fi> Reviewed-by: Kyotaro Horiguchi <horikyota.ntt@gmail.com> Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Files
| Path | Change | +/− |
|---|---|---|
| src/backend/access/transam/Makefile | modified | +2 −1 |
| src/backend/access/transam/meson.build | modified | +1 −0 |
| src/backend/access/transam/xlogwait.c | added | +409 −0 |
| src/backend/storage/ipc/ipci.c | modified | +3 −0 |
| src/backend/utils/activity/wait_event_names.txt | modified | +3 −0 |
| src/include/access/xlogwait.h | added | +98 −0 |
| src/include/storage/lwlocklist.h | modified | +1 −0 |
| src/tools/pgindent/typedefs.list | modified | +4 −0 |
Discussion
- Improve read_local_xlog_page_guts by replacing polling with latch-based waiting 20 messages · 2025-08-27 → 2026-06-08
- Implement waiting for wal lsn replay: reloaded 154 messages · 2024-11-27 → 2026-07-08