]> granicus.if.org Git - postgresql/commitdiff
Fix lock level used for partition when detaching it
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 20 Dec 2018 19:42:13 +0000 (16:42 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 20 Dec 2018 19:42:13 +0000 (16:42 -0300)
For probably bogus reasons, we acquire only AccessShareLock on the
partition when we try to detach it from its parent partitioned table.
This can cause ugly things to happen if another transaction is doing
any sort of DDL to the partition concurrently.

Upgrade that lock to ShareUpdateExclusiveLock, which per discussion
seems to be the minimum needed.

Reported by Robert Haas.

Discussion: https://postgr.es/m/CA+TgmoYruJQ+2qnFLtF1xQtr71pdwgfxy3Ziy-TxV28M6pEmyA@mail.gmail.com

src/backend/commands/tablecmds.c

index 6543eedc3a38eb21bceec027dc2af7eed18b9e9e..1dae3563605cd93c7433f8b6b4cd95bd44a9356b 100644 (file)
@@ -14726,7 +14726,7 @@ ATExecDetachPartition(Relation rel, RangeVar *name)
        if (OidIsValid(defaultPartOid))
                LockRelationOid(defaultPartOid, AccessExclusiveLock);
 
-       partRel = heap_openrv(name, AccessShareLock);
+       partRel = heap_openrv(name, ShareUpdateExclusiveLock);
 
        /* All inheritance related checks are performed within the function */
        RemoveInheritance(partRel, rel);