Re: tablecmds: Deadlock caused by Attach Partition

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: surya poondla <suryapoondla4(at)gmail(dot)com>
Cc: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>, Álvaro Herrera <alvherre(at)kurilemu(dot)de>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: tablecmds: Deadlock caused by Attach Partition
Date: 2026-10-28 01:29:02
Message-ID: CAGRkXqTSqk-4ej3_q_frxGKvf-A8CcgCH_bvvEnvPuzaYe5u-w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Chao,

I looked at the other callers of generate_partition_qual() and race
each one against a recursive ALTER TABLE on the root, like Surya’s test.

pg_get_partition_constraintdef() has the same deadlock. It locks a
partition and then its ancestors through generate_partition_qual().
It deadlocks with a recursive ALTER TABLE on the root, psql \d+ uses it.

I think it can be fixed the same way. Call lock_partition_ancestors()
in get_partition_qual_relid() before it opens the relation.

It may also help to add a comment above generate_partition_qual() so
the next caller locks the ancestors first.

That could be a different patch or fix here, I am ok for both.

Thanks,
Shihao

Attachment Content-Type Size
siblings.spec application/octet-stream 1.6 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Ayoub Kazar 2026-10-28 01:32:38 Re: [PROPOSAL] Expand OR clauses in joins to UNION ALL paths
Previous Message Chao Li 2026-10-28 01:28:37 Return INT_MAX or INT_MIN from strtoint() on overflow