在系統運行過程當中,總會與數據庫的交互,經過數據庫端的日誌查詢執行時間最長與執行次數最多的sql語句,就能夠有針對性的進行調優處理。sql
select *
from (select sa.SQL_TEXT,
sa.SQL_FULLTEXT,
sa.EXECUTIONS "執行次數",
round(sa.ELAPSED_TIME / 1000000, 2) "總執行時間",
round(sa.ELAPSED_TIME / 1000000 / sa.EXECUTIONS, 2) "平均執行時間",
sa.COMMAND_TYPE,
sa.PARSING_USER_ID "用戶ID",
u.username "用戶名",
sa.HASH_VALUE
from v$sqlarea sa
left join all_users u
on sa.PARSING_USER_ID = u.user_id
where sa.EXECUTIONS > 0
order by (sa.ELAPSED_TIME / sa.EXECUTIONS) desc)
where rownum <= 50;
複製代碼
取執行時間最長的前50條sql語句。數據庫
select *
from (select s.SQL_TEXT,
s.EXECUTIONS "執行次數",
s.PARSING_USER_ID "用戶名",
rank() over(order by EXECUTIONS desc) EXEC_RANK
from v$sql s
left join all_users u
on u.USER_ID = s.PARSING_USER_ID) t
where exec_rank <= 100;
複製代碼
取執行次數最多的前100條sql語句bash