Skip to content

Commit c5bf7a2

Browse files
committed
WAL-log the extension of a new empty MV heap which is being populated.
This page with no tuples is used to distinguish an MV containing a zero-row resultset of its backing query from an MV which has not been populated by its backing query. Unless WAL-logged, recovery and hot standby don't work correctly with what should be an empty but scannable materialized view. Fixes bugs reported by Fujii Masao in testing MVs on hot standby.
1 parent 5141603 commit c5bf7a2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/commands/matview.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515
#include "postgres.h"
1616

17+
#include "access/heapam_xlog.h"
1718
#include "access/multixact.h"
1819
#include "access/relscan.h"
1920
#include "access/xact.h"
@@ -68,10 +69,15 @@ SetRelationIsScannable(Relation relation)
6869
Assert(relation->rd_rel->relkind == RELKIND_MATVIEW);
6970
Assert(relation->rd_isscannable == false);
7071

71-
RelationOpenSmgr(relation);
7272
page = (Page) palloc(BLCKSZ);
7373
PageInit(page, BLCKSZ, 0);
74+
75+
if (RelationNeedsWAL(relation))
76+
log_newpage(&(relation->rd_node), MAIN_FORKNUM, 0, page);
77+
78+
RelationOpenSmgr(relation);
7479
smgrextend(relation->rd_smgr, MAIN_FORKNUM, 0, (char *) page, true);
80+
7581
pfree(page);
7682

7783
smgrimmedsync(relation->rd_smgr, MAIN_FORKNUM);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy