v$session_longops
This view displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution, and more operations are added for every Oracle release.
To monitor query execution progress, you must be using the cost-based optimizer and you must:
-
Set the
TIMED_STATISTICS
orSQL_TRACE
parameter totrue
-
Gather statistics for your objects with the
ANALYZE
statement or theDBMS_STATS
package
該視圖記錄了執行時間長於6秒的某個操作(這些操作可能是備份,恢復,收集統計信息,Hash Join,Sort ,Nested loop,Table Scan, Index Scan 等等),這個視圖通常用來分析SQL運行緩慢的原因,配合V$SESSION視圖。
1.必須將初始化參數 timed_statistics設置為true或者開啟sql_trace
2.必須用ANALYZE或者DBMS_STATS對對象收集過統計信息
Column | Datatype | Description |
---|---|---|
SID |
NUMBER |
Session identifier |
SERIAL# |
NUMBER |
Session serial number |
OPNAME |
VARCHAR2(64) |
Brief description of the operation |
TARGET |
VARCHAR2(64) |
The object on which the operation is carried out |
TARGET_DESC |
VARCHAR2(32) |
Description of the target |
SOFAR |
NUMBER |
The units of work done so far |
TOTALWORK |
NUMBER |
The total units of work |
UNITS |
VARCHAR2(32) |
The units of measurement |
START_TIME |
DATE |
The starting time of operation |
LAST_UPDATE_TIME |
DATE |
Time when statistics last updated |
TIMESTAMP |
DATE |
Timestamp |
TIME_REMAINING |
NUMBER |
Estimate (in seconds) of time remaining for the operation to complete |
ELAPSED_SECONDS |
NUMBER |
The number of elapsed seconds from the start of operations |
CONTEXT |
NUMBER |
Context |
MESSAGE |
VARCHAR2(512) |
Statistics summary message |
USERNAME |
VARCHAR2(30) |
User ID of the user performing the operation |
SQL_ADDRESS |
RAW(4 | 8) |
Used with the value of the SQL_HASH_VALUE column to identify the SQL statement associated with the operation |
SQL_HASH_VALUE |
NUMBER |
Used with the value of the SQL_ADDRESS column to identify the SQL statement associated with the operation |
SQL_ID |
VARCHAR2(13) |
SQL identifier of the SQL statement associated with the operation |
QCSID |
NUMBER |
Session identifier of the parallel coordinator |
SID Session標識 SERIAL# Session串號 OPNAME 操作簡要說明 TARGET 操作運行所在的對象 TARGET_DESC 目標對象說明 SOFAR 至今為止完成的工作量 TOTALWORK 總工作量 UNITS 工作量單位 START_TIME 操作開始時間 LAST_UPDATE_TIME 統計項最后更新時間 TIMESTAMP 操作的時間戳 TIME_REMAINING 預計完成操作的剩余時間(秒) ELAPSED_SECONDS 從操作開始總花費時間(秒) CONTEXT 前后關系 MESSAGE 統計項的完整描述 USERNAME 執行操作的用戶ID SQL_ADDRESS 關聯v$sql SQL_HASH_VALUE 關聯v$sql SQL_ID 關聯v$sql QCSID 主要是並行查詢一起使用
要理解的就是:比如某個SQL語句執行時間比較長,但是每個操作都沒有超過6秒鍾,那么你在V$SESSION_LONGOPS這個視圖中就無法查詢到該信息。
- 相關操作語句:
SELECT USERNAME, SID, OPNAME, ROUND(SOFAR * 100 / TOTALWORK, 0) || '%' AS PROGRESS, TIME_REMAINING, SQL_TEXT FROM V$SESSION_LONGOPS, V$SQL WHERE TIME_REMAINING <> 0 AND SQL_ADDRESS = ADDRESS AND SQL_HASH_VALUE = HASH_VALUE;
select * from v$session a,v$session_longops b where a.SID = b.SID and a.SERIAL# = b.SERIAL# ;
select * from v$sql a,v$session_longops b where a.SQL_ID = b.SQL_ID ;
select * from v$sqlarea a,v$session_longops b where a.HASH_VALUE = b.SQL_HASH_VALUE ;
如果是在RAC,改成GV$SESSION_LONGOPS這個視圖