Home >Database >Mysql Tutorial >如何查询占CPU高的oracle进程

如何查询占CPU高的oracle进程

WBOY
WBOYOriginal
2016-06-07 17:55:42774browse

oracle占用cpu过高怎么处理,本文将介绍有关oracle进程CPU占用率过高的问题,需要了解跟多的朋友可以参考下

oracle占用cpu过高怎么处理,本文将介绍有关oracle进程CPU占用率过高的问题,需要了解跟多的朋友可以参考下
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.hashvalue=(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;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn