00 /What You Will Learn
By the end you will be able to
- Explain what a deadlock is and why two transfers in opposite directions cause one.
- Read the
deadlock detectederror: code 40P01, the DETAIL lines, and who was blocked by whom. - Prevent the cycle with lock ordering (
ORDER BY id FOR UPDATE). - Handle it with a retry on 40P01.
- Say what deadlock_timeout does and where to see the count of deadlocks.
Before you start
Finish Lab 05 (SQL Transactions and Isolation) and Lab 08 (Race Conditions) first. You should know BEGIN, COMMIT and what a row lock is. Docker Desktop must be running.