File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -949,6 +949,28 @@ repack_drop(PG_FUNCTION_ARGS)
949
949
/* connect to SPI manager */
950
950
repack_init ();
951
951
952
+ /*
953
+ * To prevent concurrent lockers of the repack target table from causing
954
+ * deadlocks, take an exclusive lock on it. Consider that the following
955
+ * commands take exclusive lock on tables log_xxx and the target table
956
+ * itself when deleting the z_repack_trigger on it, while concurrent
957
+ * updaters require row exclusive lock on the target table and in
958
+ * addition, on the log_xxx table, because of the trigger.
959
+ *
960
+ * Consider how a deadlock could occur - if the DROP TABLE repack.log_%u
961
+ * gets a lock on log_%u table before a concurrent updater could get it
962
+ * but after the updater has obtained a lock on the target table, the
963
+ * subsequent DROP TRIGGER ... ON target-table would report a deadlock as
964
+ * it finds itself waiting for a lock on target-table held by the updater,
965
+ * which in turn, is waiting for lock on log_%u table.
966
+ *
967
+ * Fixes deadlock mentioned in the Github issue #55.
968
+ */
969
+ execute_with_format (
970
+ SPI_OK_UTILITY ,
971
+ "LOCK TABLE %s.%s IN ACCESS EXCLUSIVE MODE" ,
972
+ nspname , relname );
973
+
952
974
/* drop log table: must be done before dropping the pk type,
953
975
* since the log table is dependent on the pk type. (That's
954
976
* why we check numobj > 1 here.)
You can’t perform that action at this time.
0 commit comments