Oracle中国的官方博客,还是有很多好文章值得借鉴,短小精悍的风格,例如这篇《如何通过dba_hist_active_sess_history分析数据库历史性能问题》,就介绍了排查性能问题的一种常用手段,可以放在我们的工具箱中。
P. S. 原文链接,
https://blogs.oracle.com/database4cn/post/dbahistactivesesshistory


SQL> conn user/passwdSQL> create table t_ash as select * from dba_hist_active_sess_history where SAMPLE_TIME between TO_TIMESTAMP ('<time_begin>', 'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP ('<time_end>', 'YYYY-MM-DD HH24:MI:SS');$ exp user/passwd file=t_ash.dmp tables=(t_ash) log=t_ash.exp.log
然后导入到测试机,
$ imp user/passwd file=t_ash.dmp log=t_ash.imp.log

set line 200 pages 1000col sample_time for a25col event for a40alter session set nls_timestamp_format='yyyy-mm-dd hh24:mi:ss.ff';selectt.dbid, t.instance_number, min(sample_time), max(sample_time), count(*) session_countfrom t_ash tgroup by t.dbid, t.instance_numberorder by dbid, instance_number;INSTANCE_NUMBER MIN(SAMPLE_TIME) MAX(SAMPLE_TIME) SESSION_COUNT1 2015-03-26 21:00:04.278 2015-03-26 22:59:48.387 21712 2015-03-26 21:02:12.047 2015-03-26 22:59:42.584 36

selectdbid, instance_number, sample_id, sample_time, count(*) session_countfrom t_ash tgroup by dbid, instance_number, sample_id, sample_timeorder by dbid, instance_number, sample_time;INSTANCE_NUMBER SAMPLE_ID SAMPLE_TIME SESSION_COUNT1 36402900 2015-03-26 22:02:50.985 41 36402910 2015-03-26 22:03:01.095 11 36402920 2015-03-26 22:03:11.195 11 36402930 2015-03-26 22:03:21.966 211 36402940 2015-03-26 22:03:32.116 1021 36402950 2015-03-26 22:03:42.226 1811 36402960 2015-03-26 22:03:52.326 2001 36402970 2015-03-26 22:04:02.446 2271 36402980 2015-03-26 22:04:12.566 2421 36402990 2015-03-26 22:04:22.666 2591 36403000 2015-03-26 22:04:32.846 2891 36403010 2015-03-26 22:04:42.966 1471 36403020 2015-03-26 22:04:53.076 21 36403030 2015-03-26 22:05:03.186 41 36403040 2015-03-26 22:05:13.296 11 36403050 2015-03-26 22:05:23.398 1

select t.dbid,t.sample_id,t.sample_time,t.instance_number,t.event,t.session_state,t.c session_countfrom (select t.*,rank() over(partition by dbid, instance_number, sample_time order by c desc) rfrom (selectt.*,count(*) over(partition by dbid, instance_number, sample_time, event) c,row_number() over(partition by dbid, instance_number, sample_time, event order by 1) r1from t_ash t/*where sample_time >to_timestamp('2013-11-17 13:59:00','yyyy-mm-dd hh24:mi:ss')and sample_time <to_timestamp('2013-11-17 14:10:00','yyyy-mm-dd hh24:mi:ss')*/) twhere r1 = 1) twhere r < 3order by dbid, instance_number, sample_time, r;SAMPLE_ID SAMPLE_TIME INSTANCE_NUMBER EVENT SESSION_STATE SESSION_COUNT36402900 22:02:50.985 1 ON CPU 336402900 22:02:50.985 1 db file sequential read WAITING 136402910 22:03:01.095 1 ON CPU 136402920 22:03:11.195 1 db file parallel read WAITING 136402930 22:03:21.966 1 cursor: pin S wait on X WAITING 1136402930 22:03:21.966 1 latch: shared pool WAITING 436402940 22:03:32.116 1 cursor: pin S wait on X WAITING 8336402940 22:03:32.116 1 SGA: allocation forcing component growth WAITING 1636402950 22:03:42.226 1 cursor: pin S wait on X WAITING 16136402950 22:03:42.226 1 SGA: allocation forcing component growth WAITING 1736402960 22:03:52.326 1 cursor: pin S wait on X WAITING 17736402960 22:03:52.326 1 SGA: allocation forcing component growth WAITING 2036402970 22:04:02.446 1 cursor: pin S wait on X WAITING 20436402970 22:04:02.446 1 SGA: allocation forcing component growth WAITING 2036402980 22:04:12.566 1 cursor: pin S wait on X WAITING 21936402980 22:04:12.566 1 SGA: allocation forcing component growth WAITING 2036402990 22:04:22.666 1 cursor: pin S wait on X WAITING 23636402990 22:04:22.666 1 SGA: allocation forcing component growth WAITING 2036403000 22:04:32.846 1 cursor: pin S wait on X WAITING 26536403000 22:04:32.846 1 SGA: allocation forcing component growth WAITING 2036403010 22:04:42.966 1 enq: US - contention WAITING 6936403010 22:04:42.966 1 latch: row cache objects WAITING 5636403020 22:04:53.076 1 db file scattered read WAITING 136403020 22:04:53.076 1 db file sequential read WAITING 1


selectlevel lv,connect_by_isleaf isleaf,connect_by_iscycle iscycle,t.dbid,t.sample_id,t.sample_time,t.instance_number,t.session_id,t.sql_id,t.session_type,t.event,t.session_state,t.blocking_inst_id,t.blocking_session,t.blocking_session_statusfrom t_ash t/*where sample_time >to_timestamp('2013-11-17 13:55:00','yyyy-mm-dd hh24:mi:ss')and sample_time <to_timestamp('2013-11-17 14:10:00','yyyy-mm-dd hh24:mi:ss')*/start with blocking_session is not nullconnect by nocycleprior dbid = dbidand prior sample_time = sample_time/*and ((prior sample_time) - sample_time between interval '-1'second and interval '1' second)*/and prior blocking_inst_id = instance_numberand prior blocking_session = session_idand prior blocking_session_serial# = session_serial#order siblings by dbid, sample_time;LV ISLEAF ISCYCLE SAMPLE_TIME INSTANCE_NUMBER SESSION_ID SQL_ID EVENT SESSION_STATE BLOCKING_INST_ID BLOCKING_SESSION BLOCKING_SESSION_STATUS1 0 0 22:04:32.846 1 1259 3ajt2htrmb83y cursor: WAITING 1 537 VALID2 1 0 22:04:32.846 1 537 3ajt2htrmb83y SGA: WAITING UNKNOWN

select t.lv,t.iscycle,t.dbid,t.sample_id,t.sample_time,t.instance_number,t.session_id,t.sql_id,t.session_type,t.event,t.seq#,t.session_state,t.blocking_inst_id,t.blocking_session,t.blocking_session_status,t.c blocking_session_countfrom (select t.*,row_number() over(partition by dbid, instance_number, sample_time order by c desc) rfrom (select t.*,count(*) over(partition by dbid, instance_number, sample_time, session_id) c,row_number() over(partition by dbid, instance_number, sample_time, session_id order by 1) r1from (selectlevel lv,connect_by_isleaf isleaf,connect_by_iscycle iscycle,t.*from t_ash t/*where sample_time >to_timestamp('2013-11-17 13:55:00','yyyy-mm-dd hh24:mi:ss')and sample_time <to_timestamp('2013-11-17 14:10:00','yyyy-mm-dd hh24:mi:ss')*/start with blocking_session is not nullconnect by nocycleprior dbid = dbidand prior sample_time = sample_time/*and ((prior sample_time) - sample_time between interval '-1'second and interval '1' second)*/and prior blocking_inst_id = instance_numberand prior blocking_session = session_idand priorblocking_session_serial# = session_serial#) twhere t.isleaf = 1) twhere r1 = 1) twhere r < 3order by dbid, sample_time, r;SAMPLE_TIME INSTANCE_NUMBER SESSION_ID SQL_ID EVENT SEQ# SESSION_STATE BLOCKING_SESSION_STATUS BLOCKING_SESSION_COUNT22:03:32.116 1 1136 1p4vyw2jan43d SGA: 1140 WAITING UNKNOWN 8222:03:32.116 1 413 9g51p4bt1n7kz SGA: 7646 WAITING UNKNOWN 222:03:42.226 1 1136 1p4vyw2jan43d SGA: 1645 WAITING UNKNOWN 15422:03:42.226 1 537 3ajt2htrmb83y SGA: 48412 WAITING UNKNOWN 422:03:52.326 1 1136 1p4vyw2jan43d SGA: 2150 WAITING UNKNOWN 16522:03:52.326 1 537 3ajt2htrmb83y SGA: 48917 WAITING UNKNOWN 822:04:02.446 1 1136 1p4vyw2jan43d SGA: 2656 WAITING UNKNOWN 18422:04:02.446 1 537 3ajt2htrmb83y SGA: 49423 WAITING UNKNOWN 1022:04:12.566 1 1136 1p4vyw2jan43d SGA: 3162 WAITING UNKNOWN 18722:04:12.566 1 2472 SGA: 1421 WAITING UNKNOWN 1522:04:22.666 1 1136 1p4vyw2jan43d SGA: 3667 WAITING UNKNOWN 19322:04:22.666 1 2472 SGA: 1926 WAITING UNKNOWN 2522:04:32.846 1 1136 1p4vyw2jan43d SGA: 4176 WAITING UNKNOWN 19622:04:32.846 1 2472 SGA: 2434 WAITING UNKNOWN 48


如果您认为这篇文章有些帮助,还请不吝点下文章末尾的"点赞"和"在看",或者直接转发pyq,

近期更新的文章:
《一个Oracle添加索引造成其他用户对此表的查询权限丢失的案例》
《你关电脑么?》
近期的热文:
文章分类和索引:
文章转载自bisal的个人杂货铺,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




