赞
踩
时间 | 事务1 | 事务2 | 结果 |
---|---|---|---|
T1 | begin; | begin; | |
T2 | update sc_lock set state = 1 where id = ‘123’ and state = 0; | Affected rows: 1 | |
T3 | update sc_lock set state = 2 where id = ‘456’ and state = 0; | Affected rows: 1 | |
T3 | update sc_lock set state = 1 where id = ‘456’ and state = 0; | 这里会阻塞,等待事务2的修改提交 | |
T4 | update sc_lock set state = 2 where id = ‘123’ and state = 0; | ERROR: deadlock detected(检测到死锁) | |
T5 | commit; | commit; |
T4事务2执行sql后检测到死锁,报错信息:
DETAIL: Process 3714 waits for ShareLock on transaction 582; blocked
by process 3707. Process 3707 waits for ShareLock on transaction 583;
blocked by process 3714. HINT: See server log for query details.
CONTEXT: while updating tuple (0,26) in relation “sc_lock”
id为456的state最终被修改为1,说明事务2执行检测到死锁,事务2被回滚了。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。