一些性能查询的SQL 备忘

--检查数据库的等待事件

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 statement
from v$sqlarea a,dba_users b
where a.parsing_user_id=b.user_id
and   a.disk_reads >100000
order 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;


--查找前十条性能差的SQL
select * from (select parsing_user_id
executions,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 by
total_waits desc) where rownum<=5

--检查运行很久的SQL
column username format a12
column opname format a16
column progress format a8
SELECT USERNAME,SID,OPNAME,ROUND(SOFAR*100 / TOTALWORK,0) || '%' AS
PROGRESS,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 240
SET VERIFY OFF
COLUMN SID FORMAT 999
COLUMN PID FORMAT 999
COLUMN S_# FORMAT 999
COLUMN USERNAME FORMAT A9 HEADING "ORA USER"
COLUMN PROGRAM FORMAT A29
COLUMN SQL FORMAT A60
COLUMN 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 df
where 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 df
where f.file#=df.file_id
order 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 b
where a.file# = b.file#

--检查死锁及处理
select sid,serial#,username,schemaname,osuser,machine,
terminal,program,owner,object_name,object_type,o.object_id
from dba_objects o,v$locked_object l,v$session s
where o.object_id=l.object_id and s.sid=l.session_id;

posted @ 2013-02-19 09:01  jerry_xing8  阅读(422)  评论(0编辑  收藏  举报