diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 3a07705008..9e39d949b5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -3612,7 +3612,24 @@ reindex_index(Oid indexId, bool skip_constraint_checks, char persistence, * Open the target index relation and get an exclusive lock on it, to * ensure that no one else is touching this particular index. */ - iRel = index_open(indexId, AccessExclusiveLock); + if ((params->options & REINDEXOPT_MISSING_OK) != 0) + iRel = try_index_open(indexId, AccessExclusiveLock); + else + iRel = index_open(indexId, AccessExclusiveLock); + + /* if index relation is gone, leave */ + if (!iRel) + { + /* Roll back any GUC changes */ + AtEOXact_GUC(false, save_nestlevel); + + /* Restore userid and security context */ + SetUserIdAndSecContext(save_userid, save_sec_context); + + /* Close parent heap relation, but keep locks */ + table_close(heapRelation, NoLock); + return; + } if (progress) pgstat_progress_update_param(PROGRESS_CREATEIDX_ACCESS_METHOD_OID,