查询数据库是否很慢
业务报过来,说数据库很慢,作为 DBA,怎么样知道数据库是不是很慢,然后如果慢,查出源头。
1>查询oracle目前等待次数做多的事件名
select event, count(1) from gv$session_wait group by event order by 2 desc having count(1) >10;
select sid,username,sql_id,event from v$session where wait_class !='Idle';
2>比如上面direct path read事件最多,根据事件查看sql_id:
select sw.p1,
s.sql_id,
count(*),
(ratio_to_report(count(*)) over()) * 100 pct
from v$session s, v$session_wait sw
where s.event like '%latch: cache buffers chains%'
and s.sid = sw.sid
group by sw.p1, s.sql_id
order by count(*) desc;
3>根据sql 查看sql内容:
select sql_id,sql_text from v$sql where sql_id='3mg2pq789vdzg';
查询执行计划(查看内存中执行过的执行计划):
set linesize 10000
select * from table (dbms_xplan.display_cursor('b39dwjz0a404c' , 0, 'ALLSTATS LAST cost' ));
4>临时处理--kill掉操作系统进程
select 'kill -9 ' || pro.spid
from v$session ses, v$process pro
where ses.paddr = pro.addr
and ses.sid in (select sid
from v$session
where sql_id = '3mg2pq789vdzg'
and event = 'latch: cache buffers chains');
|