aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-04-17 14:22:06 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2023-04-17 14:22:06 -0400
commit2207df7c34bfcecec33da2a47068e94d7882ffdb (patch)
treea6d4e7977031f7bd1a0d33df4effac28b7f61a96
parentc53ed26ea46e425c1a78bd0e72b74a541eb08a93 (diff)
downloadpostgresql-2207df7c34bfcecec33da2a47068e94d7882ffdb.tar.gz
postgresql-2207df7c34bfcecec33da2a47068e94d7882ffdb.zip
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
-rw-r--r--src/backend/access/transam/xloginsert.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 2ce9be2cc76..35cc0559f9d 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -1256,6 +1256,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();