ITPub博客

首页 > 数据库 > Oracle > 查询oracle性能SQL

查询oracle性能SQL

原创 Oracle 作者:huangdazhu 时间:2014-04-01 14:37:49 0 删除 编辑

有很多种方法可以用来找出哪些SQL语句需要优化,但是很久以来,最简单的方法都是分析保存在V$SQL视图中的缓存的SQL信息。通过V$SQL视图,可以确定具有高消耗时间、CUP和IO读取的SQL语句。

1.查看总消耗时间最多的前10条SQL语句
select *
from (select v.sql_id,
v.child_number,
v.sql_text,
v.elapsed_time,
v.cpu_time,
v.disk_reads,
rank() over(order by v.elapsed_time desc) elapsed_rank
from v$sql v) a
where elapsed_rank <= 10;

2.查看CPU消耗时间最多的前10条SQL语句
select *
from (select v.sql_id,
v.child_number,
v.sql_text,
v.elapsed_time,
v.cpu_time,
v.disk_reads,
rank() over(order by v.cpu_time desc) elapsed_rank
from v$sql v) a
where elapsed_rank <= 10;

3.查看消耗磁盘读取最多的前10条SQL语句
select *
from (select v.sql_id,
v.child_number,
v.sql_text,
v.elapsed_time,
v.cpu_time,
v.disk_reads,
rank() over(order by v.disk_reads desc) elapsed_rank
from v$sql v) a
where elapsed_rank <= 10;

4、查看消耗内存多的sql
select b.username,        a. buffer_gets,        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; 
5、查看逻辑读多的SQL
select* from(select buffer_gets, sql_text          from v$sqlarea         where buffer_gets>500000         order by buffer_gets desc) where rownum<=30; 
6、查看执行次数多的SQL
select sql_text, executions   from (select sql_text, executions from v$sqlarea order by executions desc)  where rownum < 81; 
7、查看读硬盘多的SQL
select sql_text, disk_reads from(select sql_text, disk_reads from v$sqlarea order by disk_reads desc) where rownum<21; 
8、查看排序多的SQL
select sql_text, sorts from(select sql_text, sorts from v$sqlarea order by sorts desc) where rownum<21; 
9、分析的次数太多,执行的次数太少,要用绑变量的方法来写sql
select substr(sql_text, 1, 80) "sql", count(*), sum(executions) "totexecs"
 from v$sqlarea  where executions < 5  group by substr(sql_text, 1, 80)
having count(*) > 30  order by 2; 




来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28869493/viewspace-1133941/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2013-05-08

  • 博文量
    185
  • 访问量
    407065