Re: Allowing multiple DDL commands to run simultaneously

From: Simon Riggs <simon(at)2ndquadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Allowing multiple DDL commands to run simultaneously
Date: 2018-07-17 22:00:18
Message-ID: CANP8+jLzgJOzqh-W_nu2=j8OW9CO4nURiZEHF7U8Rb1iZTSf9A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 17 July 2018 at 19:47, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
> On Mon, Jul 9, 2018 at 6:00 AM, Simon Riggs <simon(at)2ndquadrant(dot)com> wrote:
>> Proposal would be to add a new lock mode "ShareUpdate", which does not
>> conflict with itself and yet conflicts with "ShareUpdateExclusive" or
>> higher. (Hence, it is a strong lock type). DDL would take a
>> ShareUpdateLock on the table, then during critical portions of
>> commands it would take a ShareUpdateExclusiveLock and then release it
>> again before commit.
>
> I think this would be quite prone to deadlocks. Suppose someone tries
> to grab an AccessExclusiveLock on the table during a window in which
> we hold only ShareUpdateLock. The next attempt to upgrade to
> ShareUpdateExclusiveLock will cause a simple deadlock. In general,
> any approach that involves upgrading our lock strength is likely to
> have this problem.
>
> You might be able to work around this by inventing a whole new lock
> type, say "Relation Maintenance". Make a rule that you can only take
> the "Relation Maintenance" lock while holding a Relation lock with
> strength >= ShareUpdateLock and that you do not need to bother
> acquiring it if you hold a self-exclusive lock that conflicts with
> ShareUpdateLock. I think that works out to about the same thing as
> what you're proposing, except without the deadlock hazard.

Yes, it seems better to invent a new orthogonal lock type than have a
new lock level. Thanks.

Seems more like a critical section than a lock.

I'd make code take that lock, even if they have a self-exclusive lock,
just to avoid later problems when the lock level changes.

--
Simon Riggs http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2018-07-17 22:10:06 Re: "Write amplification" is made worse by "getting tired" while inserting into nbtree secondary indexes (Was: Why B-Tree suffix truncation matters)
Previous Message Peter Geoghegan 2018-07-17 21:28:49 Re: "Write amplification" is made worse by "getting tired" while inserting into nbtree secondary indexes (Was: Why B-Tree suffix truncation matters)