]> granicus.if.org Git - postgresql/commitdiff
Lock relation used to generate fresh data for RMV.
authorKevin Grittner <kgrittn@postgresql.org>
Tue, 5 Nov 2013 21:36:33 +0000 (15:36 -0600)
committerKevin Grittner <kgrittn@postgresql.org>
Tue, 5 Nov 2013 21:36:33 +0000 (15:36 -0600)
The relation should not be accessible to any other process, but it
should be locked for consistency.  Since this is not known to
cause any bug, it will not be back-patch, at least for now.

Per report from Andres Freund

src/backend/commands/matview.c

index d5a10adc6717c4b5487080e6ed1bb86133918c48..e3b0cbb708e1961333bc050de0053067af723d17 100644 (file)
@@ -30,6 +30,7 @@
 #include "miscadmin.h"
 #include "parser/parse_relation.h"
 #include "rewrite/rewriteHandler.h"
+#include "storage/lmgr.h"
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
@@ -240,9 +241,14 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
 
        heap_close(matviewRel, NoLock);
 
-       /* Create the transient table that will receive the regenerated data. */
+       /*
+        * Create the transient table that will receive the regenerated data.
+        * Lock it against access by any other process until commit (by which time
+        * it will be gone).
+        */
        OIDNewHeap = make_new_heap(matviewOid, tableSpace, concurrent,
                                                           ExclusiveLock);
+       LockRelationOid(OIDNewHeap, AccessExclusiveLock);
        dest = CreateTransientRelDestReceiver(OIDNewHeap);
 
        /* Generate the data, if wanted. */