Skip to content

Commit 17fa4c3

Browse files
committed
Ensure that XLOG_HEAP2_VISIBLE always targets an initialized page.
Andres Freund
1 parent 4c641d9 commit 17fa4c3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/backend/commands/vacuumlazy.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,24 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
650650
/* empty pages are always all-visible */
651651
if (!PageIsAllVisible(page))
652652
{
653+
/*
654+
* It's possible that another backend has extended the heap,
655+
* initialized the page, and then failed to WAL-log the page
656+
* due to an ERROR. Since heap extension is not WAL-logged,
657+
* recovery might try to replay our record setting the
658+
* page all-visible and find that the page isn't initialized,
659+
* which will cause a PANIC. To prevent that, check whether
660+
* the page has been previously WAL-logged, and if not, do that
661+
* now.
662+
*
663+
* XXX: It would be nice to use a logging method supporting
664+
* standard buffers here since log_newpage_buffer() will write
665+
* the full block instead of omitting the hole.
666+
*/
667+
if (RelationNeedsWAL(onerel) &&
668+
XLByteEQ(PageGetLSN(page), InvalidXLogRecPtr))
669+
log_newpage_buffer(buf);
670+
653671
PageSetAllVisible(page);
654672
MarkBufferDirty(buf);
655673
visibilitymap_set(onerel, blkno, InvalidXLogRecPtr, vmbuffer,

0 commit comments

Comments
 (0)