Re: tablecmds: Deadlock caused by Attach Partition

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Álvaro Herrera <alvherre(at)kurilemu(dot)de>
Cc: Kirill Reshke <reshkekirill(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, surya poondla <suryapoondla4(at)gmail(dot)com>
Subject: Re: tablecmds: Deadlock caused by Attach Partition
Date: 2026-10-26 07:22:20
Message-ID: 95CB9015-3871-4361-A8EA-48C30113FEF6@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 25, 2026, at 17:32, Álvaro Herrera <alvherre(at)kurilemu(dot)de> wrote:
>
> On 2026-Sep-03, Kirill Reshke wrote:
>
>>> Potential issue remaining
>>> ===================
>>>
>>> Currently, find_all_inheritors() sorts all inheritors purely by OID.
>>> In most cases this works, because users typically create a
>>> partitioned table first and then add partitions later, so the
>>> partitioned table’s OID is smaller than those of its partitions.
>
> Hmm, I suppose I just added one more possibility for this kind of
> deadlock failure with the 2ebd6849743 fix; maybe we should apply this
> methodology to that code also.
>
> --
> Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/
> Are you not unsure you want to delete Firefox?
> [Not unsure] [Not not unsure] [Cancel]
> http://smylers.hates-software.com/2008/01/03/566e45b2.html

Thanks for pointing out that, looks like ALTER INDEX ATTACH PARTITION has the same deadlock issue.

PFA v5:
* 0001 - just added one line comment based on v4-0001
* 0002 - fixed the ALTER INDEX ATTACH PARTITION by leveraging 0001’s mechanism
* 0003 - based on v4-0002, added a new test for 0002. Without 0002, the test will fail

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

Attachment Content-Type Size
v5-0001-Prevent-deadlock-between-ALTER-TABLE-recursion-an.patch application/octet-stream 10.5 KB
v5-0002-Prevent-deadlocks-during-partitioned-index-attach.patch application/octet-stream 5.4 KB
v5-0003-Add-isolation-tests-for-ATTACH-PARTITION-lock-ord.patch application/octet-stream 9.9 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jim Jones 2026-10-26 07:39:00 Re: Reject access to unlogged tables in contrib modules
Previous Message David Geier 2026-10-26 07:21:22 Re: Add compiler option -fstrict-flex-arrays=1