Re: BUG #18426: Canceling vacuum while truncating a relation leads to standby PANIC

Alexander Law <exclusion@gmail.com>

From: Alexander Lakhin <exclusion@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Date: 2024-04-10T18:00:00Z
Lists: pgsql-bugs

Attachments

10.04.2024 14:00, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference:      18426
> ...
> A demo test for the issue to follow...

Please try the attached patch (for REL_16_STABLE), which:
1) adds a delay inside InvalidateBuffer() to allow for canceling the
   operation here.
2) invokes ProcessInterrupts() which would be called if
   (buf_state & BM_IO_IN_PROGRESS) inside ConditionVariableSleep() ->
   ConditionVariableTimedSleep().
(If you find these changes non-legitimate, I'll look for another approach.)

3) contains test 099_stream_vacuum, based on 027_stream_regress.

make -s check -C src/test/recovery/ PROVE_TESTS="t/099*"
fails for me (roughly on 1 of 2 runs) just like in the case observed in
the wild:
...
2024-04-10 17:20:54.521 UTC|||6616ca5a.26a393|WARNING:  page 90 of relation base/16402/16929 does not exist
2024-04-10 17:20:54.521 UTC|||6616ca5a.26a393|CONTEXT:  WAL redo at 0/DCD12AC0 for Heap2/VISIBLE: 
snapshotConflictHorizon: 0, flags: 0x03; blkref #0: rel 1663/16402/16929, fork 2, blk 0; blkref #1: rel 
1663/16402/16929, blk 90
2024-04-10 17:20:54.521 UTC|||6616ca5a.26a393|PANIC:  WAL contains references to invalid pages
2024-04-10 17:20:54.521 UTC|||6616ca5a.26a393|CONTEXT:  WAL redo at 0/DCD12AC0 for Heap2/VISIBLE: 
snapshotConflictHorizon: 0, flags: 0x03; blkref #0: rel 1663/16402/16929, fork 2, blk 0; blkref #1: rel 
1663/16402/16929, blk 90
2024-04-10 17:20:54.532 UTC|||6616ca5a.26a390|LOG:  startup process (PID 2532243) was terminated by signal 6: Aborted
...

Best regards,
Alexander

Commits

  1. Fix corruption when relation truncation fails.

  2. Replace buffer I/O locks with condition variables.