oracle 调优篇 个人日志记录

前几天系统突然出现严重卡顿,部分模块卡死现象,最后排查下  发现是有些sql查询卡死  数据库连接数过大导致 ,最后按一下流程   查询出对应sql 做了下优化解决

----查看oracle DB的负载情况

​
----查看oracle DB的负载情况
SELECT *
FROM (SELECT A.INSTANCE_NUMBER,
A.SNAP_ID,
B.BEGIN_INTERVAL_TIME + 0 BEGIN_TIME,
to_char(END_INTERVAL_TIME, 'yyyy-MM-dd hh24:mm:ss') END_TIME,
ROUND(VALUE - LAG(VALUE, 1, '0')
OVER(ORDER BY A.INSTANCE_NUMBER, A.SNAP_ID)) "DB TIME"
FROM (SELECT B.SNAP_ID,
INSTANCE_NUMBER,
SUM(VALUE) / 1000000 / 60 VALUE
FROM DBA_HIST_SYS_TIME_MODEL B
WHERE B.DBID = (SELECT DBID FROM V$DATABASE)
AND UPPER(B.STAT_NAME) IN UPPER(('DB TIME'))
GROUP BY B.SNAP_ID, INSTANCE_NUMBER) A,
DBA_HIST_SNAPSHOT B
WHERE A.SNAP_ID = B.SNAP_ID
AND B.DBID = (SELECT DBID FROM V$DATABASE)
AND B.INSTANCE_NUMBER = A.INSTANCE_NUMBER)
WHERE TO_CHAR(BEGIN_TIME, 'YYYY-MM-DD') = TO_CHAR(SYSDATE, 'YYYY-MM-DD')
ORDER BY BEGIN_TIME;

​

oracle 调优篇 个人日志记录_第1张图片

--查询对应时间段的SQL
SELECT *
FROM (SELECT a.instance_number,
a.program,
a.sql_id,
a.session_state,
a.event,
count(*),
lpad(round(ratio_to_report(count(*)) over() * 100) || '%',
10,
' ') percent,
MIN(a.sample_time),
MAX(a.sample_time)
FROM dba_hist_active_sess_history a
WHERE a.sample_time BETWEEN
to_date('20210419 09:00:00', 'YYYYMMDD HH24:MI:SS') AND
to_date('20210419 10:04:00', 'YYYYMMDD HH24:MI:SS') and a.session_state!='ON CPU' and a.program is null
--and a.instance_number=2
GROUP BY a.program, a.sql_id, a.session_state, a.event,a.instance_number
ORDER BY count(*) DESC)
WHERE ROWNUM <= 100;

 

oracle 调优篇 个人日志记录_第2张图片

--根据SQLid查询具体执行情况
select * from v$sql aa where aa.SQL_ID='8qpacwjfagf1q';

oracle 调优篇 个人日志记录_第3张图片

--优化该sql

 

 

 

你可能感兴趣的:(oracle,oracle调优)