Fix hash index redo reading a torn primary bucket page. Replay of XLOG_HASH_DELETE, XLOG_HASH_MOVE_PAGE_CONTENTS and XLOG_HASH_SQUEEZE_PAGE reads the primary bucket page only to take a cleanup lock on it, so that no hot standby scan runs in the bucket while tuples are removed or moved. VACUUM holds only a pin on that page, so these records do not modify it and carry no full-page image of it.
If the on-disk page is torn and the full-page image that repairs it comes later in the WAL, this read fails with "invalid page". That can happen in crash recovery, and on a standby started from a base backup whose copy of the page is torn. The lock is needed only to serialize against hot standby scans, which can run only once recovery has reached consistency. Skip the read and lock while HotStandbyActiveInReplay() is false. This also avoids reading the page before its repairing image has been replayed, since that image always precedes the consistency point. Reported-by: shihao zhong <[email protected]> Author: Greg Burd <[email protected]> Co-authored-by: Vignesh C <[email protected]> Suggested-by: Amit Kapila <[email protected]> Reviewed-by: Joao Rito <[email protected]> Reviewed-by: Amit Kapila <[email protected]> Discussion: https://postgr.es/m/CAGRkXqT_AiwcsWZg5hnR1L2oWO8UpQpkL0iAjoZR+bey=go...@mail.gmail.com Discussion: https://postgr.es/m/caa4ek1lwzk0mak0lnczz6hsqchnamfjb47na8xuwrp4cylf...@mail.gmail.com Backpatch-through: 15 Branch ------ REL_19_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/21c45d45d04efab45cf73c491127bfe4a31743a3 Modified Files -------------- src/backend/access/hash/hash_xlog.c | 52 +++++++++++++++++++++++++------ src/backend/access/transam/xlogrecovery.c | 3 +- src/include/access/xlogrecovery.h | 1 + 3 files changed, 45 insertions(+), 11 deletions(-)
