1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | $ docker run --name postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres:12 $ psql -h localhost -U postgres -d postgres # create table product(id int, name text, price int); # insert into product(id, name, price) values (1, 'product1', 100),(2, 'product2',200); ・A(別ターミナルから) postgres=# begin; postgres=# update product set price=101 where id =1; UPDATE 1 ・B(別ターミナルから) postgres=# begin; postgres=# update product set price=201 where id =2; UPDATE 1 ・B postgres=# update product set price=201 where id =1; UPDATE 1 ロック待ちが発生し、以下を実行するとdeadlockになる ・A postgres=# update product set price=101 where id =2; ERROR: deadlock detected DETAIL: Process 89 waits for ShareLock on transaction 492; blocked by process 104. Process 104 waits for ShareLock on transaction 491; blocked by process 89. HINT: See server log for query details. CONTEXT: while updating tuple (0,2) in relation "product" ・A postgres=# abort; ROLLBACK ・B postgres=# abort; ROLLBACK |
トランザクションA, Bからproduct1, product2に対してUPDATE文を発行すると、2つのトランザクションで互いにロック待ちとなるデッドロックが発生する。
Was this helpful?
0 / 0
1989年生まれのSRE。ホスティングから大規模なアドテクなどのインフラエンジニアとして携わる。現在はサービスの信頼性向上、DevOps、可用性、レイテンシ、パフォーマンス、モニタリング、オブザーバビリティ、緊急対応、AWS/Azureでのインフラ構築、Docker開発環境の提供、Kubernetes保守、インフラコード化、新技術の検証、リファクタリング、セキュリティ強化などを担当している。個人事業主では数社サーバー保守とベンチャー企業のSREインフラコンサルティングやMENTA/CloudTech Academyで未経験者にインフラのコーチング/コミュニティの運用を実施している。また、「脆弱性スキャナVuls」のOSS活動もしており、自称エバンジェリスト/技術広報/テクニカルサポート/コントリビュータでもある。