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: siblings.spec
Description: Binary data

Reply via email to