定位消耗资源较大和性能低效的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个查询: