zbb20170728 oracle 查看被锁对象

 查询Oracle正在执行和执行过的SQL语句

--查询Oracle正在执行的sql语句及执行该语句的用户

SELECT b.sid oracleID,
       b.username 登录Oracle用户名,
       b.serial#,
       spid 操作系统ID,
       paddr,
       sql_text 正在执行的SQL,
       b.machine 计算机名
FROM v$process a, v$session b, v$sqlarea c
WHERE a.addr = b.paddr
   AND b.sql_hash_value = c.hash_value

 

 

--查看正在执行sql的发起者的发放程序

SELECT OSUSER 电脑登录身份,
       PROGRAM 发起请求的程序,
       USERNAME 登录系统的用户名,
       SCHEMANAME,
       B.Cpu_Time 花费cpu的时间,
       STATUS,
       B.SQL_TEXT 执行的sql
FROM V$SESSION A
LEFT JOIN V$SQL B ON A.SQL_ADDRESS = B.ADDRESS
                   AND A.SQL_HASH_VALUE = B.HASH_VALUE
ORDER BY b.cpu_time DESC

 

 

--查出oracle当前的被锁对象

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 登录数据库时间
FROM v$locked_object l, all_objects o, v$session s
WHERE l.object_id = o.object_id
   AND l.session_id = s.sid
ORDER BY sid, s.serial#;

 

 

--kill掉当前的锁对象可以为

alter system kill session 'sid, s.serial#‘;





select * from v$access o where o.OBJECT like 'XXWPF007%' --查找正在运行的对象,获取sid
select a.serial# from v$session a WHERE A.SID=sid  --通过sid 获取serial#
alter system kill session 'sid,serial#' --eg: alter system kill session '123,3211'





SELECT * FROM V$DB_OBJECT_CACHE WHERE name='CUX_OE_ORDER_RPT_PKG' AND LOCKS!='0';












SELECT sn.username,M.SID,sn.SERIAL#,M.TYPE,
  DECODE(M.lmode,0,'None',1,'Null',2,'Row Share',3,'Row Excl.',4,'Share', 5,'S/Row Excl.',6,'Exclusive',lmode,
  LTRIM(TO_CHAR(lmode, '990'))) lmode,
  DECODE(M.request, 0,'None',1, 'Null', 2,'Row Share', 3,'Row Excl.',4,'Share', 5,'S/Row Excl.',6,'Exclusive',request,
  LTRIM(TO_CHAR(M. request, '990'))) request,M.id1,M.id2
  FROM v$session sn, v$lock M
  WHERE (sn.SID = M.SID AND M.request != 0)
    OR (sn.SID = M.SID AND M.request = 0 AND lmode != 4 
    AND (id1, id2) IN (SELECT s.id1, s.id2
                            FROM v$lock s
                            WHERE request != 0
                            AND s.id1 = M.id1
                            AND s.id2 = M.id2))
 ORDER BY id1, id2, M.request;
kill 所有占用资源的会话
命令形式:alter system kill session 'sid,serial#';
占用test_1的资源的会话:
alter system kill session '158,15184';

 

posted @ 2017-07-28 10:18  DaryllD  阅读(258)  评论(0编辑  收藏  举报