Re: Implement waiting for wal lsn replay: reloaded
Alexander Korotkov <aekorotkov@gmail.com>
On Wed, Jan 7, 2026 at 6:08 AM Xuneng Zhou <xunengzhou@gmail.com> wrote: > On Wed, Jan 7, 2026 at 8:32 AM Andres Freund <andres@anarazel.de> wrote: > > On 2026-01-06 18:42:59 +1300, Thomas Munro wrote: > > > Could this be causing the recent flapping failures on CI/macOS in > > > recovery/031_recovery_conflict? I didn't have time to dig personally > > > but f30848cb looks relevant: > > > > > > Waiting for replication conn standby's replay_lsn to pass 0/03467F58 on primary > > > error running SQL: 'psql:<stdin>:1: ERROR: canceling statement due to > > > conflict with recovery > > > DETAIL: User was or might have been using tablespace that must be dropped.' > > > while running 'psql --no-psqlrc --no-align --tuples-only --quiet > > > --dbname port=25195 > > > host=/var/folders/g9/7rkt8rt1241bwwhd3_s8ndp40000gn/T/LqcCJnsueI > > > dbname='postgres' --file - --variable ON_ERROR_STOP=1' with sql 'WAIT > > > FOR LSN '0/03467F58' WITH (MODE 'standby_replay', timeout '180s', > > > no_throw);' at /Users/admin/pgsql/src/test/perl/PostgreSQL/Test/Cluster.pm > > > line 2300. > > > > > > https://cirrus-ci.com/task/5771274900733952 > > > > > > The master branch in time-descending order, macOS tasks only: > > > > > > task_id | substring | status > > > ------------------+-----------+----------- > > > 6460882231754752 | c970bdc0 | FAILED > > > 5771274900733952 | 6ca8506e | FAILED > > > 6217757068361728 | 63ed3bc7 | FAILED > > > 5980650261446656 | ae283736 | FAILED > > > 6585898394976256 | 5f13999a | COMPLETED > > > 4527474786172928 | 7f9acc9b | COMPLETED > > > 4826100842364928 | e8d4e94a | COMPLETED > > > 4540563027918848 | b9ee5f2d | FAILED > > > 6358528648019968 | c5af141c | FAILED > > > 5998005284765696 | e212a0f8 | COMPLETED > > > 6488580526178304 | b85d5dc0 | FAILED > > > 5034091344560128 | 7dc95cc3 | ABORTED > > > 5688692477526016 | bb048e31 | COMPLETED > > > 5481187977723904 | d351063e | COMPLETED > > > 5101831568752640 | f30848cb | COMPLETED <-- the change > > > 6395317408497664 | 3f33b63d | COMPLETED > > > 6741325208354816 | 877ae5db | COMPLETED > > > 4594007789010944 | de746e0d | COMPLETED > > > 6497208998035456 | 461b8cc9 | COMPLETED > > > > The failure rates of this are very high - the majority of the CI runs on the > > postgres/postgres repos failed since the change went in. Which then also means > > cfbot has a very high spurious failure rate. I think we need to revert this > > change until the problem has been verified as fixed. > > This specific failure can be reproduced with this patch v1. > > I guess the potential race condition is: when > wait_for_replay_catchup() runs WAIT FOR LSN on the standby, if a > tablespace conflict fires during that wait, the WAIT FOR LSN session > is killed even though it doesn't use the tablespace. > > In my test, the failure won't occur after applying the v2 patch. I see, you were right. This is not related to the MyProc->xmin. ResolveRecoveryConflictWithTablespace() calls GetConflictingVirtualXIDs(InvalidTransactionId, InvalidOid). That would kill WAIT FOR LSN query independently on its xmin. I guess your patch is the only way to go. It's clumsy to wrap WAIT FOR LSN call with retry loop, but it would still consume less resources than polling. ------ Regards, Alexander Korotkov Supabase
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Clean up 019_replslot_limit.pl comments
- 0b866bb90368 19 (unreleased) landed
-
Stabilize 019_replslot_limit.pl: wait on slot restart_lsn
- cdb1d1cf1de6 19 (unreleased) landed
-
Fix memory ordering in WAIT FOR LSN wakeup mechanism
- a80a593ab636 19 (unreleased) landed
-
Improve WAIT FOR LSN test coverage
- cb096e6d6981 19 (unreleased) landed
-
Remove redundant WAIT FOR LSN caller-side pre-checks
- df9f938ca2ec 19 (unreleased) landed
-
Use barrier semantics when reading/writing writtenUpto
- dfb690dd5237 19 (unreleased) landed
-
Use replay position as floor for WAIT FOR LSN standby_(write|flush)
- cba67b5b87f9 19 (unreleased) landed
-
Wake standby_write/standby_flush waiters from the WAL replay loop
- e7cd592174d9 19 (unreleased) landed
-
Minimal fix for WAIT FOR ... MODE 'standby_flush'
- 29e7dbf5e4da 19 (unreleased) landed
-
Avoid syscache lookup while building a WAIT FOR tuple descriptor
- 834038c1f8d5 19 (unreleased) landed
-
Document that WAIT FOR may be interrupted by recovery conflicts
- 10484c2cc75b 19 (unreleased) landed
-
Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()
- 7e8aeb9e483d 19 (unreleased) landed
- f30848cb05d4 19 (unreleased) landed
-
Wake LSN waiters before recovery target stop
- 20a8f783e15c 19 (unreleased) landed
-
Remove redundant pg_unreachable() after elog(ERROR) from ExecWaitStmt()
- 30776ca46865 19 (unreleased) landed
-
Revert "Use WAIT FOR LSN in PostgreSQL::Test::Cluster::wait_for_catchup()"
- e54ce0b2da62 19 (unreleased) landed
-
Fix variable usage in wakeupWaiters()
- bf308639bfcf 19 (unreleased) landed
-
Add tab completion for the WAIT FOR LSN MODE option
- 76948337f724 19 (unreleased) landed
-
Add the MODE option to the WAIT FOR LSN command
- 49a181b5d634 19 (unreleased) landed
-
Extend xlogwait infrastructure with write and flush wait types
- 7a39f43d885b 19 (unreleased) landed
-
Unify error messages
- 502e256f2262 19 (unreleased) cited
-
Optimize shared memory usage for WaitLSNProcInfo
- 75e82b2f5a6f 19 (unreleased) landed
-
Fix WaitLSNWakeup() fast-path check for InvalidXLogRecPtr
- ede6acef4967 19 (unreleased) landed
-
Fix incorrect function name in comments
- 23792d738158 19 (unreleased) landed
-
Add infrastructure for efficient LSN waiting
- 3b4e53a075ea 19 (unreleased) landed
-
Add pairingheap_initialize() for shared memory usage
- 8af3ae0d4b36 19 (unreleased) landed
-
Implement WAIT FOR command
- 447aae13b030 19 (unreleased) landed