Re: Locking & concurrency - best practices

Поиск
Список
Период
Сортировка
От Adam Rich
Тема Re: Locking & concurrency - best practices
Дата
Msg-id 00a401c85733$ea26f770$be74e650$@r@indigodynamic.com
обсуждение исходный текст
Ответ на Re: Locking & concurrency - best practices  ("Merlin Moncure" <mmoncure@gmail.com>)
Список pgsql-general
> Advisory locks would work here (better that than table lock), but I
> don't think that's the right approach.  Transaction 2 should simply do
> a
> select * from parent_tbl
> where id=1 for update;
>
> at the start of the transaction.

That's actually what I'm doing (just forgot to include it in the
simplified example).  What I'm struggling with is that since these locks
aren't enforced in one central place, so I have to run the "for update"
query in every far corner of my code that touches data, whether or not
it reads or writes to parent_tbl.  If any of the developers forget
to add it, the data can become corrupted.  And since I'm essentially
using row-level locks as advisory locks, I wondered if just using
advisory locks directly would benefit us somehow, in quicker
transactions, CPU/memory overhead, WAL, etc.

In my real application, there are lots of "parent_tbl" and when I try
to "for update" the appropriate ones, I get deadlocks.  I know in
theory, I only need to lock things in the same order, everywhere.
But in practice, it seems hard to achieve.







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

Предыдущее
От: "Merlin Moncure"
Дата:
Сообщение: Re: Locking & concurrency - best practices
Следующее
От: Ken Johanson
Дата:
Сообщение: Re: Query to get column-names in table via PG tables?