SELECT snap_id
FROM DBA_HIST_SNAPSHOT x
WHERE x.END_INTERVAL_TIME >= TO_DATE ('201610251500', 'yyyymmddhh24mi')
AND x.begin_interval_time <=
TO_DATE ('201610251510', 'yyyymmddhh24mi');
2.get blocking session by snap ID
SELECT
LEVEL lv,
CONNECT_BY_ISLEAF isleaf,
CONNECT_BY_ISCYCLE iscycle,
t.session_id,
t.sql_id,
t.session_type,
t.event,
t.session_state,
t.blocking_inst_id,
t.blocking_session,
t.blocking_session_status,
t.p1text,
t.p1,
t.p2text,
t.p2,
t.p3text,
t.p3,
t.time_waited
FROM dba_hist_active_sess_history t
where snap_id > 10875
AND snap_id <= 10876
and dbid=3104116170
START WITH blocking_session IS NOT NULL
CONNECT BY NOCYCLE PRIOR dbid = dbid
AND PRIOR sample_time = sample_time
AND PRIOR blocking_inst_id = instance_number
AND PRIOR blocking_session = session_id
AND PRIOR blocking_session_serial# = session_serial#
ORDER SIBLINGS BY sample_time;
3.get top N hot objects for latest month peak time
SELECT day,
object_name,
object_type,
LOGICAL_READS,
PHYSICAL_READS,
GC_CR_BLOCKS_SERVED,
GC_CU_BLOCKS_SERVE,
Row_lock_waits,
DB_block_changes,
ITL_waits
FROM ( SELECT day,
object_name,
object_type,
LOGICAL_READS,
PHYSICAL_READS,
GC_CR_BLOCKS_SERVED,
GC_CU_BLOCKS_SERVE,
Row_lock_waits,
DB_block_changes,
ITL_waits,
Ts#,
ROW_NUMBER ()
OVER (PARTITION BY day ORDER BY Row_lock_waits DESC)
AS rownb
FROM (SELECT c.object_name,
c.object_type,
a.ts#,
a.obj#,
TO_CHAR (b.begin_interval_time, 'yyyymmdd') AS day,
TRUNC (
SUM (A.ITL_WAITS_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS ITL_WAITS,
TRUNC (
SUM (A.ROW_LOCK_WAITS_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS ROW_LOCK_WAITS,
TRUNC (
SUM (A.DB_BLOCK_CHANGES_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS DB_BLOCK_CHANGES,
TRUNC (
SUM (A.LOGICAL_READS_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS LOGICAL_READS,
TRUNC (
SUM (A.PHYSICAL_READS_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS PHYSICAL_READS,
TRUNC (
SUM (A.GC_CR_BLOCKS_SERVED_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS GC_CR_BLOCKS_SERVED,
TRUNC (
SUM (A.GC_CU_BLOCKS_SERVED_DELTA)
OVER (PARTITION BY A.OBJ#, a.snap_id),
2)
AS GC_CU_BLOCKS_SERVE,
ROW_NUMBER ()
OVER (PARTITION BY A.OBJ#, A.snap_id
ORDER BY A.OBJ#, A.snap_id)
AS RN,
A.snap_id
FROM DBA_HIST_SEG_STAT a,
DBA_HIST_SNAPSHOT b,
DBA_HIST_SEG_STAT_OBJ c
WHERE a.dbid = b.dbid
AND a.dbid = c.dbid
AND C.obj# = a.obj#
AND a.snap_id = b.snap_id
AND a.dbid = 684227036
AND TO_CHAR (b.begin_interval_time, 'hh24mi') >=
'1355'
AND TO_CHAR (b.begin_interval_time, 'hh24mi') <=
'1405'
AND b.BEGIN_INTERVAL_TIME >=
TRUNC (ADD_MONTHS (SYSDATE, -1), 'MM')
AND b.BEGIN_INTERVAL_TIME <
TRUNC (ADD_MONTHS (SYSDATE, 0), 'MM')
AND UPPER (
SUBSTR (TO_CHAR (b.begin_interval_time, 'Day'),
1,
3)) IN
('MON', 'TUE', 'WED', 'THU', 'FRI')) D
WHERE D.rn = 1
ORDER BY day DESC, ROW_LOCK_WAITS DESC)
WHERE rownb <= 10;
4.get top n SQL stats by snap ID
SELECT * FROM
(SELECT dhs.sql_id,
ROUND(SUM(dhs.elapsed_time_delta/1000000),0) elapsed_time_secs,
ROUND(SUM(dhs.cpu_time_delta/1000000),0) cpu_time_secs,
SUM(dhs.disk_reads_delta) disk_reads,
SUM(dhs.buffer_gets_delta) buffer_gets,
SUM(dhs.px_servers_execs_delta) px_server_execs,
SUM(dhs.rows_processed_delta) rows_processed,
SUM(dhs.executions_delta) executions,
ROUND(SUM(dhs.iowait_delta/1000000),0) iowait_secs,
ROUND(SUM(dhs.clwait_delta/1000000),0) clwait_secs,
ROUND(SUM(dhs.ccwait_delta/1000000),0) ccwait_secs,
ROUND(SUM(dhs.apwait_delta/1000000),0) apwait_secs
FROM dba_hist_sqlstat dhs,
gv$database d,
gv$instance i
WHERE dhs.dbid = d.dbid
AND dhs.instance_number = i.instance_number
AND dhs.snap_id > 10875 AND dhs.snap_id <= 10876
GROUP BY dhs.sql_id ORDER BY 2 DESC)
WHERE ROWNUM <= 10;
5.get top N wait events/SQLs by time waited
SELECT s.event,
s.sql_id,
COUNT (*) counts_waited,
SUM (time_waited) time_waited
FROM dba_hist_active_sess_history s,
dba_hist_seg_stat_obj o,
gv$database d,
gv$instance i
WHERE s.dbid = d.dbid
AND s.instance_number = i.instance_number
AND o.dbid(+) = s.dbid
AND o.obj#(+) = s.current_obj#
AND s.snap_id > 10875
AND s.snap_id <= 10876
GROUP BY s.event, s.sql_id
ORDER BY time_waited DESC;
SELECT s.event,
s.sql_id,
COUNT (*) counts_waited,
SUM (time_waited) time_waited
FROM dba_hist_active_sess_history s,
dba_hist_seg_stat_obj o,
gv$database d,
gv$instance i
WHERE s.dbid = d.dbid
AND s.instance_number = i.instance_number
AND o.dbid(+) = s.dbid
AND o.obj#(+) = s.current_obj#
AND s.snap_id > 10875
AND s.snap_id <= 10876
GROUP BY s.event, s.sql_id
ORDER BY time_waited DESC;
No comments:
Post a Comment