Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2775974
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: Oracle

2013-01-18 16:48:02

第一,创建一个sessions 1

SQL> select sid from v$mystat where rownum=1;


       SID
----------
        68

SQL> create table t(x int primary key);

Table created.

SQL> insert into t values(1);

1 row created.

SQL> commit;
Commit complete.

SQL> update t set x=10 where x=1;

1 row updated.

SQL> 


第二个.创建第二个sessions 2


SQL> select sid from v$mystat where rownum=1;


       SID
----------
       130


SQL> update t set x=15 where x=1;


数据卡在这里了,,产生了锁表,在数据库中对这个没过程的具体描述是就是 session 2被session1阻塞(session2 was blocked by session1)
SQL> select sid,type,id1,id2,lmode,request,block from v$lock where sid in (68,130) order by sid;

       SID TY        ID1        ID2      LMODE    REQUEST      BLOCK
---------- -- ---------- ---------- ---------- ---------- ----------
        68 TM      74909          0          3          0          0
        68 AE        100          0          4          0          0
        68 TX     655373        724          6          0          1
       130 TM      74909          0          3          0          0
       130 AE        100          0          4          0          0
       130 TX     655373        724          0          6          0

6 rows selected.

SQL> 

可以看出SID=68这第一个会话session 1,SID=130是第二个会话的session2, BLOCK=1 表示这个会话
正在阻塞其它的会话,REOUEST=6,表示当前的会话正在等待一个LMODE=6的锁,这个会话正被阻塞。


接下来,我们可以通过SID号,去查询用户信息。

SQL> select machine from v$session where sid in (68,130);

MACHINE
----------------------------------------------------------------
rhel5-01.tank.com
rhel5-01.tank.com


SQL> 


由于是我的自己的测试机器名称,看是主机名一样,


测试删除t表,如下:


SQL> drop table t;
drop table t
           *
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired


查看发现生锁的有那些


SQL> select t2.username,t2.sid,t2.serial#,t2.logon_time
  2  from v$locked_object t1,v$session t2
  3  where t1.session_id=t2.sid order by t2.logon_time;


USERNAME                              SID    SERIAL# LOGON_TIM
------------------------------ ---------- ---------- ---------
TEST                                  130        300 31-DEC-12


根据SID查看发现锁的SQL语句:


SQL> select sql_text from v$session a,v$sqltext_with_newlines b
  2    where DECODE(a.sql_hash_value, 0, prev_hash_value, sql_hash_value)=b.hash_value
  3    and a.sid=&sid order by piece;
Enter value for sid: 130
old   3:   and a.sid=&sid order by piece
new   3:   and a.sid=130 order by piece


SQL_TEXT
----------------------------------------------------------------
select * from t

kill掉发生锁的语句
SQL>alter system kill session '130,300';

阅读(1103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~