常用sql汇集

1. 查看后台正在运行的sql

select a.program, b.spid, c.sql_text from v$session a, v$process b, v$sqlarea c where a.paddr = b.addr and a.sql_hash_value = c.hash_value and a.username is not null;

2. 查看被锁object.

SELECT substr(v$lock.sid,1,4) "SID",substr(username,1,12) "UserName",substr(object_name,1,25) "ObjectName",v$lock.type "LockType",
decode(rtrim(substr(lmode,1,4)),'2','Row-S (SS)','3','Row-X (SX)','4','Share', '5','S/Row-X (SSX)','6','Exclusive', 'Other' ) "LockMode", substr(v$session.program,1,25) "ProgramName"
FROM V$LOCK,SYS.DBA_OBJECTS,V$SESSION
WHERE (OBJECT_ID = v$lock.id1
AND v$lock.sid = v$session.sid
AND username IS NOT NULL
AND username NOT IN ('SYS','SYSTEM')
AND SERIAL# != 1);

 

SELECT                                                         
        LPAD (' ', DECODE (l.xidusn, 0, 3, 0))
           || l.oracle_username
              User_name,
           o.owner,
           o.object_name,
           o.object_type,
           s.sid,
           s.serial#
    FROM   v$locked_object l, dba_objects o, v$session s
   WHERE   l.object_id = o.object_id AND l.session_id = s.sid
ORDER BY   o.object_id, xidusn DESC;

 

3. Kill session

SELECT SID,SERIAL#,STATUS FROM V$SESSION WHERE SID=418;     
ALTER SYSTEM KILL SESSION '418','10562';

SELECT 'alter system kill session ''' || sid || ',' || serial# || ''';' "Deadlock"
FROM v$session
WHERE sid IN (SELECT sid
FROM v$lock
WHERE block = 1);


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值