查看sql语句执⾏时间
--查看总消耗时间最多的前10条SQL语句
select *
from (select v.sql_id,
v.child_number,
v.sql_text,
last_load_time,
v.PARSING_USER_ID,
ROUND(v.ELAPSED_TIME / 1000000 / (CASE
WHEN (EXECUTIONS = 0 OR NVL(EXECUTIONS, 1 ) = 1) THEN
1
ELSE
EXECUTIONS
END),
2) "执⾏时间'S'",
v.SQL_FULLTEXT,
v.cpu_time,
v.disk_reads,
rank() over(order by v.elapsed_time desc) elapsed_rank
from v$sql v ) a
where elapsed_rank <= 100 and last_load_time > to_char(sysdate - 1/24, 'YYYY-MM-DD/HH:MI:SS') order by "执⾏时间'S'" desc
--查询最近⼀⼩时内最慢的SQL:
select executions, cpu_time/1e6 as cpu_sec, elapsed_time/1e6 as elapsed_sec, round(elapsed_time/sqrt(executions)) as important, v.*
from v$sql v
where executions > 10 and last_load_time > to_char(sysdate - 1/24, 'YYYY-MM-DD/HH:MI:SS')
order by important desc
--查看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;
--查看消耗磁盘读取最多的前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;
--查询执⾏最慢的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
leftjoinall_users u
on sa.PARSING_USER_ID = u.user_id
where sa.EXECUTIONS > 0
select语句查询日期order by (sa.ELAPSED_TIME / sa.EXECUTIONS) desc )
where rownum <= 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;
希望能帮到⼤家结果程序和sql执⾏慢的问题
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论