【原创】查询占CPU高的oracle进程

1:首先使用TOP命令传到占用CPU高的SPID号

PID USERNAME THR PRI NICE SIZE RES STATE TIME CPU COMMAND
3575 oracle 1 12 0 0K 0K run 748.6H 24.98% oracle
3571 oracle 1 22 0 0K 0K sleep 706.2H 22.84% oracle

2:使用DBA账户登录数据库,使用以下SQL语句查询: 
SELECT * FROM V$PROCESS WHERE spid=3575;查询到SQL相关信息

3:根据以上查询到的信息使用以下SQL查询:
SELECT sid, program FROM V$SESSION S WHERE EXISTS(SELECT 1 FROM V$PROCESS WHERE spid=3575 AND ADDR = S.PADDR);
可以查询到具体那个客户端查询一直在不断占用ORACLE资源!

最后对这个查询进行处理!

4.根据SID查得SQLITPUB
select sql_textITPUB
   from v$sqltext 
   where a.hash_value=(select sql_hash_value
                        from v$session b
                       where b.SID='&sid')
0order by piece ASC;

根据lockwait字段可以查询当前正在等待的锁的相关信息:
select * from v$lock where kaddr in (select lockwait from v$session where sid= $sid);

(sql_address,sql_hash_value),(prev_sql_addr,prev_hash_value) 根据这两组字段, 可以查询到当前session正在执行的或最近一次执行的sql语句的详细信息:
select * from v$sqltext where address = &sql_address and hash_value = &sql_hash_value;

根据PID查SQL相关信息:
select id,serial# ,username,osuser,machine,program,process,to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') logon from v$session where paddr in ( select addr from v$process where spid in('&pid'));

根据PID查SQL语句
SELECT a.username,a.machine,a.program,a.sid,a.serial#,a.status,c.piece,c.sql_text FROM v$session a,v$process b,v$sqltext c WHERE b.spid='&spid' AND b.addr=a.paddr AND a.sql_address=c.address(+) ORDER BY c.piece;

得到进程的sid号:
select id,serial# ,username,osuser,machine,program,process,to_char(logon_time,'yyyy/mm/dd hh24:mi:ss') logon from v$session where paddr in ( select addr from v$process where spid in('&pid'));

得到session的sqltext语句:
select sql_text from v$sqltext_with_newlines where hash_value in (select SQL_HASH_VALUE from v$session where paddr in (select addr  from v$process where spid= '&pid')) order by piece;

上一篇:elipse插件整理


下一篇:twitter 监控登陆活动