查詢資料庫中的topsql語句

db_wjw發表於2012-11-28

1、查詢使用資源最多的SQL語句:
(較高的磁碟讀取(disk_reads消耗I/O)和較高的邏輯讀取(buffer_gets消耗CPU)被用作衡量標準)
select sql_text from
(select sql_text,executions,buffer_gets,disk_reads
from v$sql
where buffer_gets > 100000
or disk_reads > 100000
order by buffer_gets + 100*disk_reads DESC)
where rownum <= 5;

2、查詢使用CPU最多的SQL語句:
(較高的邏輯讀取(buffer_gets消耗CPU)被用作衡量標準)
select sql_text from
(select sql_text,executions,buffer_gets,disk_reads
from v$sql
where buffer_gets > 100000
order by buffer_gets desc)
where rownum <= 5;
或者
(直接使用v$sql裡的cpu_time)
select sql_text,
round(cpu_time/1000000, 2) cpu_seconds from
(select * from v$sql order by cpu_time desc)
where rownum <= 5;


3、查詢使用磁碟I/O最多的SQL語句:
(較高的磁碟讀取(disk_reads消耗I/O)被用作衡量標準)
select sql_text from
(select sql_text,executions,buffer_gets,disk_reads
from v$sql
where disk_reads > 100000
order by disk_reads desc)
where rownum <= 5;

4、查詢佔用資料庫時間最多的SQL語句:
select sql_text,round(elapsed_time/1000000, 2) elapsed_seconds,executions from
(select * from v$sql order by elapsed_time desc)
where rownum <= 5;

5、查詢執行次數(executions)最多的SQL語句:
select sql_text, executions from
(select * from v$sql
where executions > 1000
order by executions desc)
where rownum <= 5;

6、查詢解析呼叫最多的SQL語句:
select sql_text,parse_calls from
(select * from v$sql
where parse_calls > 1000
order by parse_calls desc)
where rownum <= 5;

7、查詢使用共享記憶體最多的SQL語句:
(使用共享記憶體大於1048576(bytes)的SQL語句會顯示)
select sql_text,sharable_mem from
(select * from v$sql
where sharable_mem > 1048576
order by sharable_mem desc)
where rownum <= 5;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26194851/viewspace-750177/,如需轉載,請註明出處,否則將追究法律責任。

相關文章