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;