如何利用ash监控会话(三)

2015-02-02 23:36:39 · 作者: · 浏览: 25
1 4 60256 block# 60256 blocks 1 64 rows selected. Elapsed: 00:00:00.40 SQL> @getsql_sqlid Enter 1 for curr sql, 2 for hist sql,default 1: Enter value for sqlid: fqcxb1n33642x SQL_FULLTEXT --------------------------------------------------------------------------------------------- select count(*) from big Elapsed: 00:00:00.00 Elapsed: 00:00:00.00 SQL> @getobj_id Enter value for dblink: Enter value for obj_id: 76851 OWNER OBJECT_NAME OBJECT_TYPE CREATED STATUS -------------------- ------------------------------ ------------------- ------------------- ------- SCOTT BIG TABLE 2014-11-20 15:56:23 VALID 1 row selected. Elapsed: 00:00:00.01 SQL> @getobj_fb Enter value for file_id: 4 Enter value for block_id: 60256 OWNER SEGMENT_NAME SEGMENT_TY --------------- -------------------- ---------- SCOTT BIG TABLE 1 row selected. Elapsed: 00:00:00.37 --------------------------@脚本-------------------- --@big @sid set feedback off drop table big; create table big as select * from dba_objects; insert into big select * from big; / / / / / commit; select SUM(bytes) / 1024 / 1024 big_M from dba_segments where segment_name = 'BIG'; select count(*) from big; set feedback on --@getash_sid col p_name for a15 col p_value for a15 select SESSION_ID, NAME, P1TEXT||chr(10)||P2TEXT||chr(10)||P3TEXT p_name, p1||chr(10)||p2||chr(10)||p3 p_value, sql_id, WAIT_TIME, CURRENT_OBJ#, CURRENT_FILE#, CURRENT_BLOCK# from v$active_session_history ash, v$event_name enm where ash.event# = enm.event# and SESSION_ID = &sid order by sample_time; ---------------------------------------- --DBA_HIST_ACTIVE_SESS_HISTORY的监控:-- ---------------------------------------- --查当前时间 select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual; --根据时间找到snap_id(8天内,1小时前),因为基表非常大,利用snap_id的索引才能快速查询 select distinct snap_id from dba_hist_snapshot b where to_date('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') between b.begin_interval_time and b.end_interval_time; --top instance select /*+parallel(a,8)*/instance_number,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 group by instance_number; --top event select /*+parallel(a,8)*/event,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 and instance_number=2 and sample_time>
=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss') and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') group by event order by count(*) desc; --top user select /*+parallel(a,8)*/user_id,(select username from dba_users b where b.user_id=a.user_id) username,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 and instance_number=2 and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss') and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') group by user_id order by count(*) desc; --top sql select /*+parallel(a,8)*/sql_id,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 and instance_number=2 and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss') and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') group by sql_id order by count(*) desc; -- select SQL_TEXT from dba_hist_sqltext where sql_id='49p4hfj6azw19'; --top program select /*+parallel(a,8)*/program,count(*) from dba_hist_active_sess_history a where a.snap_id=67421 and instance_number=2 and sample_time>=to_timestamp('2014-11-20 14:07:12','yyyy-mm-dd hh24:mi:ss') and sample_time<=to_timestamp('2014-11-20 14:08:12','yyyy-mm-dd hh24:mi:ss') group by program order by count(*) desc;