Skip to content

Commit de0bea8

Browse files
committed
Lock relation used to generate fresh data for RMV.
Back-patch the 9.4-era commit 2636ecf into 9.3, as that fixes a case where we open a relation while not holding any lock on it. It's probably mostly safe anyway, since no other session could touch the newly-created table; but I think CheckTableNotInUse could be fooled if one tried. Per testing with a patch that complains if we open a relation without holding any lock on it. I don't plan to back-patch that patch, but we should close the holes it identifies in all supported branches. Discussion: https://postgr.es/m/2038.1538335244@sss.pgh.pa.us
1 parent 00d00b5 commit de0bea8

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
@@ -26,6 +26,7 @@
2626
#include "executor/executor.h"
2727
#include "miscadmin.h"
2828
#include "rewrite/rewriteHandler.h"
29+
#include "storage/lmgr.h"
2930
#include "storage/smgr.h"
3031
#include "tcop/tcopprot.h"
3132
#include "utils/rel.h"
@@ -208,8 +209,13 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
208209

209210
tableSpace = matviewRel->rd_rel->reltablespace;
210211

211-
/* Create the transient table that will receive the regenerated data. */
212+
/*
213+
* Create the transient table that will receive the regenerated data. Lock
214+
* it against access by any other process until commit (by which time it
215+
* will be gone).
216+
*/
212217
OIDNewHeap = make_new_heap(matviewOid, tableSpace);
218+
LockRelationOid(OIDNewHeap, AccessExclusiveLock);
213219
dest = CreateTransientRelDestReceiver(OIDNewHeap);
214220

215221
/* Generate the data, if wanted. */

0 commit comments

Comments
 (0)