How can I block several competitive actions in the database?

Now I use advisory lock in postgres, but maybe there are some other solutions? For example using redis? Serializable is not suitable for performance.

  • I support the question: how are the databases with pessimistic (that is, real) locks? - VladD
  • @VladD, I understand that explicit locks like LOCK TABLES are not considered? - Vladimir Martyanov
  • @ Vladimir Martiyanov: Oh, did not know about this opportunity, thank you! From my point of view, it’s still being considered, but it’s hard for me to judge whether this is what the CU wants. (Optimistic, but not pessimistic locks out of the box are built into the Entity Framework, this excuses my ignorance in this matter.) - VladD
  • @ Vladimir Martiyanov lock tables is not suitable, because I do not need to lock all the tables, but only certain parts of them. Pessimistic locks, if that's what I think are also not suitable. I need an analog mutex, only in the database. So that clients "hang" until the lock is lost and captured immediately when the mutex is released. advisory lock does just that, but it can specify only two 32-bit keys or one 64-bit key, which unfortunately is not always enough - mainameiz

1 answer 1

perhaps the most common row level locks are right for you

http://postgrespro.ru/doc/explicit-locking.html#LOCKING-ROWS

that is, by issuing a SELECT ... FOR UPDATE command, you block to the end of the transaction the rows that were affected by the SELECT command. read the link there in detail and everything is written in Russian.