Oracle10G的性能優化之ASH生產實踐一

                                                                                      Oracle10G的ASH實踐一sql

前言: ASH是oracle10G開始推出的一個新特性,  這個特性的推出對於DBA來講是很是有價值的。它以V$Ssssion爲基礎,每秒採樣一次,session

         記錄活動會話等待的事件。ASH的信息能夠經過兩種數據字典視圖來查看,一部分是V$active_session_history,裏面的數據比較新;oracle

         另外一部分是dba_hist_active_sess_history,是歷史數據。ide

-----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      spa

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,是一個視圖。code

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,又回到問題的原點。orm

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
相關文章
相關標籤/搜索