Linux中模拟诊断Oracle高CPU占用


下面是Linux中在Linux中模拟过程
1,在一个session中模拟CPU高使用率,如下:
declare
num int:=0;
begin
loop
num:=num+1;
end loop;
end;
/

2,在shell窗口用top命令查看CPU使用情况:                                                                                                           
 PID USER     PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME CPU COMMAND
 7913 Oracle    25   0 24364  23M 22144 R    91.7  2.3   0:44   0 oracle

3,通过Oracle提供的视图查看Session情况:
SQL> select addr,spid from v$process where spid='7913';                                                                                                             
ADDR     SPID
-------- ------------
2AA1A6EC 7913
SQL> select sid,sql_id from v$session where paddr='2AA1A6EC';
       SID SQL_ID
---------- -------------
       157 948mkp962vqgy
SQL> select sql_text from v$sql where sql_id='948mkp962vqgy';
SQL_TEXT
--------------------------------------------------------------------------------
declare num int:=0; begin loop num:=num+1; end loop; end;

4,从上面分析可以知道是执行的SQL有死循环.
将对应的服务进程kill掉 kill -9 7913
[在碰到CPU高占用的时候可以根据上面的步骤,分析对应的session执行的SQL进行不通的处理]

相关内容