Concurrent deadlock scenario with DROP INDEX on partitioned index

Поиск
Список
Период
Сортировка
От Jimmy Yih
Тема Concurrent deadlock scenario with DROP INDEX on partitioned index
Дата
Msg-id BYAPR05MB645402330042E17D91A70C12BD5F9@BYAPR05MB6454.namprd05.prod.outlook.com
обсуждение исходный текст
Ответы Re: Concurrent deadlock scenario with DROP INDEX on partitioned index  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hello pgsql-hackers,

When dropping a partitioned index, the locking order starts with the
partitioned table, then its partitioned index, then the partition
indexes dependent on that partitioned index, and finally the dependent
partition indexes' parent tables. This order allows a deadlock
scenario to happen if for example an ANALYZE happens on one of the
partition tables which locks the partition table and then blocks when
it attempts to lock its index (the DROP INDEX has the index lock but
cannot get the partition table lock).

Deadlock Reproduction
==================================================
Initial setup:
CREATE TABLE foopart (a int) PARTITION BY RANGE (a);
CREATE TABLE foopart_child PARTITION OF foopart FOR VALUES FROM (1) TO (5);
CREATE INDEX foopart_idx ON foopart USING btree(a);

Attach debugger to session 1 and put breakpoint on function deleteObjectsInList:
1: DROP INDEX foopart_idx;

While session 1 is blocked by debugger breakpoint, run the following:
2: ANALYZE foopart_child;

After a couple seconds, detach the debugger from session 1 and see deadlock.

In order to prevent this deadlock scenario, we should find and lock
all the sub-partition and partition tables beneath the partitioned
index's partitioned table before attempting to lock the sub-partition
and partition indexes.

Attached is a patch (+isolation test) which fixes the issue. We
observed this on latest head of Postgres.

Regards,
Jimmy Yih and Gaurab Dey
Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Mikhail Dobrinin
Дата:
Сообщение: JSONB docs patch
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: JSONB docs patch