Avoid trying to write an empty WAL record in log_newpage_range().
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 17 Apr 2023 18:22:06 +0000 (14:22 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 17 Apr 2023 18:22:06 +0000 (14:22 -0400)
commitc796d7296978e1ac09bcbb41c9230b6cc32b7d44
treec75f9cc78ac05da0f3f1087c386844314f518607
parentea7894d33d174c2fb76ad838cf9a7a17d604a950
Avoid trying to write an empty WAL record in log_newpage_range().

If the last few pages in the specified range are empty (all zero),
then log_newpage_range() could try to emit an empty WAL record
containing no FPIs.  This at least upsets an Assert in
ReserveXLogInsertLocation, and might perhaps have bad real-world
consequences in non-assert builds.

This has been broken since log_newpage_range() was introduced,
but the case was hard if not impossible to hit before commit 3d6a98457
decided it was okay to leave VM and FSM pages intentionally zero.
Nonetheless, it seems prudent to back-patch.  log_newpage_range()
was added in v12 but later back-patched, so this affects all
supported branches.

Matthias van de Meent, per report from Justin Pryzby

Discussion: https://postgr.es/m/ZD1daibg4RF50IOj@telsasoft.com
src/backend/access/transam/xloginsert.c