diff --git a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c index bb4ab7473..98bf0f2c7 100644 --- a/src/backend/distributed/commands/citus_add_local_table_to_metadata.c +++ b/src/backend/distributed/commands/citus_add_local_table_to_metadata.c @@ -1131,7 +1131,7 @@ DropIdentitiesOnTable(Oid relationId) { Relation relation = relation_open(relationId, AccessShareLock); TupleDesc tupleDescriptor = RelationGetDescr(relation); - relation_close(relation, NoLock); + List *dropCommandList = NIL; for (int attributeIndex = 0; attributeIndex < tupleDescriptor->natts; attributeIndex++) @@ -1151,14 +1151,23 @@ DropIdentitiesOnTable(Oid relationId) qualifiedTableName, columnName); - /* - * We need to disable/enable ddl propagation for this command, to prevent - * sending unnecessary ALTER COLUMN commands for partitions, to MX workers. - */ - ExecuteAndLogUtilityCommandList(list_make3(DISABLE_DDL_PROPAGATION, - dropCommand->data, - ENABLE_DDL_PROPAGATION)); + dropCommandList = lappend(dropCommandList, dropCommand->data); } + + } + + relation_close(relation, NoLock); + + char *dropCommand = NULL; + foreach_ptr(dropCommand, dropCommandList) + { + /* + * We need to disable/enable ddl propagation for this command, to prevent + * sending unnecessary ALTER COLUMN commands for partitions, to MX workers. + */ + ExecuteAndLogUtilityCommandList(list_make3(DISABLE_DDL_PROPAGATION, + dropCommand, + ENABLE_DDL_PROPAGATION)); } } diff --git a/src/backend/distributed/metadata/metadata_sync.c b/src/backend/distributed/metadata/metadata_sync.c index fcceaf6a2..b19409b5e 100644 --- a/src/backend/distributed/metadata/metadata_sync.c +++ b/src/backend/distributed/metadata/metadata_sync.c @@ -1896,7 +1896,6 @@ IdentitySequenceDependencyCommandList(Oid targetRelationId) Relation relation = relation_open(targetRelationId, AccessShareLock); TupleDesc tupleDescriptor = RelationGetDescr(relation); - relation_close(relation, NoLock); bool tableHasIdentityColumn = false; for (int attributeIndex = 0; attributeIndex < tupleDescriptor->natts; @@ -1911,6 +1910,8 @@ IdentitySequenceDependencyCommandList(Oid targetRelationId) } } + relation_close(relation, NoLock); + if (tableHasIdentityColumn) { StringInfo stringInfo = makeStringInfo(); diff --git a/src/backend/distributed/worker/worker_data_fetch_protocol.c b/src/backend/distributed/worker/worker_data_fetch_protocol.c index 8bace7eeb..86e43749d 100644 --- a/src/backend/distributed/worker/worker_data_fetch_protocol.c +++ b/src/backend/distributed/worker/worker_data_fetch_protocol.c @@ -151,7 +151,6 @@ worker_modify_identity_columns(PG_FUNCTION_ARGS) Relation tableRelation = relation_open(tableRelationId, AccessShareLock); TupleDesc tableTupleDesc = RelationGetDescr(tableRelation); - relation_close(tableRelation, NoLock); bool missingSequenceOk = false; @@ -177,6 +176,8 @@ worker_modify_identity_columns(PG_FUNCTION_ARGS) } } + relation_close(tableRelation, NoLock); + PG_RETURN_VOID(); }