Oracle 中定位重要(消耗資源多)的SQL

weixin_30488085發表於2020-04-06

1. 檢視消耗記憶體最多的sql(v$sqlarea)

1 select b.username ,
2        a.buffer_gets , --所有子游標執行這條語句導致的讀記憶體次數
3        a.executions,   --所有子游標的執行這條語句次數
4        a.buffer_gets/decode(a.executions,0,1,a.executions),--這條語句執行一次讀取記憶體次數
5        a.sql_text SQL
6 from v$sqlarea a,dba_users b
7 where a.parsing_user_id = b.user_id and a.buffer_gets >10000
8 order by buffer_gets desc;

2.檢視消耗磁碟多的sql(v$sqlarea)

1 select b.username ,
2        a.disk_reads ,  --所有子游標執行這條語句導致的讀磁碟次數
3        a.executions,   --所有子游標的執行這條語句次數
4        a.disk_reads/decode(a.executions,0,1,a.executions),----這條語句執行一次讀取磁碟次數
5        a.sql_text SQL
6 from v$sqlarea a,dba_users b
7 where a.parsing_user_id = b.user_id and a.DISK_READS >10000
8 order by disk_reads desc;

3.檢視執行次數多的SQL(v$sqlarea)

1 select sql_text, executions 
2 from v$sqlarea 
3 where rownum<81
4 order by executions desc

4.檢視排序多的SQL(v$sqlarea)

1 select sql_text, sorts 
2 from v$sqlarea 
3 order by sorts desc
4 where rownum<21;

5.分析的次數太多,執行的次數太少,要用綁變數的方法來寫sql(v$sqlarea)

1 select substr(sql_text,1,80) "sql",count(*),sum(executions) "totexecs"
2 from v$sqlarea
3 where executions<5  --sql_text 執行次數小於5
4 group by substr(sql_text,1,80)
5 having count(*)>30  --sql_text 分析次數大於30
6 order by 2;

6.前5位使用者I/O等待最高的SQL語句 (v$sqlarea)

1 select sql_text, sql_id, elapsed_time, cpu_time, user_io_wait_time 
2 from sys.v$sqlarea
3 where rownum < 6 
4 order by 5 desc

7.檢視當前使用者&username執行的SQL(v$sqltext_with_newlines,v$session)

1 select sql_text
2 from v$sqltext_with_newlines
3 where(hash_value, address) in
4      (select sql_hash_value, sql_address
5       from v$session
6       where username='&username')
7 order by address, piece;

 

 

 

轉載於:https://www.cnblogs.com/polestar/archive/2013/03/06/2946101.html

相關文章