public inbox for [email protected]  
help / color / mirror / Atom feed
From: Simon Riggs <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: Re: Table-Level Locks and Transactions
Date: Thu, 9 Dec 2021 10:33:06 +0000
Message-ID: <CANbhV-EyDBV_z5urPQHshMakkScUwRdfBjektEB3NYkdmc4=1g@mail.gmail.com> (raw)
In-Reply-To: <CAKemG7XD-UU7AGan+jp5jtw+6wwcN4z3pPSB=DuoAC1z3JDDhg@mail.gmail.com>
References: <CAKemG7XD-UU7AGan+jp5jtw+6wwcN4z3pPSB=DuoAC1z3JDDhg@mail.gmail.com>

On Thu, 9 Dec 2021 at 01:07, Greg Rychlewski <[email protected]> wrote:
>
> I'm curious to understand when table-level locks are released by one transaction to use in another.

At the end of transaction.

> For instance, say I have the following transaction, where index1 and index2 both belong to the same table.
>
> BEGIN;
> DROP INDEX index1;
> CREATE INDEX index2;
> COMMIT;
>
> This transaction acquires an ACCESS EXCLUSIVE lock during the DROP INDEX step and then acquires a SHARE lock during the CREATE INDEX step.
>
> I understand that there will be no conflicts between the statements in this transaction, but I'm wondering if an outside transaction will think that the table has an ACCESS EXCLUSIVE lock until this entire transaction is completed.

No, just index1, but the SHARE lock will prevent writes.

Have you thought about using DROP INDEX CONCURRENTLY and CREATE INDEX
CONCURRENTLY?

If in doubt, try it. Look at pg_locks.

-- 
Simon Riggs                http://www.EnterpriseDB.com/





view thread (4+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Table-Level Locks and Transactions
  In-Reply-To: <CANbhV-EyDBV_z5urPQHshMakkScUwRdfBjektEB3NYkdmc4=1g@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox