Keep read lock until we are done with table relation.

issue/6694
Gokhan Gulbiz 2023-03-29 09:45:17 +03:00
parent c893454bb8
commit 7d04b40b2d
No known key found for this signature in database
GPG Key ID: 608EF06B6BD1B45B
3 changed files with 21 additions and 10 deletions

View File

@ -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));
}
}

View File

@ -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();

View File

@ -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();
}