postgres.git / summary / log / commit / refs

commit    9ab37b6e7cd4875d9196f59c93166b427b3394a4
Author:   Álvaro Herrera <alvherre@kurilemu.de>
Date:     Sun Oct 25 09:23:46 2026 +0000
First released in: 14.25, 15.20, 16.16, 17.12, 18.7, 19.0

    Retain locks after marking the partitioned index valid
    
    Commit 8b08f7d4820f (pg11-era), for no apparent reason, made
    validatePartitionedIndex() release the locks on the parent partitioned
    index and table when marking the parent index valid after marking the
    index partition as valid.  This leads to race condition, which
    particularly manifest when restoring from pg_dump in parallel mode, for
    instance causing restore of FKs to fail if the PK that they depend on is
    being concurrently validated.  Fix by retaining those locks until
    transaction commit, as we normally do everywhere in DDL code.
    
    Per buildfarm failures.
    
    Author: Andrey Borodin <x4mmm@yandex-team.ru> (in absentia)
    Diagnosed-by: Kirill Reshke <reshkekirill@gmail.com>
    Backpatch-through: 14
    Discussion: https://postgr.es/m/l4joqljvbou26unhplkdj7m5olxn7rsy2loqlcta44nie5k3bs@zudmva7han7g


src/backend/commands/tablecmds.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 3fd375feffc..f72b2fa1553 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -19716,8 +19716,13 @@ validatePartitionedIndex(Relation partedIdx, Relation partedTbl) validatePartitionedIndex(parentIdx, parentTbl); - relation_close(parentIdx, AccessExclusiveLock); - relation_close(parentTbl, AccessExclusiveLock); + /* + * Keep these locks until commit so that the concurrent validator of + * another index partition cannot miss our uncommitted changes, which + * would leave the parent index invalid. + */ + relation_close(parentIdx, NoLock); + relation_close(parentTbl, NoLock); } } [parent: 3b2a60481c84]