定位消耗资源较大和性能低效的sql

定位消耗资源较大和性能低效的sql 在应用开发和维护中对我们很有作用,可以帮助我们快捷方便的定位一些低效sql,以便我们有针对性的进行优化。

 

1.-------占用共享池超过100k的sql
 SELECT SQL_TEXT, SHARABLE_MEM
  FROM V$SQL
 WHERE SHARABLE_MEM > '100000'
 ORDER BY SHARABLE_MEM;

 

2.------查看低效sql
SELECT EXECUTIONS , DISK_READS, BUFFER_GETS,
ROUND((BUFFER_GETS-DISK_READS)/BUFFER_GETS,2) Hit_radio,
ROUND(DISK_READS/EXECUTIONS,2) Reads_per_run,
SQL_TEXT
FROM V$SQLAREA
WHERE EXECUTIONS>0
AND BUFFER_GETS > 0
AND (BUFFER_GETS-DISK_READS)/BUFFER_GETS < 0.8
ORDER BY 4 DESC;

 

3.------查询消耗资源较多的sql

select b.username用户名,a.disk_reads磁盘读取量,a.executions执行时间,  
a.disk_reads/decode(a.executions,0,1,a.executions)单位读取数,a.sql_text SQL语句  
from v$sqlarea a,dba_users b  
where a.parsing_user_id = b.user_id  
 and a.disk_reads >10000  
order by disk_reads desc;  

用buffer_gets替换disk_reads可查询出消耗内存较多的sql。

 

附:

----列出使用频率最高的5个查询:

select sql_text,executions
from (select sql_text,executions,
rank() over
(order by executions desc) exec_rank
from v$sql)
where exec_rank <=5;
 
----消耗磁盘读取(磁盘IO)最多的sql top5:
select disk_reads,sql_text
from (select sql_text,disk_reads,
dense_rank() over
(order by disk_reads desc) disk_reads_rank
from v$sql)
where disk_reads_rank <=5;

----找出需要大量缓冲读取(内存)操作的查询:
select buffer_gets,sql_text
from (select sql_text,buffer_gets,
dense_rank() over
(order by buffer_gets desc) buffer_gets_rank
from v$sql)
where buffer_gets_rank<=5;

你可能感兴趣的:(oracle,调优与开发)