diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index e3b0cbb708..4a7805057e 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -239,8 +239,6 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, owner = matviewRel->rd_rel->relowner; - heap_close(matviewRel, NoLock); - /* * Create the transient table that will receive the regenerated data. * Lock it against access by any other process until commit (by which time @@ -255,6 +253,8 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, if (!stmt->skipData) refresh_matview_datafill(dest, dataQuery, queryString, owner); + heap_close(matviewRel, NoLock); + /* Make the matview match the newly generated data. */ if (concurrent) {