amcheck: detect corruption from the recent snapshot-export bug

Поиск
Список
Период
Сортировка
Искать

amcheck: detect corruption from the recent snapshot-export bug

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Вложения:
Hi hackers!

I was investigating foreign-key violations reported by a user after
failover. Some tuples had HEAP_XMIN_INVALID set despite their xmin being
committed in pg_xact. During the investigation I found the recent
snapshot-export bug thread [0], with a fix already committed.

pg_visibility reported the affected tuples on the standby, but
verify_heapam() did not. We routinely run verify_heapam() and would like
it to catch this damage without having to scan the same tables again
with pg_visibility.

PFA a two-patch series. 0001 detects this damage by reporting
HEAP_XMIN_INVALID when xmin is known to have committed. It excludes
old-style VACUUM FULL tuples and does not treat an assumed commit after
pg_xact truncation as evidence of corruption.

I think it would be good to have such check backpatched along with the
corruption fix.

0002 revisits the related xmin/xmax checks I proposed in 2024 [1]. It
checks committed hints against aborted transactions, and invalid xmax
hints against committed updaters, including multixact members. I kept
these separate so that we can address the known corruption first.

The first patch's test also covers HEAP_MOVED_IN, though I'm not sure
it's worth adding coverage for this old VACUUM FULL format.

I am still thinking about how best to repair the existing damage.

Thank you!


Best regards, Andrey Borodin.

[0] https://postgr.es/m/CAH2-WzmHVeYY%3Dpjz9x8DhhxVjXHX0pvoQ-MdiB1Tt6%3Do2GTiKg%40mail.gmail.com
[1] https://postgr.es/m/BE90C4F8-9A37-40AD-A5CC-9818BBE59BCC@yandex-team.ru

Re: amcheck: detect corruption from the recent snapshot-export bug

От:
Mark Dilger <mark.dilger@enterprisedb.com>
Дата:


On Sun, Oct 4, 2026 at 6:51 AM Andrey Borodin <x4mmm@yandex-team.ru> wrote:
Hi hackers!

I was investigating foreign-key violations reported by a user after
failover. Some tuples had HEAP_XMIN_INVALID set despite their xmin being
committed in pg_xact. During the investigation I found the recent
snapshot-export bug thread [0], with a fix already committed.

pg_visibility reported the affected tuples on the standby, but
verify_heapam() did not. We routinely run verify_heapam() and would like
it to catch this damage without having to scan the same tables again
with pg_visibility.

PFA a two-patch series. 0001 detects this damage by reporting
HEAP_XMIN_INVALID when xmin is known to have committed. It excludes
old-style VACUUM FULL tuples and does not treat an assumed commit after
pg_xact truncation as evidence of corruption.

This also affects HEAP_XMAX_INVALID for committed deletions. 
 
I think it would be good to have such check backpatched along with the
corruption fix.

0002 revisits the related xmin/xmax checks I proposed in 2024 [1]. It
checks committed hints against aborted transactions, and invalid xmax
hints against committed updaters, including multixact members. I kept
these separate so that we can address the known corruption first.

The first patch's test also covers HEAP_MOVED_IN, though I'm not sure
it's worth adding coverage for this old VACUUM FULL format.

A minor nit:  the new error messages do not follow existing style.

I believe this patch set fixes a real bug.  Thanks for finding it. 

-- Mark Dilger

Re: amcheck: detect corruption from the recent snapshot-export bug

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Вложения:
Hi Mark,

On 5 Oct 2026, Mark Dilger wrote:
> This also affects HEAP_XMAX_INVALID for committed deletions.

Yesterday in an off-list conversation I replied that: "Users reported
disappearing rows. So I wasn’t looking for emerging rows..."

Coincidentally, another production case reached me today: an old tuple
version has HEAP_XMAX_INVALID set for a committed updater, and VACUUM
fails with "cannot freeze committed xmax", just like in 2024. We have
not yet established whether snapshot export caused it, but likely so.
A cluster at hand has lots of savepoints and exprted snapshots, but
offending rows emerged in May.

That check was in 0002. In the attached v2 I moved it and its tests into
0001, so the first patch covers both invalid hints. I also adjusted the
diagnostic wording.

Thank you!


Best regards, Andrey Borodin.

Re: amcheck: detect corruption from the recent snapshot-export bug

От:
Andrey Borodin <x4mmm@yandex-team.ru>
Дата:
Hi hackers,

On 6 Oct 2026, I wrote:
> In the attached v2 I moved it and its tests into
> 0001, so the first patch covers both invalid hints.

Is there any chance of backpatching 0001 from v2 in time for the
upcoming minor releases? I have observed this corruption in production,
and verify_heapam() still does not detect it.

Thank you!


Best regards, Andrey Borodin.



FAQ