Ava withdraws 100 at a cash machine. The machine must check her balance and then take the money, with no other change in between.
- Start a transaction and read Ava's row (account 1) with a lock. Stay in the transaction.
- Take 100 from Ava and commit.
Predict, for two sessions A and B:
- A has locked Ava's row and has not committed. B runs an UPDATE on Ava's row. What does B do? Answer with one word.
- A locks account 1, B locks account 2, then each one wants the other's row. What does PostgreSQL report?
- To prevent this, both transactions lock the two accounts in the same order. Which account id do they lock first?