@@ -2892,13 +2892,8 @@ AlterTableGetLockLevel(List *cmds)
2892
2892
break ;
2893
2893
2894
2894
/*
2895
- * These subcommands affect write operations only. XXX
2896
- * Theoretically, these could be ShareRowExclusiveLock.
2895
+ * These subcommands affect write operations only.
2897
2896
*/
2898
- case AT_ColumnDefault :
2899
- case AT_ProcessedConstraint : /* becomes AT_AddConstraint */
2900
- case AT_AddConstraintRecurse : /* becomes AT_AddConstraint */
2901
- case AT_ReAddConstraint : /* becomes AT_AddConstraint */
2902
2897
case AT_EnableTrig :
2903
2898
case AT_EnableAlwaysTrig :
2904
2899
case AT_EnableReplicaTrig :
@@ -2907,6 +2902,14 @@ AlterTableGetLockLevel(List *cmds)
2907
2902
case AT_DisableTrig :
2908
2903
case AT_DisableTrigAll :
2909
2904
case AT_DisableTrigUser :
2905
+ cmd_lockmode = ShareRowExclusiveLock ;
2906
+ break ;
2907
+
2908
+ /*
2909
+ * These subcommands affect write operations only. XXX
2910
+ * Theoretically, these could be ShareRowExclusiveLock.
2911
+ */
2912
+ case AT_ColumnDefault :
2910
2913
case AT_AlterConstraint :
2911
2914
case AT_AddIndex : /* from ADD CONSTRAINT */
2912
2915
case AT_AddIndexConstraint :
@@ -2918,6 +2921,9 @@ AlterTableGetLockLevel(List *cmds)
2918
2921
break ;
2919
2922
2920
2923
case AT_AddConstraint :
2924
+ case AT_ProcessedConstraint : /* becomes AT_AddConstraint */
2925
+ case AT_AddConstraintRecurse : /* becomes AT_AddConstraint */
2926
+ case AT_ReAddConstraint : /* becomes AT_AddConstraint */
2921
2927
if (IsA (cmd -> def , Constraint ))
2922
2928
{
2923
2929
Constraint * con = (Constraint * ) cmd -> def ;
@@ -2943,11 +2949,9 @@ AlterTableGetLockLevel(List *cmds)
2943
2949
/*
2944
2950
* We add triggers to both tables when we add a
2945
2951
* Foreign Key, so the lock level must be at least
2946
- * as strong as CREATE TRIGGER. XXX Might be set
2947
- * down to ShareRowExclusiveLock though trigger
2948
- * info is accessed by pg_get_triggerdef
2952
+ * as strong as CREATE TRIGGER.
2949
2953
*/
2950
- cmd_lockmode = AccessExclusiveLock ;
2954
+ cmd_lockmode = ShareRowExclusiveLock ;
2951
2955
break ;
2952
2956
2953
2957
default :
@@ -6193,16 +6197,13 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel,
6193
6197
ListCell * old_pfeqop_item = list_head (fkconstraint -> old_conpfeqop );
6194
6198
6195
6199
/*
6196
- * Grab an exclusive lock on the pk table, so that someone doesn't delete
6197
- * rows out from under us. (Although a lesser lock would do for that
6198
- * purpose, we'll need exclusive lock anyway to add triggers to the pk
6199
- * table; trying to start with a lesser lock will just create a risk of
6200
- * deadlock.)
6200
+ * Grab ShareRowExclusiveLock on the pk table, so that someone doesn't
6201
+ * delete rows out from under us.
6201
6202
*/
6202
6203
if (OidIsValid (fkconstraint -> old_pktable_oid ))
6203
- pkrel = heap_open (fkconstraint -> old_pktable_oid , AccessExclusiveLock );
6204
+ pkrel = heap_open (fkconstraint -> old_pktable_oid , ShareRowExclusiveLock );
6204
6205
else
6205
- pkrel = heap_openrv (fkconstraint -> pktable , AccessExclusiveLock );
6206
+ pkrel = heap_openrv (fkconstraint -> pktable , ShareRowExclusiveLock );
6206
6207
6207
6208
/*
6208
6209
* Validity checks (permission checks wait till we have the column
0 commit comments