Skip to content
Snippets Groups Projects
Commit de0bea8d authored by Tom Lane's avatar Tom Lane
Browse files

Lock relation used to generate fresh data for RMV.

Back-patch the 9.4-era commit 2636ecf7 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
parent 00d00b5b
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "executor/executor.h" #include "executor/executor.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "rewrite/rewriteHandler.h" #include "rewrite/rewriteHandler.h"
#include "storage/lmgr.h"
#include "storage/smgr.h" #include "storage/smgr.h"
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
#include "utils/rel.h" #include "utils/rel.h"
...@@ -208,8 +209,13 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ...@@ -208,8 +209,13 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
tableSpace = matviewRel->rd_rel->reltablespace; tableSpace = matviewRel->rd_rel->reltablespace;
/* 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); OIDNewHeap = make_new_heap(matviewOid, tableSpace);
LockRelationOid(OIDNewHeap, AccessExclusiveLock);
dest = CreateTransientRelDestReceiver(OIDNewHeap); dest = CreateTransientRelDestReceiver(OIDNewHeap);
/* Generate the data, if wanted. */ /* Generate the data, if wanted. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment