@@ -650,6 +650,24 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
650
650
/* empty pages are always all-visible */
651
651
if (!PageIsAllVisible (page ))
652
652
{
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
+
653
671
PageSetAllVisible (page );
654
672
MarkBufferDirty (buf );
655
673
visibilitymap_set (onerel ,blkno ,InvalidXLogRecPtr ,vmbuffer ,