实验1:
1 | session1: |
session2执行update语句的时候卡主了,需要等待session1把锁释放掉。
session3查看当前被锁的会话:
1 | 20:01:16 SYS@ boston> select a.object_name,b.session_id,c.serial#,'alter system kill session '''||b.session_id||','||c.serial#||'''; ' as a,c.program,c.username,c.command,c.machine,c.lockwait from all_objects a,v$locked_object b,v$session c where a.object_id=b.object_id and c.sid=b.session_id; |
查看被锁的对象
1 | SELECT l.session_id sid,s.serial#,l.locked_mode ,l.oracle_username ,l.os_user_name ,s.machine,s.terminal,o.object_name,s.logon_time,c.sql_text FROM v$locked_object l, all_objects o, v$session s, v$sqlarea c WHERE l.object_id = o.object_id AND l.session_id = s.sid and s.sql_id = c.sql_id ORDER BY sid,s.serial#; |
查询结果如上所示,因为session1的查询已经结束,session2的sql还被锁住,只能查询到session2的sql语句,因此我们要杀掉sessoin1的会话,让session2继续正常运行。如果杀掉了sesison2,其他会话再进来执行dml变更操作,会话仍然被卡主。
实验2:
rollback回滚上面的操作,之后继续实验2
1 | session2: |
session1执行select操作被卡主
session3查看被锁的语句
1 | 20:10:44 SYS@ boston> select a.object_name,b.session_id,c.serial#,'alter system kill session '''||b.session_id||','||c.serial#||'''; ' as a,c.program,c.username,c.command,c.machine,c.lockwait from all_objects a,v$locked_object b,v$session c where a.object_id=b.object_id and c.sid=b.session_id; |
1 | 20:16:01 SYS@ boston> SELECT l.session_id sid, |
查询结果为session1的select语句被堵塞,处于正在执行的状态,session2的update语句已经执行完成,需要commit才能把锁释放掉。