Table-Level Locks and Transactions

From: Greg Rychlewski <greg(dot)rychlewski(at)gmail(dot)com>
To: pgsql-novice(at)lists(dot)postgresql(dot)org
Subject: Table-Level Locks and Transactions
Date: 2021-12-09 01:07:07
Message-ID: CAKemG7XD-UU7AGan+jp5jtw+6wwcN4z3pPSB=DuoAC1z3JDDhg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi,

I'm curious to understand when table-level locks are released by one
transaction to use in another.

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.

Thanks

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Simon Riggs 2021-12-09 10:33:06 Re: Table-Level Locks and Transactions
Previous Message David G. Johnston 2021-11-26 18:39:33 Re: Simple question about running a function.