#author("2021-06-15T06:36:55+09:00","default:ryuichi","ryuichi")
#author("2021-06-15T06:38:30+09:00","default:ryuichi","ryuichi")
* アドバイザリーロック [#le1b8fe2]
* pg_try_advisory_xact_lock [#l82d35ce]
** 排他勧告的ロック pg_try_advisory_xact_lock [#l82d35ce]
Session A │ Session B
================================================================================================
=> BEGIN; UPDATE t1 SET n = 101 WHERE id = 1 R│=>
ETURNING pg_try_advisory_xact_lock(id); │=>
BEGIN │=>
pg_try_advisory_xact_lock │=>
--------------------------- │=>
t │=>
(1 row) │=>
│=>
=*> │=> BEGIN; SELECT * FROM t1 WHERE id = 1 AND pg_
│try_advisory_xact_lock(1);
│BEGIN
│ id | n
│----+---
│(0 rows)
│
│=*>
=*> COMMIT; │=*>
=> │=*> SELECT * FROM t1 WHERE id = 1 AND pg_try_ad
=> │visory_xact_lock(1);
│ id | n
│----+-----
│ 1 | 101
│(1 row)
│
│=*>
** 参考 [#yd5f4ce2]
- https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS
- https://www.postgresql.jp/document/12/html/functions-admin.html
- https://www.programmersought.com/article/48592944017/
- https://subscription.packtpub.com/book/data/9781789537819/2/ch02lvl1sec18/utilizing-advisory-locks
- https://tech.gunosy.io/entry/digdag-operator-pg_lock#pg_advisory_lock%E3%82%92%E4%BD%BF%E3%81%A3%E3%81%9F%E8%A1%8C%E3%83%AC%E3%83%99%E3%83%AB%E6%8E%92%E4%BB%96%E3%83%AD%E3%83%83%E3%82%AF%E3%81%AE%E5%AE%9F%E7%8F%BE