Chao Li (Evan) · GitHub

Commits on Aug 22, 2026

  1. 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/

    Chao Li (Evan) Commitfest Bot

    authored and Commitfest Bot committed

    Aug 22, 2026
    Configuration menu

    Browse the repository at this point in the history

  2. Configuration menu

    Browse the repository at this point in the history

Read the original on github.com ↗