aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Grittner <kgrittn@postgresql.org>2013-03-06 17:15:34 -0600
committerKevin Grittner <kgrittn@postgresql.org>2013-03-06 17:15:34 -0600
commitc5bf7a2052c8e7ebbd1ca3986525c3629d7345d1 (patch)
treef40088a4a14b0d63b6fea8d8d8d5ce38be562f1d
parent5141603ebd162a50c36583f1a80eceadc94ef25e (diff)
downloadpostgresql-c5bf7a2052c8e7ebbd1ca3986525c3629d7345d1.tar.gz
postgresql-c5bf7a2052c8e7ebbd1ca3986525c3629d7345d1.zip
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.
-rw-r--r--src/backend/commands/matview.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c
index e040bedb7e5..6a0643828a4 100644
--- a/src/backend/commands/matview.c
+++ b/src/backend/commands/matview.c
@@ -14,6 +14,7 @@
*/
#include "postgres.h"
+#include "access/heapam_xlog.h"
#include "access/multixact.h"
#include "access/relscan.h"
#include "access/xact.h"
@@ -68,10 +69,15 @@ SetRelationIsScannable(Relation relation)
Assert(relation->rd_rel->relkind == RELKIND_MATVIEW);
Assert(relation->rd_isscannable == false);
- RelationOpenSmgr(relation);
page = (Page) palloc(BLCKSZ);
PageInit(page, BLCKSZ, 0);
+
+ if (RelationNeedsWAL(relation))
+ log_newpage(&(relation->rd_node), MAIN_FORKNUM, 0, page);
+
+ RelationOpenSmgr(relation);
smgrextend(relation->rd_smgr, MAIN_FORKNUM, 0, (char *) page, true);
+
pfree(page);
smgrimmedsync(relation->rd_smgr, MAIN_FORKNUM);