--检查数据库的等待事件
from v$session_wait
where event not like 'SQL%' and event not like 'rdbms%'
--找出系统中耗时的操作
select b.username username,a.disk_reads reads, a.executions exec,a.disk_reads/decode(a.executions,0,1,a.executions) rds_exec_ratio, a.sql_text statementfrom v$sqlarea a,dba_users bwhere a.parsing_user_id=b.user_idand a.disk_reads >100000order by a.disk_reads desc;--查看buffer中耗时的操作
select * from (select address,rank() over( order by buffer_gets desc) as rank_bufgets, to_char(100*ratio_to_report(buffer_gets) over(),'999.99') pct_bufgets from v$sql ) where rank_bufgets <11;-- 查看buffer中耗时的操作
select * from (select sql_text,rank() over( order by buffer_gets desc) as rank_bufgets, to_char(100*ratio_to_report(buffer_gets) over(),'999.99') pct_bufgets from v$sql ) where rank_bufgets <11; --查找前十条性能差的SQLselect * from (select parsing_user_idexecutions,sorts,command_type,disk_reads,sql_text from v$sqlarea order by disk_reads desc)where rownum<10;--等待时间最多的5和系统等待事件的获取
select * from (select * from v$system_event where event not like 'sql%' order bytotal_waits desc) where rownum<=5--检查运行很久的SQL
column username format a12column opname format a16column progress format a8SELECT USERNAME,SID,OPNAME,ROUND(SOFAR*100 / TOTALWORK,0) || '%' ASPROGRESS,TIME_REMAINING,SQL_TEXT FROM V$SESSION_LONGOPS , V$SQL WHERE TIME_REMAINING <>0 AND SQL_ADDRESS=ADDRESS AND SQL_HASH_VALUE = HASH_VALUE;--检查消耗CPU最高的进程
SET LINE 240SET VERIFY OFFCOLUMN SID FORMAT 999COLUMN PID FORMAT 999COLUMN S_# FORMAT 999COLUMN USERNAME FORMAT A9 HEADING "ORA USER"COLUMN PROGRAM FORMAT A29COLUMN SQL FORMAT A60COLUMN OSNAME FORMAT A9 HEADING "OS USER"SELECT P.PID PID,S.SID SID,P.SPID SPID,S.USERNAME USERNAME,S.OSUSER OSNAME,P.SERIAL#S_#,P.TERMINAL,P.PROGRAM PROGRAM,P.BACKGROUND,S.STATUS,RTRIM(SUBSTR(A.SQL_TEXT, 1, 80))SQLFROM V$PROCESS P, V$SESSION S,V$SQLAREA A WHERE P.ADDR = S.PADDR AND S.SQL_ADDRESS= A.ADDRESS (+) AND P.SPID LIKE '%&1%'; --检查碎片程度高的表 select segment_name table_name,count(*) extents from dba_segments where owner not in ('sys','system') group by segment_name having count(*)=(select max(count(*)) from dba_segments group by segment_name) ;--检查表空间的1/O比例
select df.tablespace_name name,df.file_name "FILE",F.phyrds pyr,f.phyblkrd pbr,f.phywrts pyw,f.phyblkwrt pbw from v$filestat f,dba_data_files dfwhere f.file#=df.file_id order by df.tablespace_name; select df.tablespace_name name,df.file_name "File"from v$filestat f,dba_data_files dfwhere f.file#=df.file_idorder by tablespace_name --检测文件系统的I/O比例select substr(a.file#,1,2) "#",substr(a.name,1,30) "NAME",
a.status,a.bytes,b.phyrds,b.phywrts from v$datafile a,v$filestat bwhere a.file# = b.file#--检查死锁及处理
select sid,serial#,username,schemaname,osuser,machine,terminal,program,owner,object_name,object_type,o.object_idfrom dba_objects o,v$locked_object l,v$session swhere o.object_id=l.object_id and s.sid=l.session_id;
转:http://www.cnblogs.com/jerryxing/archive/2013/02/19/2916471.html