Re: Table-Level Locks and Transactions

Поиск
Список
Период
Сортировка
От Simon Riggs
Тема Re: Table-Level Locks and Transactions
Дата
Msg-id CANbhV-EyDBV_z5urPQHshMakkScUwRdfBjektEB3NYkdmc4=1g@mail.gmail.com
обсуждение исходный текст
Ответ на Table-Level Locks and Transactions  (Greg Rychlewski <greg.rychlewski@gmail.com>)
Ответы Re: Table-Level Locks and Transactions
Список pgsql-novice
On Thu, 9 Dec 2021 at 01:07, Greg Rychlewski <greg.rychlewski@gmail.com> 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
theCREATE INDEX step.
 
>
> I understand that there will be no conflicts between the statements in this transaction, but I'm wondering if an
outsidetransaction 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/



В списке pgsql-novice по дате отправления:

Предыдущее
От: Greg Rychlewski
Дата:
Сообщение: Table-Level Locks and Transactions
Следующее
От: Laurenz Albe
Дата:
Сообщение: Re: Table-Level Locks and Transactions