diff --git a/src/backend/distributed/commands/dependencies.c b/src/backend/distributed/commands/dependencies.c index 258f5ec51..0f7bf627b 100644 --- a/src/backend/distributed/commands/dependencies.c +++ b/src/backend/distributed/commands/dependencies.c @@ -88,6 +88,17 @@ EnsureDependenciesExistOnAllNodes(const ObjectAddress *target) */ List *workerNodeList = ActivePrimaryNonCoordinatorNodeList(RowShareLock); + /* + * Lock dependent objects explicitly to make sure same DDL command won't be sent + * multiple times from parallel sessions. Having IF EXISTS may not handle locking + * issues if sent from parallel sessions. + */ + foreach_ptr(dependency, dependenciesWithCommands) + { + LockDatabaseObject(dependency->classId, dependency->objectId, + dependency->objectSubId, RowExclusiveLock); + } + /* * right after we acquired the lock we mark our objects as distributed, these changes * will not become visible before we have successfully created all the objects on our