研究v$sqlarea,v$sql,v$sqltext

如下內容轉自http://lzfhope.blog.163.com/blog/static/63639922008101955913105

經過看這個表的結構能夠了解共享池中,SQL是如何運行的,這樣能夠了解很多關鍵的信息.
能夠了解SQL全文,執行使用的內存消耗的CPU,被裝載的次數等等比較有意義的信息
經過這個視圖能夠了解最近被執行最屢次數的SQL語句,被最多用戶執行的SQL語句.固然共享池要足夠大,設計的語句也應該儘可能考慮到共享(例如一個很簡單的就是多考慮變量綁定),研究這個對於瞭解性能仍是有必定做用的
sql

SQL_TEXT VARCHAR2(1000)    
SQL前一千個字符 內容.

SQL_FULLTEXT CLOB
SQL全文 

SQL_ID     VARCHAR2(13)    
SQL identifier of the parent cursor in the library cache 

SHARABLE_MEM    NUMBER    
使用了多少共享內存(包含子游標所使用的)

PERSISTENT_MEM    NUMBER   
打開的遊標其生命週期所消耗的固定內存(包含子有效的固定內存)

RUNTIME_MEM     NUMBER    
遊標運行時候所須要的內容(包含子游標的)

SORTS     NUMBER    
全部的排序測試(包含子游標的)

VERSION_COUNT    NUMBER   
Number of child cursors that are present in the cache under this parent

LOADED_VERSIONS    NUMBER   
Number of child cursors that are present in the cache and have their context heap (KGL heap 6) loaded  

OPEN_VERSIONS    NUMBER     
The number of child cursors that are currently open under this current parent

USERS_OPENING    NUMBER    
共有多少用戶打開它(包含子游標)

FETCHES NUMBER 
   Number    
Numberof fetches associated with the SQL statement 

EXECUTIONS    NUMBER    
總共執行次數(包含子游標)

PX_SERVERS_EXECUTIONS     NUMBER    
Total number of executions performed by Parallel eXecution Servers. The 
value is 0 when the statement has never been executed in parallel.

END_OF_FETCH_COUNT    NUMBER   
完整執行的次數,一般小於總共執行次數.
Number of times this cursor was fully executed since the cursor was brought into the library cache. The value of this statistic is not incremented when the cursor is partially executed, either because it failed during the execution or because only the first few rows produced by this cursor are fetched before the cursor is closed or re-executed. By definition,the value of the END_OF_FETCH_COUNT column should be less or equal to the value of the EXECUTIONS column.

USERS_EXECUTING    NUMBER   
共多少個用戶執行(..)  (..)表示包含子游標,下同.

LOADS    NUMBER    
對象被裝載或者重載的次數

FIRST_LOAD_TIME 
   VARCHAR2(19)     
第一次裝載的時間.

INVALIDATIONS    NUMBER   
Total number of invalidations over all the child cursors

PARSE_CALLS    NUMBER   
Sum of all parse calls to all the child cursors under this parent 統共分析的次數(..)

DISK_READS    NUMBER   
Sum of the number of disk reads over all child cursors

DIRECT_WRITES    NUMBER   
Sum of the number of direct writes over all child cursors

BUFFER_GETS    NUMBER   
Sum of buffer gets over all child cursors

APPLICATION_WAIT_TIME
    NUMBER   
Application wait time (in microseconds)

CONCURRENCY_WAIT_TIME    NUMBER   
Concurrency wait time (in microseconds)

CLUSTER_WAIT_TIME   
NUMBER    Cluster wait time (in microseconds)

USER_IO_WAIT_TIME   
NUMBER    User I/O Wait Time (in microseconds)

PLSQL_EXEC_TIME    
NUMBER    PL/SQL execution time (in microseconds)

JAVA_EXEC_TIME     NUMBER   
Java execution time (in microseconds)

ROWS_PROCESSED     NUMBER   
處理了多少條記錄

COMMAND_TYPE 
   NUMBER   
Oracle command type definition

OPTIMIZER_MODE VARCHAR2(10)   
Mode under which the SQL statement was executed

OPTIMIZER_COST     NUMBER    
Cost of this query given by the optimizer

OPTIMIZER_ENV     RAW(703)    
Optimizer environment

OPTIMIZER_ENV_HASH_VALUE    NUMBER    
Hash value for the optimizer environmen

PARSING_USER_ID NUMBER   
User ID of the user that has parsed the very first cursor under this parent

PARSING_SCHEMA_ID    NUMBER   
Schema ID that was used to parse this child cursor

PARSING_SCHEMA_NAME    VARCHAR2(30)    
Schema name that was used to parse this child cursor

KEPT_VERSIONS     NUMBER    
Number of child cursors that have been marked to be kept using the DBMS_SHARED_POOL package

ADDRESS    RAW(4 | 8)    
Address of the handle to the parent for this cursor

HASH_VALUE
    NUMBER    
Hash value of the parent statement in the library cache

OLD_HASH_VALUE    NUMBER    
Old SQL hash value 

PLAN_HASH_VALUE    NUMBER   
Numerical representation of the SQL plan for this cursor. Comparing one PLAN_HASH_VALUE to another easily identifies whether or not two plans are the same (rather than comparing the two plans line by line)

MODULE    VARCHAR2(64)   
Contains the name of the module that was executing at the time that the SQL statement was first parsed as set by calling DBMS_APPLICATION_INFO.SET_MODULE

MODULE_HASH    NUMBER    
Hash value of the module that is named in the MODULE column

ACTION    VARCHAR2(64)   
Contains the name of the action that was executing at the time that the
SQL statement was first parsed as set by calling
DBMS_APPLICATION_INFO.SET_ACTION

ACTION_HASH    NUMBER   
Hash value of the action that is named in the ACTION column          

SERIALIZABLE_ABORTS    NUMBER   
Number of times the transaction fails to serialize, producing ORA-08177 errors, totalled over all the child cursors

OUTLINE_CATEGORY    VARCHAR2(64)   
If an outline was applied during construction of the cursor, then this column displays the category of that outline. Otherwise the column is left  
blank.

CPU_TIME 
   NUMBER   
分析,執行和提取所消耗的時間(單位爲微秒)
CPU time (in microseconds) used by this cursor for parsing, executing, and fetching

ELAPSED_TIME    NUMBER   
客觀上分析,執行和提取所消耗的時間(單位爲微秒)
這個時間一般比CPU_TIME長,由於可能還包含其它時間

OUTLINE_SID    VARCHAR2(40)   
Outline session identifier

LAST_ACTIVE_CHILD_ADDRESS
    RAW(4)    
Address (identifier) of the child cursor that was the last to be active in the group (that is, the child cursor on behalf of which statistics in V$SQL were updated)

REMOTE    VARCHAR2(1)    
Indicates whether the cursor is remote mapped (Y) or not (N)

OBJECT_STATUS    VARCHAR2(19)    
Status of the cursor:
■ VALID - Valid, authorized without errors
■ VALID_AUTH_ERROR - Valid, authorized with authorization errors
■ VALID_COMPILE_ERROR - Valid, authorized with compilation errors
■ VALID_UNAUTH - Valid, unauthorized
■ INVALID_UNAUTH - Invalid, unauthorized
■ INVALID - Invalid, unauthorized but keep the timestamp

LITERAL_HASH_VALUE    NUMBER   
Hash value of the literals which are replaced with system-generated bind variables and are to be matched, when CURSOR_SHARING is used. This is not the hash value for the SQL statement. If CURSOR_SHARING is no used, then the value is 0.

LAST_LOAD_TIME    DATE    
執行計劃最後被此裝載的時間.
Time at which the query plan (heap 6) was loaded into the library cache    

IS_OBSOLETE     VARCHAR2(1)    
Indicates whether the cursor has become obsolete (Y) or not (N) happen if the number of child cursors is too large.

CHILD_LATCH    NUMBER     
Child latch number that is protecting the cursor

SQL_PROFILE    VARCHAR2(64)    
SQL profile  

PROGRAM_ID    NUMBER   
Program identifier

PROGRAM_LINE#    NUMBER    
Program line number

EXACT_MATCHING_SIGNATURE    NUMBER   
The signature used when the CURSOR_SHARING parameter is set to EXACT

FORCE_MATCHING_SIGNATURE 
   NUMBER    
The signature used when the CURSOR_SHARING parameter is set to FORCE

LAST_ACTIVE_TIME    DATE   
最後換一次查詢計劃被激活的時間.
Time at which the query plan was last active

BIND_DATA    RAW(2000)    
Bind data
其中PROGRAM_ID,PROGRAM_LINE#能夠用於定位是那個程序(一般指過程,函數或者是其它包裹等),能夠用於跟蹤。

SELECT T.USER_NAME ,e.SQL_FULLTEXT,E.PROGRAM_ID,E.PROGRAM_LINE#,X.OBJECT_NAME
  FROM V$OPEN_CURSOR T, V$SESSION D, v$sqlarea e
  JOIN  ALL_OBJECTS  X ON X.OBJECT_ID=E.PROGRAM_ID
 WHERE T.SID = D.SID
   and t.SQL_ID = e.SQL_ID
   AND T.USER_NAME IN ('DM', 'WH', 'IPD', 'MK')
服務器

關於共同點:
1)都存儲了sql內容
2) 記錄的都是位於內存中的sql內容
3) 由於是內存,因此都不保留歷史記錄
session

不一樣點:
1)存儲的爲止不都是相同。其中v$sqlv$sqlarea存儲的sql都是位於shared sql area中的sql,v$sqltext是位於sga中的sql。但文檔沒有明確說明這裏的sga是否還包含了psa(私有sql區域--共享服務器模式下)。
2)存儲sql的方式也不一樣,v$sqlv$sqlarea都是用一行來存儲sql全文,而v$sqltext用一行存儲sql的一行。
3)v$sql不存儲包含group by sql語句。一般這個視圖,在每一個查詢執行完成後更新,但對於執行好久的sql,它是每5秒更新一次,這點對於查看sql執行狀態是有意義的。
4)存儲的明細不一樣--這是最基本的。

後順便提一下,v$sqltext_with_newlinev$sqltext是同樣,不一樣的是前者並把換行符和tab替換爲空格 ,這樣更容易閱讀。V$SQLSTATSV$SQL,v$sqlarea同樣都有提供CPU的統計數據.
app

有關內存結構請參見 http://lzfhope.blog.163.com/blog/static/6363992200863012124663/ less

相關文章
相關標籤/搜索