Skip to content

Commit 5317f52

Browse files
committed
Make repack_drop() processing robust against deadlocks.
Concurrent activity on the target table can cause deadlocks when repack_drop() is doing its job, ie, dropping the temporary objects created. It is highly likely to occur when pg_repack is interrupted midway through its processing.
1 parent 20a679b commit 5317f52

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/repack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,17 @@ repack_drop(PG_FUNCTION_ARGS)
949949
/* connect to SPI manager */
950950
repack_init();
951951

952+
/*
953+
* To prevent concurrent lockers of the repack target table from
954+
* causing deadlocks, take an exclusive lock on it.
955+
*
956+
* Fixes deadlock mentioned in the Github issue #55.
957+
*/
958+
execute_with_format(
959+
SPI_OK_UTILITY,
960+
"LOCK TABLE %s IN ACCESS EXCLUSIVE MODE",
961+
relname);
962+
952963
/* drop log table: must be done before dropping the pk type,
953964
* since the log table is dependent on the pk type. (That's
954965
* why we check numobj > 1 here.)

0 commit comments

Comments
 (0)