某天,测试突然说服务器慢。
通过xshell连接数据库服务器。连接都慢的吓人
连上后发现。
load average 和 wa不正常 io 占用了这么多cpu?
https://www.cnblogs.com/littlecharacter/p/12154587.html#anchor_top linux top说明
百度了2个sql查询下 当前耗时sql。
https://blog.csdn.net/weixin_43228740/article/details/89784981 这个里面很详细了。
果然一查 就是同事的某个sql引起的。
--查询执行最慢的50条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;
--查询最耗时的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;
--查询最近一小时内最慢的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
来源:oschina
链接:https://my.oschina.net/u/3065626/blog/4304294