Fix lock level used for partition when detaching it

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
This commit is contained in:
Alvaro Herrera 2018-12-20 16:42:13 -03:00
parent 4e4c0d6686
commit 053ad56d27
1 changed files with 1 additions and 1 deletions

View 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);