| From: | Melanie Plageman <melanieplageman(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Andres Freund <andres(at)anarazel(dot)de> |
| Subject: | Hardening visibility-map maintenance and recovery |
| Date: | 2026-09-25 21:54:01 |
| Message-ID: | CAAKRu_aaP=0GZe+D721byOM9Vwjtu94VdAE_em0PNC0r3EK2zg@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
After getting involved in the discussion of corruption caused by
CREATE DATABASE (from template) STRATEGY WAL_LOG [1], I started
thinking about how we could prevent and fix VM corruption in more
cases.
After ed62d26caca, the idea was that both setting and clearing the VM
always registered the VM block, so we would be protected against VM
corruption. This turned out to not work if the VM got removed somehow
from the primary or standby and they got out-of-sync (like in [1]). I
have some stop-gap fixes proposed for that in [2]. However, I think if
we make some bigger changes, we can prevent and repair scenarios like
this.
The patches attached do the following visibility map hardening:
- WAL-log page corruption repair so that it is propagated to the
standby (and isn't lost after a crash). Also extend page corruption
repair to cover a few more scenarios.
- Register the VM buffer whenever INSERT/UPDATE/DELETE clears
PD_ALL_VISIBLE, even if the VM bits were already clear on the primary.
This repairs divergence and can't result in torn pages during recovery
like the stop-gap strategy.
- Stop reading the VM with RBM_ZERO_ON_ERROR. Introduce a new mode,
RBM_ZERO_ON_MISSING, that allows extending if the page is not created
yet but errors on corrupt pages.
This series also makes zero_damaged_pages a string instead of a
boolean so you can specify 'vm' instead of just on and allow you to
ignore and zero out the VM if it is corrupt during recovery.
There's also a patch to stop masking PD_ALL_VISIBLE WAL consistency
checking during recovery in [3] (see v6-0002), which I plan to commit
soon once sources of this kind of corruption are fixed.
The aim is to prevent avoidable divergence, make repairs durable, and
leave better evidence when corruption does occur. (note that patch set
doesn't have tests yet)
- Melanie
[1] https://www.postgresql.org/message-id/CAAKRu_bK7oJvtrrzL_V-OHouCWDKyU2-ERv%2BQvV6XM9Wh2dpUg%40mail.gmail.com
[2] https://www.postgresql.org/message-id/CAAKRu_bApoksLDb-HX0GYciU3uLWqA1JagntaV8GP0%3D%2BidehHw%40mail.gmail.com
[3] https://www.postgresql.org/message-id/CAAKRu_aRdQ6RjneKeQh9%2BRVMFgMrtjTYFX%3DzDgBdSiQ8JDs6Jg%40mail.gmail.com
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Detect-and-repair-a-stale-all-frozen-visibility-m.patch | text/x-patch | 3.3 KB |
| v1-0002-WAL-log-visibility-map-corruption-repair.patch | text/x-patch | 3.9 KB |
| v1-0003-Make-heap_page_fix_vm_corruption-usable-outside-o.patch | text/x-patch | 12.3 KB |
| v1-0004-Repair-visibility-map-corruption-on-empty-pages.patch | text/x-patch | 3.9 KB |
| v1-0005-Register-the-VM-buffer-whenever-clearing-PD_ALL_V.patch | text/x-patch | 9.0 KB |
| v1-0006-Factor-out-parsing-of-flag-list-GUCs-with-boolean.patch | text/x-patch | 11.1 KB |
| v1-0007-Make-zero_damaged_pages-selectable-per-relation-f.patch | text/x-patch | 12.2 KB |
| v1-0008-Add-RBM_ZERO_ON_MISSING-and-read-the-visibility-m.patch | text/x-patch | 7.3 KB |
| v1-0009-Return-the-prior-visibility-map-bits-from-visibil.patch | text/x-patch | 4.7 KB |
| v1-0010-Warn-when-heap-redo-finds-a-diverged-visibility-m.patch | text/x-patch | 13.6 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | shihao zhong | 2026-09-25 22:03:16 | Re: GIN index fast list search may become un-interruptible for long time. |
| Previous Message | Nikhil Kumar Veldanda | 2026-09-25 21:42:11 | Re: ZSTD TOAST compression, and an extensible compression method encoding |