Skip to content

Commit

Permalink
Avoid trying to write an empty WAL record in log_newpage_range().
Browse files Browse the repository at this point in the history
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 3d6a984
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
  • Loading branch information
tglsfdc committed Apr 17, 2023
1 parent cd7cdc5 commit 3e383f9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/backend/access/transam/xloginsert.c
Expand Up @@ -1304,6 +1304,10 @@ log_newpage_range(Relation rel, ForkNumber forknum,
blkno++;
}

/* Nothing more to do if all remaining blocks were empty. */
if (nbufs == 0)
break;

/* Write WAL record for this batch. */
XLogBeginInsert();

Expand Down

0 comments on commit 3e383f9

Please sign in to comment.