Commits on Aug 22, 2026
-
Prevent deadlock between ALTER TABLE recursion and ATTACH PARTITION
ALTER TABLE commands that recurse to partitions (e.g. ALTER COLUMN SET DEFAULT) lock partitions in ascending OID order using find_all_inheritors(). In contrast, ALTER TABLE ATTACH PARTITION may lock ancestor tables in reverse OID order while recursively collecting partition constraints. When these two operations run concurrently, this lock order inversion can lead to a deadlock. To avoid this, pre-lock all ancestor partitioned tables in OID order when processing ALTER TABLE ATTACH PARTITION. This ensures a consistent lock ordering before any recursive traversal of the partition hierarchy occurs. The ancestor locks are taken early, via RangeVarCallbackForAlterRelation(), so that they precede the standard ALTER TABLE locking of the target relation. This fixes a reproducible deadlock observed on the current master branch with deep partition hierarchies. Author: Chao Li <lic@highgo.com> Reviewed-by: Discussion: https://postgr.es/m/
authored and Commitfest Bot committed
Aug 22, 2026