From affe38eac695d34a3b8d3cd9c18411de10fb5b66 Mon Sep 17 00:00:00 2001 From: Hadi Moshayedi Date: Tue, 2 Mar 2021 15:58:06 -0800 Subject: [PATCH] Populate DATABASEOID cache before CREATE INDEX CONCURRENTLY --- src/backend/distributed/commands/utility_hook.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index 525faa6b7..adde39dbf 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -910,6 +910,19 @@ ExecuteDistributedDDLJob(DDLJob *ddlJob) */ if (ddlJob->startNewTransaction) { + /* + * If cache is not populated, system catalog lookups will cause + * the xmin of current backend to change. Then the last phase + * of CREATE INDEX CONCURRENTLY, which is in a separate backend, + * will hang waiting for our backend and result in a deadlock. + * + * We populate the cache before starting the next transaction to + * avoid this. Most of the metadata has already been resolved in + * planning phase, we only need to lookup metadata needed for + * connection establishment. + */ + (void) CurrentDatabaseName(); + CommitTransactionCommand(); StartTransactionCommand(); }