@@ -13997,10 +13997,9 @@ QueuePartitionConstraintValidation(List **wqueue, Relation scanrel,
13997
13997
List * thisPartConstraint ;
13998
13998
13999
13999
/*
14000
- * This is the minimum lock we need to prevent concurrent data
14001
- * additions.
14000
+ * This is the minimum lock we need to prevent deadlocks.
14002
14001
*/
14003
- part_rel = heap_open (partdesc -> oids [i ], ShareLock );
14002
+ part_rel = heap_open (partdesc -> oids [i ], AccessExclusiveLock );
14004
14003
14005
14004
/*
14006
14005
* Adjust the constraint for scanrel so that it matches this
@@ -14113,17 +14112,17 @@ ATExecAttachPartition(List **wqueue, Relation rel, PartitionCmd *cmd)
14113
14112
*
14114
14113
* We do that by checking if rel is a member of the list of attachrel's
14115
14114
* partitions provided the latter is partitioned at all. We want to avoid
14116
- * having to construct this list again, so we request a lock on all
14117
- * partitions. We need ShareLock, preventing data changes , because we
14118
- * may decide to scan them if we find out that the table being attached (or
14119
- * its leaf partitions) may contain rows that violate the partition
14120
- * constraint. If the table has a constraint that would prevent such rows,
14121
- * which by definition is present in all the partitions, we need not scan
14122
- * the table, nor its partitions. But we cannot risk a deadlock by taking
14123
- * a weaker lock now and the stronger one only when needed.
14115
+ * having to construct this list again, so we request the strongest lock
14116
+ * on all partitions. We need the strongest lock , because we may decide
14117
+ * to scan them if we find out that the table being attached (or its leaf
14118
+ * partitions) may contain rows that violate the partition constraint. If
14119
+ * the table has a constraint that would prevent such rows, which by
14120
+ * definition is present in all the partitions, we need not scan the
14121
+ * table, nor its partitions. But we cannot risk a deadlock by taking a
14122
+ * weaker lock now and the stronger one only when needed.
14124
14123
*/
14125
14124
attachrel_children = find_all_inheritors (RelationGetRelid (attachrel ),
14126
- ShareLock , NULL );
14125
+ AccessExclusiveLock , NULL );
14127
14126
if (list_member_oid (attachrel_children , RelationGetRelid (rel )))
14128
14127
ereport (ERROR ,
14129
14128
(errcode (ERRCODE_DUPLICATE_TABLE ),
0 commit comments