Skip to content

Commit 72a914e

Browse files
committed
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 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
1 parent 9b104a2 commit 72a914e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/backend/access/transam/xloginsert.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,10 @@ log_newpage_range(Relation rel, ForkNumber forkNum,
11711171
blkno++;
11721172
}
11731173

1174+
/* Nothing more to do if all remaining blocks were empty. */
1175+
if (nbufs == 0)
1176+
break;
1177+
11741178
/* Write WAL record for this batch. */
11751179
XLogBeginInsert();
11761180

0 commit comments

Comments
 (0)