如何查询oracle的死锁?
下面查询可以查到死锁,但是注意其实查询到的不是真正的死锁,查询到的只是是死锁发生前的等待条件,真正的死锁在10G中会被系统所阻止掉
成都创新互联公司长期为数千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为巴彦企业提供专业的网站设计制作、成都网站建设,巴彦网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。
select t2.username||' '||t2.sid||' '||t2.serial#||' '||t2.logon_time||' '||t3.sql_text
from v$locked_object t1,v$session t2,v$sqltext t3
where t1.session_id=t2.sid
and t2.sql_address=t3.address
order by t2.logon_time ;
此外,从V$LOCK的BLOCK字段可以看到,BLOCK0表示有等待发生了,注意是行级等待,而在表级没有死锁或等待
select * from v$lock where block0 ;
如何杀死oracle死锁进程?
1.查哪个过程被锁\x0d\x0a查V$DB_OBJECT_CACHE视图:SELECT*FROMV$DB_OBJECT_CACHEWHEREOWNER='过程的所属用户'ANDLOCKS!='0';\x0d\x0a2. 查是哪一个SID,通过SID可知道是哪个SESSION.\x0d\x0a查V$ACCESS视图:SELECT*FROMV$ACCESSWHEREOWNER='过程的所属用户'ANDNAME='刚才查到的过程名';\x0d\x0a3. 查出SID和SERIAL#\x0d\x0a查V$SESSION视图:SELECTSID,SERIAL#,PADDRFROMV$SESSIONWHERESID='刚才查到的SID'查V$PROCESS视图:SELECTSPIDFROMV$PROCESSWHEREADDR='刚才查到的PADDR';\x0d\x0a4. 杀进程(1).先杀ORACLE进程:ALTERSYSTEMKILLSESSION'查出的SID,查出的SERIAL#';(2).再杀操作系统进程:KILL-9刚才查出的SPID或ORAKILL刚才查出的SID刚才查出的SPID方法二:经常在oracle的使用过程中碰到这个问题,所以也总结了一点解决方法:)1)查找死锁的进程:sqlplus"/assysdba"SELECT\x0d\x0as.username,l.\x0d\x0aOBJECT_ID\x0d\x0a,l.SESSION_ID,s.SERIAL#,l.ORACLE_USERNAME,l.OS_USER_NAME,l.PROCESSFROMV$LOCKED_OBJECTl,V$SESSIONSWHERE\x0d\x0al.SESSION_ID=\x0d\x0aS.SID;2)kill掉这个死锁的进程:altersystemkillsession‘sid,serial#’;(其中sid=\x0d\x0al.session_id)3)如果还不能解决,\x0d\x0aselectpro.spidfromv$sessionses,v$processprowhereses.sid=XXandses.paddr=pro.addr;其中sid用死锁的sid替换。
oracle 如何查看有没有死锁
-- 死锁查询语句
SELECT bs.username "Blocking User", bs.username "DB User",
ws.username "Waiting User", bs.SID "SID", ws.SID "WSID",
bs.serial# "Serial#", bs.sql_address "address",
bs.sql_hash_value "Sql hash", bs.program "Blocking App",
ws.program "Waiting App", bs.machine "Blocking Machine",
ws.machine "Waiting Machine", bs.osuser "Blocking OS User",
ws.osuser "Waiting OS User", bs.serial# "Serial#",
ws.serial# "WSerial#",
DECODE (wk.TYPE,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'USER Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL USER LOCK',
'DX', 'Distributed Xaction',
'CF', 'Control FILE',
'IS', 'Instance State',
'FS', 'FILE SET',
'IR', 'Instance Recovery',
'ST', 'Disk SPACE Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'LOG START OR Switch',
'RW', 'ROW Wait',
'SQ', 'Sequence Number',
'TE', 'Extend TABLE',
'TT', 'Temp TABLE',
wk.TYPE
) lock_type,
DECODE (hk.lmode,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (hk.lmode)
) mode_held,
DECODE (wk.request,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (wk.request)
) mode_requested,
TO_CHAR (hk.id1) lock_id1, TO_CHAR (hk.id2) lock_id2,
DECODE
(hk.BLOCK,
0, 'NOT Blocking', /**//* Not blocking any other processes */
1, 'Blocking', /**//* This lock blocks other processes */
2, 'Global', /**//* This lock is global, so we can't tell */
TO_CHAR (hk.BLOCK)
) blocking_others
FROM v$lock hk, v$session bs, v$lock wk, v$session ws
WHERE hk.BLOCK = 1
AND hk.lmode != 0
AND hk.lmode != 1
AND wk.request != 0
AND wk.TYPE(+) = hk.TYPE
AND wk.id1(+) = hk.id1
AND wk.id2(+) = hk.id2
AND hk.SID = bs.SID(+)
AND wk.SID = ws.SID(+)
AND (bs.username IS NOT NULL)
AND (bs.username 'SYSTEM')
AND (bs.username 'SYS')
ORDER BY 1;
查询发生死锁的select语句
select sql_text from v$sql where hash_value in (
select sql_hash_value from v$session where sid in (select session_id from v$locked_object)
)
oracle怎么查看表死锁住的原因
1.可能在Oracle中可以有计时器,在频繁操作数据库,update,insert,delete语句,在jobs中能查看到(如图)
2.可能在.net程序中使用到timer控件,频繁的操作数据库update,insert,delete语句(如图)
3.可能在.net程序中使用到Thead(线程)频繁的操作数据库update,insert,delete语句(这个条为个人观点,还未得到证实)
【注释】:此处更新数据量都比较大,比如说update的数据库条数可能在1000条以上,
导致其他操作在等待(update跟其他操作都是同一张表)
4.可能使用到事务处理(Tran),没有提交事务(CommintTran)或者没有回滚事务(Rollback)
【注释】:在SqlServer数据库里面有一个隐式事务,关闭时候,每次修改插入都需要手动提交,不然就会导致死锁
怎么查看oracle是否有死锁
-- 死锁查询语句
SELECT bs.username "Blocking User", bs.username "DB User",
ws.username "Waiting User", bs.SID "SID", ws.SID "WSID",
bs.serial# "Serial#", bs.sql_address "address",
bs.sql_hash_value "Sql hash", bs.program "Blocking App",
ws.program "Waiting App", bs.machine "Blocking Machine",
ws.machine "Waiting Machine", bs.osuser "Blocking OS User",
ws.osuser "Waiting OS User", bs.serial# "Serial#",
ws.serial# "WSerial#",
DECODE (wk.TYPE,
'MR', 'Media Recovery',
'RT', 'Redo Thread',
'UN', 'USER Name',
'TX', 'Transaction',
'TM', 'DML',
'UL', 'PL/SQL USER LOCK',
'DX', 'Distributed Xaction',
'CF', 'Control FILE',
'IS', 'Instance State',
'FS', 'FILE SET',
'IR', 'Instance Recovery',
'ST', 'Disk SPACE Transaction',
'TS', 'Temp Segment',
'IV', 'Library Cache Invalidation',
'LS', 'LOG START OR Switch',
'RW', 'ROW Wait',
'SQ', 'Sequence Number',
'TE', 'Extend TABLE',
'TT', 'Temp TABLE',
wk.TYPE
) lock_type,
DECODE (hk.lmode,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (hk.lmode)
) mode_held,
DECODE (wk.request,
0, 'None',
1, 'NULL',
2, 'ROW-S (SS)',
3, 'ROW-X (SX)',
4, 'SHARE',
5, 'S/ROW-X (SSX)',
6, 'EXCLUSIVE',
TO_CHAR (wk.request)
) mode_requested,
TO_CHAR (hk.id1) lock_id1, TO_CHAR (hk.id2) lock_id2,
DECODE
(hk.BLOCK,
0, 'NOT Blocking', /**//* Not blocking any other processes */
1, 'Blocking', /**//* This lock blocks other processes */
2, 'Global', /**//* This lock is global, so we can't tell */
TO_CHAR (hk.BLOCK)
) blocking_others
FROM v$lock hk, v$session bs, v$lock wk, v$session ws
WHERE hk.BLOCK = 1
AND hk.lmode != 0
AND hk.lmode != 1
AND wk.request != 0
AND wk.TYPE(+) = hk.TYPE
AND wk.id1(+) = hk.id1
AND wk.id2(+) = hk.id2
AND hk.SID = bs.SID(+)
AND wk.SID = ws.SID(+)
AND (bs.username IS NOT NULL)
AND (bs.username 'SYSTEM')
AND (bs.username 'SYS')
ORDER BY 1;
查询发生死锁的select语句
select sql_text from v$sql where hash_value in (
select sql_hash_value from v$session where sid in (select session_id from v$locked_object)
)
如何查看oracle数据库死锁
1、?用SYS登陆TOAD
2、打开菜单Database-Monitor-SessionBrowser
3、查看所有会话,是否存在锁定资源的情况!
4、?如果有死锁,可以将此会话Kill掉!
标题名称:如何查oracle死锁,oracle 查死锁
转载源于:http://lswzjz.com/article/dsscish.html