Oracle 死锁测试
1,建立测试表
create table l (id int);
insert into l values(1);
insert into l values(2);
2,执行锁测试
需要打开2个会话.
| 会话1 | 会话2 |
| select * from l where id=1 for update; | |
| select * from l where id=2 for update; | |
| select * from l where id=2 for update; ----等待会话2提交。
|
|
| select * from l where id=1 for update; ----等待会话1提交。
|
|
| SQL> select * from l where id=2 for update;
|
|
| //需要执行commit,rollback.会话2才能正常执行。 |

3,PG锁测试
| 会话1 | 会话2 |
| begin; | begin; |
| select * from l where id=1 for update; | |
| select * from l where id=2 for update; | |
| select * from l where id=2 for update; #会话等待2
|
|
| select * from l where id=1 for update; #会话2报错,会话rollback; postgres=*# select * from l where id=1 for update; postgres=!# select * from l where id=2 for update; |
|
| #会话1正常执行。可以正常commit
|
|
- 点赞
- 收藏
- 关注作者






评论(0)