From a2f7eadeb9fba32b46158eec6f6837b1bf1b2ac3 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Fri, 11 Sep 2020 16:02:00 -0700 Subject: [PATCH] lock while initializing relfilenode --- cstore_fdw.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cstore_fdw.c b/cstore_fdw.c index 5ad465807..07b47d590 100644 --- a/cstore_fdw.c +++ b/cstore_fdw.c @@ -948,12 +948,21 @@ InitializeRelFileNode(Relation relation) if (!OidIsValid(classform->relfilenode)) { + Relation tmprel; Oid tablespace; Oid filenode = relation->rd_id; char persistence = relation->rd_rel->relpersistence; RelFileNode newrnode; SMgrRelation srel; + /* + * Upgrade to AccessExclusiveLock, and hold until the end of the + * transaction. This shouldn't happen during a read, but it's hard to + * prove that because it happens lazily. + */ + tmprel = heap_open(relation->rd_id, AccessExclusiveLock); + heap_close(tmprel, NoLock); + if (OidIsValid(relation->rd_rel->reltablespace)) tablespace = relation->rd_rel->reltablespace; else