|
| 1 | +-- how much history do we have: |
| 2 | +select min(sample_time) from V$ACTIVE_SESSION_HISTORY |
| 3 | + |
| 4 | +-- top events |
| 5 | +select event,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY where sample_time> sysdate-1/24 |
| 6 | +and user_id>0 |
| 7 | +group by event |
| 8 | +order by count(*) desc; |
| 9 | + |
| 10 | + |
| 11 | +-- top sql |
| 12 | +select sql_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY where sample_time> sysdate-1/24 |
| 13 | +and user_id>0 |
| 14 | +group by sql_id |
| 15 | +order by count(*) desc; |
| 16 | + |
| 17 | + |
| 18 | +-- see specific samples |
| 19 | +select sample_time,user_id,sql_id,event from DBA_HIST_ACTIVE_SESS_HISTORY |
| 20 | +where 1=1 |
| 21 | +--and sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi') |
| 22 | +and sample_time> sysdate-1/24 |
| 23 | +--and user_id>0 |
| 24 | +--and session_id=371 |
| 25 | +order by sample_time; |
| 26 | + |
| 27 | +-- look for hot buffers |
| 28 | +select p1,p2,p3,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY |
| 29 | +where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi') |
| 30 | +and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi') |
| 31 | +and user_id>0 |
| 32 | +and event='buffer busy waits' |
| 33 | +group by p1,p2,p3 |
| 34 | +order by count(*) |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + SELECT SEGMENT_NAME, SEGMENT_TYPE FROM DBA_EXTENTS |
| 39 | + WHERE FILE_ID = 1 AND 231928 BETWEEN BLOCK_ID AND |
| 40 | + BLOCK_ID + BLOCKS - 1; |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +-- top SQL waiting for a specific events |
| 46 | +select sql_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY |
| 47 | +where sample_time> sysdate-1/24 |
| 48 | +and user_id>0 |
| 49 | +and event is null |
| 50 | +group by sql_id |
| 51 | +order by count(*) |
| 52 | + |
| 53 | +-- top programs waiting for a specific events |
| 54 | +select program,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY |
| 55 | +where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi') |
| 56 | +and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi') |
| 57 | +and user_id>0 |
| 58 | +and event='buffer busy waits' |
| 59 | +group by program |
| 60 | +order by count(*) |
| 61 | + |
| 62 | +-- top users waiting for a specific events |
| 63 | +select user_id,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY |
| 64 | +where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi') |
| 65 | +and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi') |
| 66 | +and user_id>0 |
| 67 | +and event='buffer busy waits' |
| 68 | +group by user_id |
| 69 | +order by count(*) 2 3 4 5 6 7 ; |
| 70 | + |
| 71 | +-- Everyone waiting for specific event |
| 72 | +select sample_time,user_id,sql_id,event,p1,blocking_session from V$ACTIVE_SESSION_HISTORY |
| 73 | +where event like 'library%' |
| 74 | + |
| 75 | +-- Who is waiting for specific event the most: |
| 76 | +select SESSION_ID,user_id,sql_id,round(sample_time,'hh'),count(*) from V$ACTIVE_SESSION_HISTORY |
| 77 | +where event like 'log file sync' |
| 78 | +group by SESSION_ID,user_id,sql_id,round(sample_time,'hh') |
| 79 | +order by count(*) desc |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +select event,count(*) from DBA_HIST_ACTIVE_SESS_HISTORY |
| 86 | +where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi') |
| 87 | +and sample_time< to_date('03-MAR-11 16:00','dd-mon-yy hh24:mi') |
| 88 | +and user_id>0 |
| 89 | +group by event |
| 90 | +order by count(*) desc |
| 91 | + |
| 92 | + |
| 93 | +select to_char(trunc(sample_time, 'hh24') + round((cast(sample_time as date)- trunc(cast(sample_time as date), 'hh24'))*60*24/5)*5/60/24, 'dd/mm/yyyy hh24:mi'),count(*) from DBA_HIST_ACTIVE_SESS_HISTORY |
| 94 | +where sample_time> to_date('03-MAR-11 15:30','dd-mon-yy hh24:mi') |
| 95 | +and sample_time< to_date('03-MAR-11 16:30','dd-mon-yy hh24:mi') |
| 96 | +and user_id=209 |
| 97 | +and event='buffer busy waits' |
| 98 | +group by to_char(trunc(sample_time, 'hh24') + round((cast(sample_time as date)- trunc(cast(sample_time as date), 'hh24'))*60*24/5)*5/60/24, 'dd/mm/yyyy hh24:mi') |
| 99 | +order by count(*) |
| 100 | + |
| 101 | + |
| 102 | +select sql_id,count(*) from V$ACTIVE_SESSION_HISTORY |
| 103 | +where sample_time> to_date('08-FEB-10 13:00','dd-mon-yy hh24:mi') |
| 104 | +and sample_time< to_date('08-FEB-10 16:00','dd-mon-yy hh24:mi') |
| 105 | +and user_id>0 |
| 106 | +group by sql_id |
| 107 | +order by count(*) desc |
| 108 | + |
| 109 | +select * from dba_views where view_name like 'DBA_HIST%' |
| 110 | + |
| 111 | +select sh.sample_time,sh.SESSION_ID,user_id,sh.sql_id,event,p1,blocking_session,PROGRAM,sql_text |
| 112 | +from DBA_HIST_ACTIVE_SESS_HISTORY sh |
| 113 | +left outer join DBA_HIST_SQLTEXT sq on sq.sql_id=sh.sql_id |
| 114 | +where 1=1 |
| 115 | +and sample_time> to_date('08-FEB-10 00:00','dd-mon-yy hh24:mi') |
| 116 | +and sample_time< to_date('08-FEB-10 23:00','dd-mon-yy hh24:mi') |
| 117 | +and user_id=61 |
| 118 | +--and sql_id='809u1jtt54kfy' |
| 119 | +order by sample_time |
| 120 | + |
| 121 | + |
| 122 | +select trunc(sample_time), |
| 123 | +sum(case when INSTANCE_NUMBER=1 then 1 else 0 end) inst1, |
| 124 | +sum(case when INSTANCE_NUMBER=2 then 1 else 0 end) inst2 |
| 125 | +from DBA_HIST_ACTIVE_SESS_HISTORY sh |
| 126 | +where 1=1 |
| 127 | +and user_id=61 |
| 128 | +group by trunc(sample_time) |
| 129 | +order by trunc(sample_time) |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +select * from DBA_HIST_SQLTEXT where sql_id='d15cdr0zt3vtp'; |
| 134 | +where dbms_lob.instr(sql_text, 'GLOBAL',1,1) > 0 |
| 135 | + |
| 136 | +desc DBA_HIST_ACTIVE_SESS_HISTORY |
| 137 | + |
| 138 | +EXEC DBMS_MONITOR.session_trace_enable(session_id =>1234, serial_num=>1234, waits=>TRUE, binds=>FALSE); |
| 139 | + |
| 140 | +select sample_time,user_id,sql_id,event,p1,blocking_session from V$ACTIVE_SESSION_HISTORY |
| 141 | +where event like 'library%' |
| 142 | + |
| 143 | +select * from v$active_session_history where session_id=306 |
| 144 | +6969666696 |
| 145 | +select SESSION_ID,user_id,sql_id,round(sample_time,'hh'),count(*) from V$ACTIVE_SESSION_HISTORY |
| 146 | +where event like 'log file sync' |
| 147 | +group by SESSION_ID,user_id,sql_id,round(sample_time,'hh') |
| 148 | +order by count(*) desc |
| 149 | + |
| 150 | + |
| 151 | +select * from dba_users; 61 |
0 commit comments