Oracle10G的ASH实践一
前言: ASH是oracle10G开始推出的一个新特性, 这个特性的推出对于DBA来说是非常有价值的。它以V$Ssssion为基础,每秒采样一次,
记录活动会话等待的事件。ASH的信息可以通过两种数据字典视图来查看,一部分是V$active_session_history,里面的数据比较新;
另一部分是dba_hist_active_sess_history,是历史数据。
-----1>从dba_objects查询得到V$ACTIVE_SESSION_HISTORY是一个public的同义词
SQL> select owner,object_name,object_type from dba_objects where object_name='V$ACTIVE_SESSION_HISTORY'; OWNER OBJECT_NAME OBJECT_TYPE ------------------------------ -------------------------------------------------------------------------------- ------------------- PUBLIC V$ACTIVE_SESSION_HISTORY SYNONYM
----2>到同义词视图里去查看,是从哪里的,找到了V_$ACTIVE_SESSION_HISTORY
SQL> select * from dba_synonyms where synonym_name='V$ACTIVE_SESSION_HISTORY'; OWNER SYNONYM_NAME TABLE_OWNER TABLE_NAME DB_LINK ------------------------------ ------------------------------ ------------------------------ ------------------------------ -------------------------------------------------------------------------------- PUBLIC V$ACTIVE_SESSION_HISTORY SYS V_$ACTIVE_SESSION_HISTORY
-----3>查看V_$ACTIVE_SESSION_HISTORY,是一个视图。
SQL> select owner,object_name,object_type from dba_objects where object_name='V_$ACTIVE_SESSION_HISTORY'; OWNER OBJECT_NAME OBJECT_TYPE ------------------------------ -------------------------------------------------------------------------------- ------------------- SYS V_$ACTIVE_SESSION_HISTORY VIEW
----4>查看视图代码,发现基表还是v$active_session_history,又回到问题的原点。
SQL> select text from dba_views where view_name='V_$ACTIVE_SESSION_HISTORY'; TEXT -------------------------------------------------------------------------------- select "SAMPLE_ID","SAMPLE_TIME","SESSION_ID","SESSION_SERIAL#","USER_ID","SQL_ID","SQL_CHILD_NUMBER","SQL_PLAN_HASH_VALUE","FORCE_MATCHING_SIGNATURE","SQL_OPCODE","SERVICE_HASH","SESSION_TYPE","SESSION_STATE","QC_SESSION_ID","QC_INSTANCE_ID","BLOCKING_SESSION","BLOCKING_SESSION_STATUS","BLOCKING_SESSION_SERIAL#","EVENT","EVENT_ID","EVENT#","SEQ#","P1TEXT","P1","P2TEXT","P2","P3TEXT","P3","WAIT_CLASS","WAIT_CLASS_ID","WAIT_TIME","TIME_WAITED","XID","CURRENT_OBJ#","CURRENT_FILE#","CURRENT_BLOCK#","PROGRAM","MODULE","ACTION","CLIENT_ID" from v$active_session_history
----5>突然想到动态性能视图是基于内存的。
查看V$fixed_view_definition,原来是基于GV$ACTIVE_SESSION_HISTORY。
SQL> select VIEW_DEFINITION from V$fixed_view_definition where view_name='V$ACTIVE_SESSION_HISTORY'; VIEW_DEFINITION -------------------------------------------------------------------------------- SELECT sample_id, sample_time, session_id, session_serial#, user_id, sql_id, sql_child_number, sql_plan_hash_value, force_matching_signature, sql_opcode, service_hash, session_type, session_state, qc_session_id, qc_instance_id, blocking_session, blocking_session_status, blocking_session_serial#, event, event_id, event#, seq#, p1text, p1, p2text, p2, p3text, p3, wait_class, wait_class_id, wait_time, time_waited, xid, current_obj#, current_file#, current_block#, program, module, action, client_id FROM GV$ACTIVE_SESSION_HISTORY WHERE inst_id = USERENV('INSTANCE')
----6>查找发现是GV$ACTIVE_SESSION_HISTORY是一个同义词
SQL> select owner,object_name,object_type from dba_objects where object_name='GV$ACTIVE_SESSION_HISTORY'; OWNER OBJECT_NAME OBJECT_TYPE ------------------------------ -------------------------------------------------------------------------------- ------------------- PUBLIC GV$ACTIVE_SESSION_HISTORY SYNONYM
----7>查看v$fixed_view_definition,可是字段的最大长度是4000,就认为这个视图的定义超过了4000就看不到完整的内容
SQL> desc v$fixed_view_definition; Name Type Nullable Default Comments --------------- -------------- -------- ------- -------- VIEW_NAME VARCHAR2(30) Y VIEW_DEFINITION VARCHAR2(4000) Y
---8>仍然找不到基表。换个思路,可以试着查找有没有和sql视图类似的情况。
select VIEW_DEFINITION from v$fixed_view_definition where view_name=upper('v$fixed_view_definition'); VIEW_DEFINITION -------------------------------------------------------------------------------- select VIEW_NAME , VIEW_DEFINITION from GV$FIXED_VIEW_DEFINITION where inst_id = USERENV('Instance')
---9>找到了定义和基表,查看列定义。
SQL> select VIEW_DEFINITION from v$fixed_view_definition where view_name=upper('gv$fixed_view_definition'); VIEW_DEFINITION -------------------------------------------------------------------------------- select i.inst_id,kqfvinam,kqftpsel from x$kqfvi i, x$kqfvt t where i.indx = t.indx
--10>从执行计划里可以得到,直接查看gv$active_session_history,终于找到
SQL> explain plan for select * from GV$ACTIVE_SESSION_HISTORY; Explained SQL> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT -------------------------------------------------------------------------------- Plan hash value: 2905781256 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 328 | 216K| | 1 | VIEW | GV$ACTIVE_SESSION_HISTORY | 328 | 216K| | 2 | NESTED LOOPS | | 328 | 233K| | 3 | FIXED TABLE FULL | X$KEWASH | 100 | 4800 | |* 4 | FIXED TABLE FIXED INDEX| X$ASH (ind:1) | 3 | 2046 | -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 4 - filter("S"."SAMPLE_ADDR"="A"."SAMPLE_ADDR" AND "S"."SAMPLE_ID"="A"."SAMPL "S"."SAMPLE_TIME"="A"."SAMPLE_TIME") 17 rows selected