【會話】V$SESSION檢視
【會話】V$SESSION檢視
講到Oracle的會話,就必須首先對V$SESSION這個檢視中的每個列都非常熟悉。該檢視在Oracle 11gR2下包含97列,在Oracle 12cR2下增加了6列,共包含103列。下面作者以表格的形式對這個檢視中的重要列做詳細說明。
表 3-26 V$SESSION檢視
V$SESSION displays session information for each current session. | |||||
檢視列序號 | 列 | 資料型別 | 說明 | 官方解釋 | 備註 |
1 | SADDR | RAW(4 | 8) | 會話地址,對應於V$TRANSACTION.SES_ADDR列。 | Session address | |
2 | SID | NUMBER | 會話識別符號。 | Session identifier | |
3 | SERIAL# | NUMBER | 會話序列號,用來唯一地標識會話物件。如果該會話結束且其它會話以相同的會話ID開始,那麼可以保證會話級的命令被應用到正確的會話物件。 | Session serial number. Used to uniquely identify a session's objects. Guarantees that session-level commands are applied to the correct session objects if the session ends and another session begins with the same session ID. | |
4 | AUDSID | NUMBER |
審計會話ID,審查SESSION ID的唯一性,通常也用於尋找並行查詢模式。 SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS FROM V$SESSION WHERE AUDSID = USERENV('SESSIONID'); SELECT USERENV('LANGUAGE') 資料庫字符集, USERENV('ISDBA') 是否DBA角色, USERENV('SESSIONID') 當前會話識別符號, USERENV('ENTRYID') 可審計的會話識別符號, USERENV('LANG') 會話語言名稱的ISO簡記, USERENV('INSTANCE') 當前的例項, USERENV('TERMINAL') 當前計算機名 FROM DUAL; |
Auditing session ID | |
5 | PADDR | RAW(4 | 8) |
擁有這個會話的程式地址,對應於V$PROCESS.ADDR列,通常用於查詢會話對應的OS程式號: SELECT B.SID, B.SERIAL#, C.SPID FROM V$SESSION B, V$PROCESS C WHERE B.PADDR = C.ADDR; |
Address of the process that owns the session | |
6 | USER# | NUMBER | Oracle使用者識別符號。 | Oracle user identifier | |
7 | USERNAME | VARCHAR2(30) | Oracle使用者名稱。 | Oracle username | |
8 | COMMAND | NUMBER | 正在執行的SQL語句型別(分析的最後一個語句)。關於該列值的含義,請參閱V$SQLCOMMAND.COMMAND列。如果該列的值為0,那麼表示並沒有在V$SESSION檢視裡記錄。 |
Command in progress (last statement parsed). You can find the command name for any value n returned in this COMMAND column by running this SQL query: SELECT command_name FROM v$sqlcommand WHERE command_type = n; A value of 0 in this COMMAND column means the command is not recorded in V$SESSION. |
sys.audit_actions |
9 | OWNERID | NUMBER | 如果值為2147483644,那麼此列的內容無效,否則此列包含擁有可移植會話的使用者標符。對於利用並行從伺服器的操作,將這個值解釋為一個4位元組的值,其低位兩位元組表示會話號,而高位位元組表示查詢協調程式的例項ID。 |
Identifier of the user who owns the migratable session; the column contents are invalid if the value is 2147483644 For operations using Parallel Slaves, interpret this value as a 4-byte value. The low-order 2 bytes represent the session number and the high-order bytes represent the instance ID of the query coordinator. |
|
10 | TADDR | VARCHAR2(8) | 表示事務處理狀態物件的地址,對應於V$TRANSACTION.ADDR列。 | Address of the transaction state object | |
11 | LOCKWAIT | VARCHAR2(8) | 等待鎖的地址,對應於V$LOCK的KADDR列;若當前會話沒有被阻塞則為空 | Address of the lock the session is waiting for; NULL if none | |
12 | STATUS | VARCHAR2(8) |
會話的狀態: ?ACTIVE:當前正在執行SQL語句(waiting for/using a resource); ?INACTIVE:等待操作(即等待需要執行的SQL語句); ?KILLED:標記為終止,刪除; ?CACHED:為Oracle*XA使用而臨時快取記憶體; ?SNIPED:會話不活動,在客戶機上等待,該狀態不再被允許變為ACTIVE。 |
Status of the session: ACTIVE - Session currently executing SQL INACTIVE - Session which is inactive and either has no configured limits or has not yet exceeded the configured limits KILLED - Session marked to be killed CACHED - Session temporarily cached for use by Oracle*XA SNIPED - An inactive session that has exceeded some configured limits (for example, resource limits specified for the resource manager consumer group or idle_time specified in the user's profile). Such sessions will not be allowed to become active again. |
|
13 | SERVER | VARCHAR2(9) | 表示伺服器型別:DEDICATED、SHARED、PSEUDO、POOLED、NONE。若顯示的結果中有NONE或SHARED,則說明當前資料庫啟動了共享伺服器模式。其中,狀態為NONE的會話表示空閒的共享伺服器連線,說明當前會話沒有處理任務;若程式正在執行某些任務則會表現為SHARED狀態。PSEUDO和“ALTER SYSTEM KILL SESSION sid,serial#;”相關,如果發出ALTER SYSTEM去終止一個會話,被標記為終止的SESSION在V$SEESSION的STATUS為KILLED,對應的SERVER值為PSEUDO。POOLED和Oracle 11g推出的駐留連線池(Database Resident Connection Pool)特性相關,駐留連線池提供了資料庫層面上的連線池管理機制,為應對高併發、短會話前端應用進行有益的嘗試,POOLED表示使用駐留連線池技術的連線。 |
Server type: ?DEDICATED ?SHARED ?PSEUDO ?POOLED ?NONE |
|
14 | SCHEMA# | NUMBER | 模式使用者識別符號。 | Schema user identifier | |
15 | SCHEMANAME | VARCHAR2(30) | 模式使用者名稱。 | Schema user name | |
16 | OSUSER | VARCHAR2(30) | 作業系統客戶端使用者名稱。 | Operating system client user name | |
17 | PROCESS | VARCHAR2(24) | 作業系統的客戶端程式ID,即客戶端程式在客戶端機器上的程式ID號;V$PROCESS中的SPID表示的是作業系統的程式ID,即伺服器程式在伺服器上的程式ID。若客戶端為Windows系統,則該列的值格式為“客戶端程式ID:執行緒ID”。對於後臺程式而言(TYPE='BACKGROUND'),該列的值和V$PROCESS中的SPID的值是一致的。 | Operating system client process ID | |
18 | MACHINE | VARCHAR2(64) | 作業系統機器名。 | Operating system machine name | |
19 | PORT | NUMBER | 客戶端埠號。 | Client port number | |
20 | TERMINAL | VARCHAR2(30) | 作業系統終端名。 | Operating system terminal name | |
21 | PROGRAM | VARCHAR2(48) | 作業系統程式名。 | Operating system program name | |
22 | TYPE | VARCHAR2(10) | 會話型別,BACKGROUND表示後臺程式,USER表示使用者程式。 | Session type | |
23 | SQL_ADDRESS | RAW(4 | 8) | 與SQL_HASH_VALUE一道使用標識當前正在執行的SQL語句。 | Used with SQL_HASH_VALUE to identify the SQL statement that is currently being executed | |
24 | SQL_HASH_VALUE | NUMBER | 與SQL_ADDRESS一道使用標識當前正在執行的SQL語句。 | Used with SQL_ADDRESS to identify the SQL statement that is currently being executed | |
25 | SQL_ID | VARCHAR2(13) | 正在執行的SQL語句ID | SQL identifier of the SQL statement that is currently being executed | |
26 | SQL_CHILD_NUMBER | NUMBER | 正在執行的SQL語句的子游標的ID,從0開始 | Child number of the SQL statement that is currently being executed | |
27 | SQL_EXEC_START | DATE | 該會話開始執行該SQL語句的時間。若SQL_ID為空,則該列為空。 | Time when the execution of the SQL currently executed by this session started; NULL if SQL_ID is NULL | |
28 | SQL_EXEC_ID | NUMBER | SQL執行的識別符號ID。若SQL_ID為空或SQL還未開始執行,則該列為空。對應於V$SQL_MONITOR.SQL_EXEC_ID列。 | SQL execution identifier; NULL if SQL_ID is NULL or if the execution of that SQL has not yet started (see V$SQL_MONITOR) | |
29 | PREV_SQL_ADDR | RAW(4 | 8) | 與PREV_HASH_VALUE一起使用標識上一次執行的SQL語句。 | Used with PREV_HASH_VALUE to identify the last SQL statement executed | |
30 | PREV_HASH_VALUE | NUMBER | 與SQL_HASH_VALUE一起使用標識上一次執行的SQL語句。 | Used with SQL_HASH_VALUE to identify the last SQL statement executed | |
31 | PREV_SQL_ID | VARCHAR2(13) | 上一次執行的SQL語句ID。 | SQL identifier of the last SQL statement executed | |
32 | PREV_CHILD_NUMBER | NUMBER | 上一次執行的SQL語句的子游標ID。 | Child number of the last SQL statement executed | |
33 | PREV_EXEC_START | DATE | 上一次執行SQL語句的開始時間。 | SQL execution start of the last executed SQL statement | |
34 | PREV_EXEC_ID | NUMBER | 上一次執行SQL語句的執行ID。對應於V$SQL_MONITOR.SQL_EXEC_ID列。 | SQL execution identifier of the last executed SQL statement | |
35 | PLSQL_ENTRY_OBJECT_ID | NUMBER | Object ID of the top-most PL/SQL subprogram on the stack; NULL if there is no PL/SQL subprogram on the stack | ||
36 | PLSQL_ENTRY_SUBPROGRAM_ID | NUMBER | Subprogram ID of the top-most PL/SQL subprogram on the stack; NULL if there is no PL/SQL subprogram on the stack | ||
37 | PLSQL_OBJECT_ID | NUMBER | Object ID of the currently executing PL/SQL subprogram; NULL if executing SQL | ||
38 | PLSQL_SUBPROGRAM_ID | NUMBER | Subprogram ID of the currently executing PL/SQL object; NULL if executing SQL | ||
39 | MODULE | VARCHAR2(48) | 包含當前正在執行的模組名,正如由呼叫DBMS_APPLICATION_INFO.SET_MODULE過程所設定MODULE_HASHNUMBER上面MODULE的雜湊值。 | Name of the currently executing module as set by calling the DBMS_APPLICATION_INFO.SET_MODULE procedure | |
40 | MODULE_HASH | NUMBER | MODULE列的HASH值。 | Hash value of the MODULE column | |
41 | ACTION | VARCHAR2(32) | 包含當前執行活動的名稱,正如由呼叫DBMS_APPLICATION_INFO.SET_ACTION過程所設定ACTION_HASHNUMBER上列活動名稱的雜湊值。 | Name of the currently executing action as set by calling the DBMS_APPLICATION_INFO.SET_ACTION procedure | |
42 | ACTION_HASH | NUMBER | ACTION列的HASH值。 | Hash value of the ACTION column | |
43 | CLIENT_INFO | VARCHAR2(64) | 由DBMS_APPLICATION_INFO.SET_CLIENT_INFO過程設定的資訊。 | Information set by the DBMS_APPLICATION_INFO.SET_CLIENT_INFO procedure | |
44 | FIXED_TABLE_SEQUENCE | NUMBER |
此列包含一個數,每當會話完成一個資料庫呼叫並且存在來自動態效能表的介入選擇,它個數就增加。這個列可被效能監控程式用來監控資料庫中的統計資料。每當效能監控程式檢視資料庫時,只需要檢視當前活動的會話或在這個列中具有比上次效能監控程式所看到的最大值更大的值的會話即可。所有其他會話自上次效能監控程式檢視資料庫以來都是空閒的。 當session完成一個user call後就會增加的一個數值,也就是說,如果session inactive,它就不會增加。因此可以根據此欄位的值變化來監控某個時間點以來的session的效能情況。例如,一個小時以前,某個session的FIXED_TABLE_SEQUENCE是10000,而現在是20000,則表明一個小時內其user call比較頻繁,可以重點關注此session的performance statistics。 |
This contains a number that increases every time the session completes a call to the database and there has been an intervening select from a dynamic performance table. This column can be used by performance monitors to monitor statistics in the database. Each time the performance monitor looks at the database, it only needs to look at sessions that are currently active or have a higher value in this column than the highest value that the performance monitor saw the last time. All the other sessions have been idle since the last time the performance monitor looked at the database. | |
45 | ROW_WAIT_OBJ# | NUMBER | 被鎖定行所在TABLE的OBJECT_ID,該列和DBA_OBJECTS中的OBJECT_ID關聯可以得到被鎖定的表名。 | Object ID for the table containing the row specified in ROW_WAIT_ROW# | |
46 | ROW_WAIT_FILE# | NUMBER | 被鎖定行所在的資料檔案號,該列和v$datafile中的file#關聯可以得到資料檔名。此列僅在會話當前正在等待其它事務處理提交併且ROW_WAIT_OBJ#不為-1時有效。 | Identifier for the datafile containing the row specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1. | |
47 | ROW_WAIT_BLOCK# | NUMBER | 被鎖定行所在的資料塊號。此列僅在會話當前正在等待其它事務處理提交併且ROW_WAIT_OBJ#不為-1時有效。 | Identifier for the block containing the row specified in ROW_WAIT_ROW#. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1. | |
48 | ROW_WAIT_ROW# | NUMBER |
被鎖定的當前行的行號。此列僅在會話當前正在等待其它事務處理提交併且ROW_WAIT_OBJ#不為-1時有效。 可以通過ROW_WAIT_OBJ#、ROW_WAIT_FILE#、ROW_WAIT_BLOCK#和ROW_WAIT_ROW#這4個欄位查詢現在正在被鎖的表的相關資訊(ROWID),例如,表名、檔名及行號。 SELECT DBMS_ROWID.ROWID_CREATE(1, (SELECT DATA_OBJECT_ID FROM DBA_OBJECTS WHERE OBJECT_ID = ROW_WAIT_OBJ#), ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW#), A.ROW_WAIT_OBJ#, A.ROW_WAIT_FILE#, A.ROW_WAIT_BLOCK#, A.ROW_WAIT_ROW#, (SELECT D.OWNER || '.' || D.OBJECT_NAME FROM DBA_OBJECTS D WHERE OBJECT_ID = ROW_WAIT_OBJ#) OBJECT_NAME FROM V$SESSION A WHERE A.ROW_WAIT_OBJ# <> -1; |
Current row being locked. This column is valid only if the session is currently waiting for another transaction to commit and the value of ROW_WAIT_OBJ# is not -1. | |
49 | TOP_LEVEL_CALL# | NUMBER | Oracle top level call number | ||
50 | LOGON_TIME | DATE | 使用者的登入時間 | Time of logon | |
51 | LAST_CALL_ET | NUMBER | 使用者最後一條語句執行完畢後到sysdate的時間,單位為秒。每次使用者執行一個新的語句後,該欄位復位為0,重新開始記數。可以通過該欄位來獲得一個連線使用者最後一次運算元據庫後的空閒時間。 | If the session STATUS is currently ACTIVE, then the value represents the elapsed time (in seconds) since the session has become active.If the session STATUS is currently INACTIVE, then the value represents the elapsed time (in seconds) since the session has become inactive. | |
52 | FAILOVER_TYPE | VARCHAR2(13) |
表示TAF的型別, 1.SESSION:表示在故障切換髮生後,新的連線會被建立到正常例項,問題出現時正在執行的操作不會被繼續執行。 2.SELECT:表示在故障切換髮生後,新的連線會被建立到正常例項,問題出現時正在執行的SELECT語句會被繼續執行,在新的節點上繼續返回後續結果集,而已經返回的記錄集則拋棄。 3.NONE:表示不會發生故障切換,即禁用TAF。 |
Indicates whether and to what extent transparent application failover (TAF) is enabled for the session: NONE - Failover is disabled for this session SESSION - Client is able to fail over its session following a disconnect SELECT - Client is able to fail over queries in progress as well See Also: Oracle Database Concepts for more information on TAF Oracle Database Net Services Administrator's Guide for information on configuring TAF |
|
53 | FAILOVER_METHOD | VARCHAR2(10) | 指定TAF的方法,可選項有BASIC(資料庫會在故障切換時在目標例項中建立會話)和PRECONNECT(資料庫會在最初建立連線時就同時建立到所有例項的連線,當發生故障時就可以立刻切換到其它鏈路上,這會對目標例項產生額外的工作負載)。需要注意的是,PRECONNECT選項只能用於客戶端的TAF配置,不能用於服務端的TAF配置。BASIC方式在Failover時會有延遲,PRECONNECT方式雖然沒有時間延遲,但是會建立多個冗餘連線會消耗更多資源,兩者就是用時間換資源和用資源換時間的區別。 |
Indicates the transparent application failover method for the session: NONE - Failover is disabled for this session BASIC - Client itself reconnects following a disconnect PRECONNECT - Backup instance can support all connections from every instance for which it is backed up |
|
54 | FAILED_OVER | VARCHAR2(3) | 若當前會話執行在故障切換模式並進行過故障切換,則為TRUE,否則為FALSE。 | Indicates whether the session is running in failover mode and failover has occurred (YES) or not (NO) | |
55 | RESOURCE_CONSUMER_GROUP | VARCHAR2(32) | 會話的當前資源使用者組的名稱 | Name of the session's current resource consumer group | |
56 | PDML_ENABLED | VARCHAR2(3) | 此列已被PDML_STATUS所替代。 | This column has been replaced by the PDML_STATUS column | |
57 | PDML_STATUS | VARCHAR2(8) | 如果ENABLED,那麼會話正處於PARALLEL DML啟用方式。如果DISABLED,那麼此會話不支援PARALLEL DML啟用方式。如果FORCED,那麼會話已經更改為強制PARALLEL DML。 | If ENABLED, the session is in a PARALLEL DML enabled mode. If DISABLED, PARALLEL DML enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DML. | |
58 | PDDL_STATUS | VARCHAR2(8) | 如果ENABLED,那麼會話正處於PARALLEL DDL啟用方式。如果DISABLED,那麼此會話不支援PARALLEL DDL啟用方式。如果FORCED,那麼會話已經更改為強制PARALLEL DDL。 | If ENABLED, the session is in a PARALLEL DDL enabled mode. If DISABLED, PARALLEL DDL enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DDL. | |
59 | PQ_STATUS | VARCHAR2(8) | 如果ENABLED,那麼會話正處於PARALLEL QUERY啟用方式。如果DISABLED,那麼此會話不支援PARALLEL QUERY啟用方式。如果FORCED,那麼會話已經更改為強制PARALLEL QUERY。 | If ENABLED, the session is in a PARALLEL QUERY enabled mode. If DISABLED, PARALLEL QUERY enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL QUERY. | |
60 | CURRENT_QUEUE_DURATION | NUMBER | If queued (1), the current amount of time the session has been queued. If not currently queued, the value is 0. | ||
61 | CLIENT_IDENTIFIER | VARCHAR2(64) | 會話的客戶端標識。 | Client identifier of the session | |
62 | BLOCKING_SESSION_STATUS | VARCHAR2(11) | 標識當前會話是否被阻塞。VALID表示當前會話被阻塞,可以通過BLOCKING_INSTANCE和 BLOCKING_SESSION列查詢到阻塞會話;“NO HOLDER”表示沒有被阻塞;“NOT IN WAIT”表示當前會話未等待;UNKNOWN表示未知。 |
This column provides details on whether there is a blocking session: VALID - there is a blocking session, and it is identified in the BLOCKING_INSTANCE and BLOCKING_SESSION columns NO HOLDER - there is no session blocking this session NOT IN WAIT - this session is not in a wait UNKNOWN - the blocking session is unknown |
|
63 | BLOCKING_INSTANCE | NUMBER | 當BLOCKING_SESSION_STATUS的值為VALID時,該列表示阻塞會話的例項號(Instance Number)。 | Instance identifier of the blocking session. This column is valid only if BLOCKING_SESSION_STATUS has the value VALID. | |
64 | BLOCKING_SESSION | NUMBER | 當BLOCKING_SESSION_STATUS的值為VALID時,該列表示阻塞會話的SID。 | Session identifier of the blocking session. This column is valid only if BLOCKING_SESSION_STATUS has the value VALID. | |
65 | FINAL_BLOCKING_SESSION_STATUS | VARCHAR2(11) |
The final blocking session is the final element in the wait chain constructed by following the sessions that are blocked by one another starting with this session. In the case of a cyclical wait chain, one of the sessions in the wait chain will be chosen as the final blocker. This column provides details on whether there is a final blocking session: VALID - there is a final blocking session and it is identified in the FINAL_BLOCKING_INSTANCE and FINAL_BLOCKING_SESSION columns NO HOLDER - there is no session blocking this session NOT IN WAIT - this session is not in a wait UNKNOWN - the final blocking session is unknown |
||
66 | FINAL_BLOCKING_INSTANCE | NUMBER | Instance identifier of the final blocking session. This column is valid only if FINAL_BLOCKING_SESSION_STATUS has the value VALID. | ||
67 | FINAL_BLOCKING_SESSION | NUMBER | Session identifier of the blocking session. This column is valid only if FINAL_BLOCKING_SESSION_STATUS has the value VALID. | ||
68 | SEQ# | NUMBER | A number that uniquely identifies the current or last wait (incremented for each wait) | ||
69 | EVENT# | NUMBER | 等待事件的事件號,對應於V$EVENT_NAME.EVENT#列。 | Event number | |
70 | EVENT | VARCHAR2(64) | 等待事件的名稱,若為空則表示ON CPU。 |
Resource or event for which the session is waiting See Also: Appendix C, "Oracle Wait Events" |
|
71 | P1TEXT | VARCHAR2(64) | Description of the first wait event parameter | ||
72 | P1 | NUMBER | First wait event parameter (in decimal) | ||
73 | P1RAW | RAW(8) | First wait event parameter (in hexadecimal)Foot 2 | ||
74 | P2TEXT | VARCHAR2(64) | Description of the second wait event parameter | ||
75 | P2 | NUMBER | Second wait event parameter (in decimal) | ||
76 | P2RAW | RAW(8) | Second wait event parameter (in hexadecimal)Footref 2 | ||
77 | P3TEXT | VARCHAR2(64) | Description of the third wait event parameter | ||
78 | P3 | NUMBER | Third wait event parameter (in decimal) | ||
79 | P3RAW | RAW(8) | Third wait event parameter (in hexadecimal)Footref 2 | ||
80 | WAIT_CLASS_ID | NUMBER | Identifier of the class of the wait event | ||
81 | WAIT_CLASS# | NUMBER | Number of the class of the wait event | ||
82 | WAIT_CLASS | VARCHAR2(64) | Name of the class of the wait event | ||
83 | WAIT_TIME | NUMBER |
If the session is currently waiting, then the value is 0. If the session is not in a wait, then the value is as follows: > 0 - Value is the duration of the last wait in hundredths of a second -1 - Duration of the last wait was less than a hundredth of a second -2 - Parameter TIMED_STATISTICS was set to false This column has been deprecated in favor of the columns WAIT_TIME_MICRO and STATE. |
||
84 | SECONDS_IN_WAIT | NUMBER | If the session is currently waiting, then the value is the amount of time waited for the current wait. If the session is not in a wait, then the value is the amount of time since the start of the last wait.This column has been deprecated in favor of the columns WAIT_TIME_MICRO and TIME_SINCE_LAST_WAIT_MICRO. | ||
85 | STATE | VARCHAR2(19) |
Wait state: WAITING - Session is currently waiting WAITED UNKNOWN TIME - Duration of the last wait is unknown; this is the value when the parameter TIMED_STATISTICS is set to false WAITED SHORT TIME - Last wait was less than a hundredth of a second WAITED KNOWN TIME - Duration of the last wait is specified in the WAIT_TIME column |
||
86 | WAIT_TIME_MICRO | NUMBER | Amount of time waited (in microseconds). If the session is currently waiting, then the value is the time spent in the current wait. If the session is currently not in a wait, then the value is the amount of time waited in the last wait. | ||
87 | TIME_REMAINING_MICRO | NUMBER |
Value is interpreted as follows: > 0 - Amount of time remaining for the current wait (in microseconds) 0 - Current wait has timed out -1 - Session can indefinitely wait in the current wait NULL - Session is not currently waiting |
||
88 | TIME_SINCE_LAST_WAIT_MICRO | NUMBER | Time elapsed since the end of the last wait (in microseconds). If the session is currently in a wait, then the value is 0. | ||
89 | SERVICE_NAME | VARCHAR2(64) | Service name of the session | ||
90 | SQL_TRACE | VARCHAR2(8) | Indicates whether SQL tracing is enabled (ENABLED) or disabled (DISABLED) | ||
91 | SQL_TRACE_WAITS | VARCHAR2(5) | Indicates whether wait tracing is enabled (TRUE) or not (FALSE) | ||
92 | SQL_TRACE_BINDS | VARCHAR2(5) | Indicates whether bind tracing is enabled (TRUE) or not (FALSE) | ||
93 | SQL_TRACE_PLAN_STATS | VARCHAR2(10) |
Frequency at which row source statistics are dumped in the trace files for each cursor: never first_execution all_executions |
||
94 | SESSION_EDITION_ID | NUMBER | Shows the value that, in the session, would be reported by sys_context('USERENV', 'SESSION_EDITION_ID') | ||
95 | CREATOR_ADDR | RAW(4 | 8) | 對應V$PROCESS的ADDR列,若當前會話為KILLED狀態的話,則可以使用該列來返回會話的地址。 | Address of the creating process or circuit | |
96 | CREATOR_SERIAL# | NUMBER | Serial number of the creating process or circuit | ||
97 | ECID | VARCHAR2(64) | Execution context identifier (sent by Application Server) | ||
98 | SQL_TRANSLATION_PROFILE_ID | NUMBER | Object number of the SQL translation profile | 12c | |
99 | PGA_TUNABLE_MEM | NUMBER |
The amount of tunable PGA memory (in bytes). Untunable memory is PGA_ALLOC_MEM from V$PROCESS minus PGA_TUNABLE_MEM from V$SESSION. |
12c | |
100 | SHARD_DDL_STATUS | VARCHAR2(8) |
Indicates whether shard DDL is enabled in the current session (ENABLED) or not (DISABLED). This value is only relevant for the shard catalog database. |
12cR2 | |
101 | CON_ID | NUMBER |
The ID of the container to which the data pertains. Possible values include: 0: This value is used for rows containing data that pertain to the entire CDB. This value is also used for rows in non-CDBs. 1: This value is used for rows containing data that pertain to only the root n: Where n is the applicable container ID for the rows containing data |
12c | |
102 | EXTERNAL_NAME | VARCHAR2(1024) | External name of the database user. For enterprise users, returns the Oracle Internet Directory DN. | 12c | |
103 | PLSQL_DEBUGGER_CONNECTED | VARCHAR2(5) |
Indicates whether the session is connected to a PL/SQL debugger. Possible values: TRUE FALSE |
12c |
Oracle 11g中v$session檢視server列的含義
V$SESSION檢視包含很多列,涉及到session資訊、client資訊以及application資訊等。其中,server列資訊表示該session的連線型別,也就是我們們常說的共享伺服器連線或者專用伺服器連線。那有沒有其他伺服器連線型別呢?下面我們就看一下Oracle11g官方文件中server列的幾個取值:
- DEDICATED
- SHARED
- PSEUDO
- POOLED
- NONE
其中,DEDICATED表示專用伺服器連線,SHARED表示共享伺服器連線,這兩個大家較為熟悉;
PSEUDO和kill session相關,如果發出ALTER SYSTEM去終止session的會話,等待60秒後沒有終止session,會收到一個資訊表明session已標識為終止。被標記為終止的session在v$seession的status為KILLED,對應的server值可能為PSEUDO;
POOLED和Oracle 11g推出的駐留連線池(Database Resident Connection Pool)特性相關,駐留連線池提供了資料庫層面上的連線池管理機制,為應對高併發、短會話前端應用進行有益的嘗試,POOLED表示使用駐留連線池技術的連線;
NONE表示空閒的共享伺服器連線。
v$session中LAST_CALL_ET引數的理解
在實際的資料庫應用中,我們經常遇到這樣一個問題,連線到Oracle資料庫的使用者在作了一次操作後,再也沒有後續操作,但卻長時間沒有和資料庫斷開連線。最近在研究一箇中介軟體到資料庫中的長連線異常問題,查詢到v$session中LAST_CALL_ET引數,覺得這個引數很有用,下面是自己的一點理解:
1. 引數定義
LOGON_TIME 是一個日期型(Date)欄位,為使用者登陸時間;
LAST_CALL_ET是一個數字型(Number)欄位,其含義是使用者最後一條語句執行完畢後到sysdate的時間,單位為秒。每次使用者執行一個新的語句後,該欄位復位為0,重新開始記數。我們可以通過該欄位來獲得一個連線使用者最後一次運算元據庫後的空閒時間。
針對這兩個引數定義的測試:
SQL> conn system/oracle@devdb2;
已連線。
SQL> select ses.SID,ses.username,ses.machine,ses.program,ses.last_call_et,sql.hash_value,sql.sql_text
from v$session ses, v$sql sql
where ses.sql_hash_value = sql.hash_value(+)
and ses.PROGRAM = 'sqlplus.exe'
SID | USERNAME | MACHINE | PROGRAM | LAST_CALL_ET | HASH_VALUE | SQL_TEXT |
132 | SYSTEM | ZDC\BEILEI | sqlplus.exe | 3(登陸後的時間) |
SQL> select count(*) from user_object_size;
SID | USERNAME | MACHINE | PROGRAM | LAST_CALL_ET | HASH_VALUE | SQL_TEXT |
132 | SYSTEM | ZDC\BEILEI | sqlplus.exe | 24(sql執行的時間) | 178228611 | select count(*) from user_object_size |
SQL> select count(*) from user_object_size;
COUNT(*)
----------
20
SID | USERNAME | MACHINE | PROGRAM | LAST_CALL_ET | HASH_VALUE | SQL_TEXT |
132 | SYSTEM | ZDC\BEILEI | sqlplus.exe | 1(sql執行完,引數復位0,重新開始計算到sysdate的時間/s) |
2. 識別超過一定空閒時間的連線
select username,logon_time,last_call_et,
to_char(sysdate-(last_call_et/(60*60*24)),'hh24:mi:ss') last_work_time
from v$session
where username is not null;
select ses.username,ses.machine,ses.program,ses.last_call_et,sql.hash_value,sql.sql_text
from v$session ses, v$sql sql
where ses.sql_hash_value = sql.hash_value
and ses.last_call_et > 600
and ses.type = 'USER'
SELECT s.username 使用者名稱稱, s.status 狀態,s.machine 機器名稱,
osuser 作業系統使用者名稱稱,spid UNIX程式號,
'kill -9 '||spid UNIX級斷開連線,
'alter system kill session ' ||''''||s.sid||',
'||s.serial# || ''';' Oracle級斷開連線,
TO_CHAR (logon_time, 'dd/mm/yyyy hh24:mi:ss') 登陸時間,
last_call_et 空閒時間秒,
TO_CHAR (TRUNC (last_call_et / 3600, 0))||' '||' HRS '||
TO_CHAR (TRUNC ((last_call_et - TRUNC(last_call_et / 3600, 0) * 3600) / 60, 0) ) ||' MINS' 空閒時間小時分鐘,
module 模組
FROM v$session s, v$process p
WHERE TYPE = 'USER'
AND p.addr = s.paddr
AND status != 'KILLED'
-- AND SUBSTR (machine, 1, 19) NOT IN ('機器名')
AND last_call_et > 60 * 60 * 1-- 空閒時間超過1小時的連線
ORDER BY last_call_et desc;
select sid,username,status,
to_char(logon_time,'dd-mm-yy hh:mi:ss') "LOGON",
floor(last_call_et/3600)||':'||
floor(mod(last_call_et,3600)/60)||':'||
mod(mod(last_call_et,3600),60) "IDLE",
program
from v_$session
where type='USER'
order by last_call_et;
select s.process, s.sid, t.sql_text
from gv$session s, gv$sql t
where s.sql_address =t.address
and s.sql_hash_value =t.hash_value
--and s.program like '%JDBC%'
and s.last_call_et > 600
and s.status = 'ACTIVE'
個人認為還是查清楚這些異常連線的原因,不要輕易的kill掉這些會話。
參考文獻:http://www.weste.net/2006/8-7/11352794038.html
Subject: | Removing Sessions in Killed Status on Unix | |||
Doc ID: | 274216.1 | Type: | BULLETIN | |
Modified Date : | 11-NOV-2008 | Status: | PUBLISHED |
v$Session詳解
從Oracle10gR1開始,Oracle在V$SESSION中增加關於等待事件的欄位,實際上也就是把原來V$SESSION_WAIT檢視中的所有欄位全部整合到了V$SESSION檢視中,開始的時候我還以為ASH是依賴聯合查詢來獲取資訊的,仔細一看才發現現在V$SESSION已經發生了變化。(如果進一步研究你會發現,實際上V$SESSION的底層查詢語句及X$表已經有了變化)
這一變化使得我們的查詢得以簡化,但是也使得V$SESSION_WAIT開始變得多餘,此外V$SESSION中還增加了BLOCKING_SESSION等欄位,以前我們需要通dba_waiters等檢視才能獲得的資訊,現在也可以直接從V$SESSION中得到了。既然這樣,讓我們好好研究V$SESSION檢視中每個欄位的含義。
首先,請看官方文件上面關於V$SESSION欄位的說明:
v$session:This view has one row for every session connected to the database instance. The sessions include user sessions, as well as background processes like DBWR, LGWR, archiver.
1、SADDR --Session address Session地址
2、SID --Session identifier Session ID
3、SERIAL#
官方解釋:Session serial number. Used to uniquely identify a session's objects. Guarantees that session-level commands are applied to the correct session objects if the session ends and another session begins with the same session ID.
sid 會重用,但是同一個SID被重用時,serial#會增加,不會重複。
比如說你在10:00時發現有一個SID 為10 ,serial#為100的session 不正常,想殺掉他,要是直接用kill sid 10 ,而同時這個session 主動退出,新session近來 而又正好用了 10這個SID (這時新session的serial#不會=100,只會比100高),就會發生誤殺的情況。所以Oracle要求我們在殺session時,必須同時指定sid和serial#.
從另外一個角度上說,sid 在同一個instance的當前session中是一個unique key, 而sid ,serial#則是在整個instance生命期內的所有session中是unique key。(不考慮serial#超過最大值,重用的情況)
3、AUDSID --Auditing session ID
from asktom
the audsid column is populated via a sequence and for normal
sessions is the same as "userenv('sessionid')" -- but for some background sessions -- it is not set
(it comes back as "0" making the view not work.
So, I'd just ignore "audsid" for now and use SID.
4、paddr ,這個我們要和saddr、taddr一起講一下
saddr(session address):表示當前記錄的記憶體地址;
paddr(process address):該session對應的程式地址,關聯v$process的addr欄位,可以通過這個欄位查處當前session對應作業系統的那個程式的id;
taddr(transation address):當前有活動事務的地址,關聯v$transaction表的addr,通過這個欄位關聯查出當前session正在使用的回滾段的情況,以及當前事務的大小等資訊
5、USER#、USERNAME 表示登入的使用者名稱編號和使用者名稱,比如說sytem、test等,如果沒有說明是後臺程式產生的session。
比如說:QMNC、MMON 、MMNL 等後臺經常,這是時候我們可以看看v$session 的PROGRAM欄位。
6、COMMAND Command in progress (last statement parsed); for a list of values, seeTable 7-5. These values also appear in the AUDIT_ACTIONStable.
COMMAND Column of V$SESSION and Corresponding Commands
Number |
Command |
Number |
Command |
1 |
CREATE TABLE |
2 |
INSERT |
3 |
SELECT |
4 |
CREATE CLUSTER |
5 |
ALTER CLUSTER |
6 |
UPDATE |
7 |
DELETE |
8 |
DROP CLUSTER |
9 |
CREATE INDEX |
10 |
DROP INDEX |
11 |
ALTER INDEX |
12 |
DROP TABLE |
13 |
CREATE SEQUENCE |
14 |
ALTER SEQUENCE |
15 |
ALTER TABLE |
16 |
DROP SEQUENCE |
17 |
GRANT OBJECT |
18 |
REVOKE OBJECT |
19 |
CREATE SYNONYM |
20 |
DROP SYNONYM |
21 |
CREATE VIEW |
22 |
DROP VIEW |
23 |
VALIDATE INDEX |
24 |
CREATE PROCEDURE |
25 |
ALTER PROCEDURE |
26 |
LOCK |
27 |
NO-OP |
28 |
RENAME |
29 |
COMMENT |
30 |
AUDIT OBJECT |
31 |
NOAUDIT OBJECT |
32 |
CREATE DATABASE LINK |
33 |
DROP DATABASE LINK |
34 |
CREATE DATABASE |
35 |
ALTER DATABASE |
36 |
CREATE ROLLBACK SEG |
37 |
ALTER ROLLBACK SEG |
38 |
DROP ROLLBACK SEG |
39 |
CREATE TABLESPACE |
40 |
ALTER TABLESPACE |
41 |
DROP TABLESPACE |
42 |
ALTER SESSION |
43 |
ALTER USER |
44 |
COMMIT |
45 |
ROLLBACK |
46 |
SAVEPOINT |
47 |
PL/SQL EXECUTE |
48 |
SET TRANSACTION |
49 |
ALTER SYSTEM |
50 |
EXPLAIN |
51 |
CREATE USER |
52 |
CREATE ROLE |
53 |
DROP USER |
54 |
DROP ROLE |
55 |
SET ROLE |
56 |
CREATE SCHEMA |
57 |
CREATE CONTROL FILE |
59 |
CREATE TRIGGER |
60 |
ALTER TRIGGER |
61 |
DROP TRIGGER |
62 |
ANALYZE TABLE |
63 |
ANALYZE INDEX |
64 |
ANALYZE CLUSTER |
65 |
CREATE PROFILE |
66 |
DROP PROFILE |
67 |
ALTER PROFILE |
68 |
DROP PROCEDURE |
70 |
ALTER RESOURCE COST |
71 |
CREATE MATERIALIZED VIEW LOG |
72 |
ALTER MATERIALIZED VIEW LOG |
73 |
DROP MATERIALIZED VIEW LOG |
74 |
CREATE MATERIALIZED VIEW |
75 |
ALTER MATERIALIZED VIEW |
76 |
DROP MATERIALIZED VIEW |
77 |
CREATE TYPE |
78 |
DROP TYPE |
79 |
ALTER ROLE |
80 |
ALTER TYPE |
81 |
CREATE TYPE BODY |
82 |
ALTER TYPE BODY |
83 |
DROP TYPE BODY |
84 |
DROP LIBRARY |
85 |
TRUNCATE TABLE |
86 |
TRUNCATE CLUSTER |
91 |
CREATE FUNCTION |
92 |
ALTER FUNCTION |
93 |
DROP FUNCTION |
94 |
CREATE PACKAGE |
95 |
ALTER PACKAGE |
96 |
DROP PACKAGE |
97 |
CREATE PACKAGE BODY |
98 |
ALTER PACKAGE BODY |
99 |
DROP PACKAGE BODY |
100 |
LOGON |
101 |
LOGOFF |
102 |
LOGOFF BY CLEANUP |
103 |
SESSION REC |
104 |
SYSTEM AUDIT |
105 |
SYSTEM NOAUDIT |
106 |
AUDIT DEFAULT |
107 |
NOAUDIT DEFAULT |
108 |
SYSTEM GRANT |
109 |
SYSTEM REVOKE |
110 |
CREATE PUBLIC SYNONYM |
111 |
DROP PUBLIC SYNONYM |
112 |
CREATE PUBLIC DATABASE LINK |
113 |
DROP PUBLIC DATABASE LINK |
114 |
GRANT ROLE |
115 |
REVOKE ROLE |
116 |
EXECUTE PROCEDURE |
117 |
USER COMMENT |
118 |
ENABLE TRIGGER |
119 |
DISABLE TRIGGER |
120 |
ENABLE ALL TRIGGERS |
121 |
DISABLE ALL TRIGGERS |
122 |
NETWORK ERROR |
123 |
EXECUTE TYPE |
157 |
CREATE DIRECTORY |
158 |
DROP DIRECTORY |
159 |
CREATE LIBRARY |
160 |
CREATE JAVA |
161 |
ALTER JAVA |
162 |
DROP JAVA |
163 |
CREATE OPERATOR |
164 |
CREATE INDEXTYPE |
165 |
DROP INDEXTYPE |
167 |
DROP OPERATOR |
168 |
ASSOCIATE STATISTICS |
169 |
DISASSOCIATE STATISTICS |
170 |
CALL METHOD |
171 |
CREATE SUMMARY |
172 |
ALTER SUMMARY |
173 |
DROP SUMMARY |
174 |
CREATE DIMENSION |
175 |
ALTER DIMENSION |
176 |
DROP DIMENSION |
177 |
CREATE CONTEXT |
178 |
DROP CONTEXT |
179 |
ALTER OUTLINE |
180 |
CREATE OUTLINE |
181 |
DROP OUTLINE |
182 |
UPDATE INDEXES |
183 |
ALTER OPERATOR |
|
|
7、OWNERID
如果值為2147483644,則此列的內容無效。否則此列包含擁有可移植會話的使用者標符。對於利用並行從伺服器的操作,將這個值解釋為一個48 位元組的值。其低位兩位元組表示會話號,而高位位元組表示查詢協調程式的例項ID
8、LOCKWAIT Address of lock waiting for; null if none
等待鎖的地址;如果沒有,為NULL
9、STATUS
Status of the session:
-
ACTIVE - Session currently executing SQL
-
INACTIVE
-
KILLED - Session marked to be killed
-
CACHED - Session temporarily cached for use by Oracle*XA
-
SNIPED - Session inactive, waiting on the client
文件裡面已經說的比較清楚了
10、SERVER
伺服器型別:DEDICATED(獨有)、SHARED(共享)、PSEUDO、NONE
伺服器型別在安裝時候已經選擇了,我們一般選擇DEDICATED模式,非共享。
11、SCHEMA# 模式使用者識別符號
12、SCHEMANANME 模式使用者名稱、OSUSER 作業系統客戶機使用者
13、PROCESS 作業系統客戶機程式ID
關於v$process與v$session中process的理解
說明
v$session有個process欄位,V$PROCESS有個SPID欄位,這兩個欄位是不是一個意思呢?是不是都代表會話的作業系統程式呢?
官方文件上的解釋:
SPID VARCHAR2(12) Operating system process identifier
PROCESS VARCHAR2(9) Operating system client process ID
本文以資料庫伺服器安裝在linux上為例進行說明。
V$PROCESS中的SPID表示的是作業系統的程式,v$session中的process表示客戶端程式ID,即客戶端程式在客戶端機器上的程式ID號。一個表示客戶端程式在客戶端機器上的程式號,一個表示伺服器程式在伺服器上的程式號。
連線伺服器的會話,發起會話的客戶端程式可能是unix程式,也可能是windows程式。
-------------------
windows客戶端程式
-------------------
例如,使用windows程式連線unix上的資料庫,對應會話sid=35,對應客戶端windows的988:5412
今天有朋友問到V$SESSION中的PROCESS是啥意思,聯機文件的解釋如下:
PROCESS |
VARCHAR2(24) |
Operating system client process ID |
作業系統的客戶端程式ID。
但是如果我們檢視PROCESS列,會發現並不像文件解釋的那麼明確,
這個列有2個數字組成,中間用:分割,
我們從WINDOWS 用SQLPLUS登陸到資料庫中,然後查詢PROCESS欄位,就很容易發現:前面的數字是客戶端程式的ID號。
C:\Documents and Settings\htaix>sqlplus scott/tiger@testdb
SQL*Plus: Release 10.2.0.1.0 - Production on 星期三 12月 12 10:48:33 2012
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連線到:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> select process
2 from v$session where username='SCOTT';
PROCESS
------------------------
14612:4716
從WINDOWS的工作管理員就很容易發現14612是sqlplus的程式ID,
那麼4716是啥呢?
4716其實是SQLPLUS的執行緒ID,通過工作管理員是看不到這個號的。
為此我寫了一個簡單的小程式,用於獲取指定程式號的執行緒ID列表:
輸入上面的程式ID就可以看到程式14612的執行緒ID是4716.
程式採用DELPHI編寫,原始碼如下,有興趣的朋友可以試試:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
memo1: TMemo;
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses TlHelp32;
procedure TForm1.Button2Click(Sender: TObject);
var
FProcessEntry32: TProcessEntry32;
ProcessID: DWord;
ThreadHandle: THandle;
ThreadStruct: TThreadEntry32;
begin
ProcessID:= strtoint(edit1.Text);
ThreadHandle := CreateToolHelp32Snapshot(TH32CS_SnapThread,ProcessID);
try
ThreadStruct.dwSize := sizeOf(TThreadEntry32);
if Thread32First(ThreadHandle, ThreadStruct) then
repeat
if ThreadStruct.th32OwnerProcessID = ProcessID then
Memo1.Lines.Add(IntTostr(ThreadStruct.th32ThreadID));
until not Thread32Next(ThreadHandle, ThreadStruct);
finally
CloseHandle(ThreadHandle)
end;
end;
end.
14、MACHINE 作業系統機器名、TERMINAL 作業系統終端名
可以根據主terminal查詢客戶端的ip
select utl_inaddr.get_host_address(terminal) from v$session where username is not null;
15、PROGRAM 作業系統程式名
通過本機連線的session,一般都有program。如果是通過伺服器連線的session,一般都沒有program。
16、TYPE 會話型別
一般有兩個型別:background(後臺程式)、user(使用者)
17、SQL_ADDRESS
Used with SQL_HASH_VALUE to identify the SQL statement that is currently being executed
當前正在執行的SQL語句的SQL_HASH_VALUE值
18、SQL_HASH_VALUE
Used with SQL_ADDRESS to identify the SQL statement that is currently being executed
當前正在執行的SQL語句的SQL_ADDRESS值
SQL_HASH_VALUE,SQL_ADDRESS:這兩列用於鑑別預設被session執行的SQL語句。如果為null或0,那就說明這個session沒有執行任何SQL語句。PREV_HASH_VALUE和PREV_ADDRESS兩列用來鑑別被session執行的上一條語句。
19、SQL_ID
SQL identifier of the SQL statement that is currently being executed
正在執行的SQL語句的識別符號
20、SQL_CHILD_NUMBER
Child number of the SQL statement that is currently being executed
21、PREV_SQL_ADDR
Used with PREV_HASH_VALUE to identify the last SQL statement executed
22、PREV_HASH_VALUE
Used with SQL_HASH_VALUE to identify the last SQL statement executed
23、MODULE、ACTION
Name of the currently executing module as set by calling the DBMS_APPLICATION_INFO.SET_MODULE procedure
- session 1:
- SQL> select sid from v$mystat where rownum=1;
- SID
- ----------
- 10
- SQL> create or replace procedure proc1
- 2 as
- 3 begin
- 4 dbms_application_info.set_action('PROC1');
- 5 for i in 1..50 loop
- 6 dbms_lock.sleep(1);
- 7 end loop;
- 8 dbms_application_info.set_action(NULL);
- 9 end;
- 10 /
- Procedure created.
- SQL> create or replace procedure proc2
- 2 as
- 3 begin
- 4 dbms_application_info.set_action('PROC2');
- 5 for i in 1..30 loop
- 6 dbms_lock.sleep(2);
- 7 end loop;
- 8 dbms_application_info.set_action(NULL);
- 9 end;
- 10 /
- Procedure created.
- SQL> create or replace procedure proc_main
- 2 as
- 3 begin
- 4 dbms_application_info.set_module('PROC_MAIN','MAIN');
- 5 dbms_lock.sleep(20);
- 6 proc1;
- 7 proc2;
- 8 dbms_application_info.set_module('PROC_MAIN',NULL);
- 9 end;
- 10 /
- Procedure created.
- SQL> exec proc_main;
- session 2:
- SQL> select sid,serial#,module,action from v$session where sid=10;
- SID SERIAL# MODULE ACTION
- ---------- ---------- ---------- ----------
- 10 26 PROC_MAIN MAIN
- ......
- SQL> select sid,serial#,module,action from v$session where sid=10;
- SID SERIAL# MODULE ACTION
- ---------- ---------- ---------- ----------
- 10 26 PROC_MAIN PROC1
- ......
- SQL> select sid,serial#,module,action from v$session where sid=10;
- SID SERIAL# MODULE ACTION
- ---------- ---------- ---------- ----------
- 10 26 PROC_MAIN PROC2
- ......
- SQL> select sid,serial#,module,action from v$session where sid=10;
- SID SERIAL# MODULE ACTION
- ---------- ---------- ---------- ----------
- 10 26 PROC_MAIN_HASH_VALUE,SQL_ADDRESS
如果是psql登入的也可以看到登入工具:MODULE 為登入工具、或者sqlplus工具,action是sql視窗你正在做的操作
24、MODULE_HASH、ACTION_HASH hash值
25、CLIENT_INFO:還記得SET COMMAND ID命令嗎?該命令設定的值就會在V$SESSION.CLIENT_INFO中體現。
讓我舉個例子說給你們看看的,這個可以找了好長時間的啊。
1)首先,讓我們來設定SET_CLIENT_INFO,這裡我們通過一個觸發器
- SQL> CREATE OR REPLACE TRIGGER trigger_name AFTER LOGON ON DATABASE
- 2 DECLARE
- 3 ipinfo VARCHAR2(30);
- 4 BEGIN
- 5 SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') INTO ipinfo FROM DUAL;
- 6 DBMS_APPLICATION_INFO.SET_CLIENT_INFO(ipinfo);
- 7 END;
- 8 /
- Trigger created
2)這個觸發器的意思能夠看懂吧,通過這個觸發器,讓我一登陸就是知道了
- [oracle@IM-8-201 ~]$ sqlplus test/test
- SQL> select CLIENT_INFO from v$session where username='TEST';
- CLIENT_INFO
- ----------------------------------------------------------------
- 192.168.1.100
26、FIXED_TABLE_SEQUENCE:
當session完成一個user call後就會增加的一個數值,也就是說,如果session inactive,它就不會增加。因此可以根據此欄位的值變化來監控某個時間點以來的session的效能情況。例如,一個小時以前,某個session的FIXED_TABLE_SEQUENCE是10000,而現在是20000,則表明一個小時內其user call比較頻繁,可以重點關注此session的performance statistics。
- SQL> conn sys/sys as sysdba
- Connected.
- SQL> SELECT FIXED_TABLE_SEQUENCE FROM V$SESSION a where a.username='SYS';
- FIXED_TABLE_SEQUENCE
- --------------------
- 3023
- SQL> SELECT FIXED_TABLE_SEQUENCE FROM V$SESSION a where a.username='SYS';
- FIXED_TABLE_SEQUENCE
- --------------------
- 3025
- SQL> SELECT FIXED_TABLE_SEQUENCE FROM V$SESSION a where a.username='SYS';
- FIXED_TABLE_SEQUENCE
- --------------------
- 3027
27、ROW_WAIT_OBJ#
被鎖定行所在table的object_id。和dba_objects中的object_id關聯可以得到被鎖定的table name。
28、ROW_WAIT_FILE#
被鎖定行所在的datafile id。和v$datafile中的file#關聯可以得到datafile name。
29、ROW_WAIT_ROW#
session當前正在等待的被鎖定的行。
30、LOGON_TIME: session logon time
31、LAST_CALL_ET
If the session STATUS is currently ACTIVE, then the value represents the elapsed time in seconds since the session has become active.
If the session STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.
32、PDML_ENABLED This column has been replaced by column PDML_STATUS
既然這麼說,就要先看PDML_STATUS
33、PDML_STATUS
If ENABLED, the session is in a PARALLEL DML enabled mode. If DISABLED, PARALLEL DML enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DML.
PARALLEL :資料並行技術,具體等會兒給連結
34、PDDL_STATUS
If ENABLED, the session is in a PARALLEL DDL enabled mode. If DISABLED, PARALLEL DDL enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL DDL.
這個是針對DDL的
35、PQ_STATUS
If ENABLED, the session is in a PARALLEL QUERY enabled mode. If DISABLED, PARALLEL QUERY enabled mode is not supported for the session. If FORCED, the session has been altered to force PARALLEL QUERY.
這個是針對select的,簡單吧
36、CURRENT_QUEUE_DURATION
If queued (1), the current amount of time the session has been queued. If not currently queued, the value is 0.
if 1則session已經在佇列中,if 0 則還未形成排隊
37、CLIENT_IDENTIFIER
Client identifier of the session
38、BLOCKING_SESSION_STATUS
Blocking session status:
*VALID 狀態valid為正在等待
*NO HOLDER
*GLOBAL
*NOT IN WAIT
*UNKNOWN
發生阻塞時候可以查詢
到了10G,多了blocking_session 和 blocking_session_status欄位,可以知道是否被阻塞。如果blocking_session_status欄位是VALID,那一個有效的SID會出現在blocking_session 欄位。
SQL> select sid, sql_id, PREV_SQL_ID , BLOCKING_SESSION_STATUS , BLOCKING_SESSION ,WAIT_CLASS_ID,SECONDS_IN_WAIT ,WAIT_CLASS from v$session where
2 username='KONG';
SID SQL_ID PREV_SQL_ID BLOCKING_SESSION_STATUS BLOCKING_SESSION WAIT_CLASS_ID SECONDS_IN_WAIT WAIT_CLASS
---------- ------------- ------------- --------------------------------- ---------------- ------------- --------------- ----------------------------------------------------------------
290 0hcsvq77pq2a8 dyk4dprp70d74 VALID 300 4217450380 118 Application
300 0hcsvq77pq2a8 NO HOLDER 2723168908 124 Idle
可以看到290 的程式被300的程式阻塞。
在以前如果想要查詢某個session執行了那個sql語句,那需要用兩個欄位來查詢: HASH_VALUE和ADDRESS。現在只有一個SQL_ID就可以了。
SQL> select sql_text from v$sqltext st, v$session s
2 where (st.sql_id = s.sql_id ) and s.sid=300;
SQL_TEXT
----------------------------------------------------------------
select count(*) from t2
BLOCKING_INSTANCE NUMBER 模組化的例項識別符號
BLOCKING_SESSION NUMBER 模組化的session識別符號
SEQ# NUMBER 不唯一的標示每個等待的序列號
EVENT# NUMBER 事件數量
EVENT VARCHAR2(64) oracle的session正在等待的資料或者事件
P1TEXT VARCHAR2(64) 首個附加引數的描述
P1 NUMBER 首個附加引數
P1RAW RAW(4) 首個附加引數和前一個區別我還不是很懂
P2TEXT VARCHAR2(64) 第二個附加引數的描述
P2 NUMBER 第二個附加引數
P2RAW RAW(4) 第二個附加引數
P3TEXT VARCHAR2(64) 第三個附加引數的描述
P3 NUMBER 第三個附加引數
P3RAW RAW(4) 第三個附加引數
WAIT_CLASS_ID NUMBER 標記等待事件種類
WAIT_CLASS# NUMBER 等待事件的種類
WAIT_CLASS VARCHAR2(64) 等待事件的名稱
WAIT_TIME NUMBER 非0代表上一次session上次等待時間,0代表session當前正在等待
SECONDS_IN_WAIT NUMBER
oracle文件的資料:
If WAIT_TIME = 0, then SECONDS_IN_WAIT is the seconds spent in the
current wait condition. If WAIT_TIME > 0, then SECONDS_IN_WAIT is the
seconds since the start of the last wait, and SECONDS_IN_WAIT - WAIT_
TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19)
oracle資料文件:
Wait state:
■ 0 - WAITING (the session is currently waiting)
■ -2 - WAITED UNKNOWN TIME (duration of last wait is unknown)
■ -1 - WAITED SHORT TIME (last wait <1/100th of a second)
■ >0 - WAITED KNOWN TIME (WAIT_TIME = duration of last wait)
SERVICE_NAME VARCHAR2(64) session的服務名稱
SQL_TRACE VARCHAR2(8) 標示sql是否能被跟蹤
SQL_TRACE_WAITS VARCHAR2(5) 標記是否等待事件被跟蹤
SQL_TRACE_BINDS VARCHAR2(5) 標記是否繫結跟蹤可用與否
------------------------------------------------------------------------------------------------------------------------
v$session
SADDR: session address
SID: session identifier,常用於連線其它列。
SERIAL#: sid 會重用,但是同一個sid被重用時,serial#會增加,不會重複。
AUDSID: audit session id。可以通過audsid查詢當前session的sid。select sid from v$session where audsid=userenv('sessionid');
PADDR: process address,關聯v$process的addr欄位,可以通過這個欄位查處當前session對應作業系統的那個程式的id。
USER#: session's user id。等於dba_users中的user_id。Oracle內部程式的user#為0。
USERNAME: session's username。等於dba_users中的username。Oracle內部程式的username為空。
COMMAND: session正在執行的SQL Id。1代表create table,3代表select。
TADDR: 當前的transaction address。可以用來關聯v$transaction的addr欄位。
LOCKWAIT: 可以通過這個欄位查詢出當前正在等待的鎖的相關資訊。sid & lockwait與v$lock中的sid & kaddr相對應。
STATUS: 用來判斷session狀態。Active:正執行SQL語句。Inactive:等待操作。Killed:被標註為刪除。
SERVER: server type (dedicated or shared)
SCHEMA#: schema user id。Oracle內部程式的schema#為0。
SCHEMANAME: schema username。Oracle內部程式的schemaname為sys。
OSUSER: 客戶端作業系統使用者名稱。
PROCESS: 客戶端process id。
MACHINE: 客戶端machine name。
TERMINAL: 客戶端執行的terminal name。
PROGRAM: 客戶端應用程式。比如ORACLE.EXE (PMON)或者sqlplus.exe
TYPE: session type (background or user)
SQL_ADDRESS, SQL_HASH_VALUE, SQL_ID, SQL_CHILD_NUMBER: session正在執行的sql statement,和v$sql中的address, hash_value, sql_id, child_number相對應。
PREV_SQL_ADDR, PREV_HASH_VALUE, PREV_SQL_ID, PREV_CHILD_NUMBER: 上一次執行的sql statement。
MODULE, MODULE_HASH, ACTION, ACTION_HASH, CLIENT_INFO: 應用通過DBMS_APPLICATION_INFO設定的一些資訊。
FIXED_TABLE_SEQUENCE: 當session完成一個user call後就會增加的一個數值,也就是說,如果session inactive,它就不會增加。因此可以根據此欄位的值變化來監控某個時間點以來的session的效能情況。例如,一個小時以前,某個session的FIXED_TABLE_SEQUENCE是10000,而現在是20000,則表明一個小時內其user call比較頻繁,可以重點關注此session的performance statistics。
ROW_WAIT_OBJ#: 被鎖定行所在table的object_id。和dba_objects中的object_id關聯可以得到被鎖定的table name。
ROW_WAIT_FILE#: 被鎖定行所在的datafile id。和v$datafile中的file#關聯可以得到datafile name。
ROW_WAIT_BLOCK#: Identifier for the block containing the row specified in ROW_WAIT_ROW#
ROW_WAIT_ROW#: session當前正在等待的被鎖定的行。
LOGON_TIME: session logon time
v$process
ADDR: process address。可以和v$session的paddr欄位關聯。
PID: Oracle程式identifier。
SPID: 作業系統程式identifier。
USERNAME: 作業系統程式的使用者名稱。並非Oracle使用者名稱。
SERIAL#:: process serial number。
TERMINAL: 作業系統terminal identifier(e.g., computer name)。
PROGRAM: 程式正在執行的程式(e.g., ORACLE.EXE (ARC0)),和v$session中的program類似。
BACKGROUND: 1代表oracle background process,null代表normal process。
檢視當前使用者的sid和serial#:
select sid, serial#, status from v$session where audsid=userenv('sessionid');
檢視當前使用者的spid:
select spid from v$process p, v$session s where s.audsid=userenv('sessionid') and s.paddr=p.addr;
select spid from v$process p join v$session s on p.addr=s.paddr and s.audsid=userenv('sessionid');
檢視當前使用者的trace file路徑:
select p.value || '/' || t.instance || '_ora_' || ltrim(to_char(p.spid,'fm99999')) || '.trc'
from v$process p, v$session s, v$parameter p, v$thread t
where p.addr = s.paddr and s.audsid = userenv('sessionid') and p.name = 'user_dump_dest';
已知spid,檢視當前正在執行或最近一次執行的語句:
select /*+ ordered */ sql_text from v$sqltext sql
where (sql.hash_value, sql.address) in (
select decode(sql_hash_value, 0, prev_hash_value, sql_hash_value), decode(sql_hash_value, 0, prev_sql_addr, sql_address)
from v$session s where s.paddr = (select addr from v$process p where p.spid = to_number('&pid')))
order by piece asc;
檢視鎖和等待:
col user_name format a10
col owner format a10
col object_name format a15
col sid format 999999
col serial# format 999999
col spid format a6
select /*+ rule */ lpad(' ', decode(l.xidusn, 0, 3, 0)) || l.oracle_username user_name,
o.owner, o.object_name, o.object_type, s.sid, s.serial#, p.spid
from v$locked_object l, dba_objects o, v$session s, v$process p
where l.object_id = o.object_id and l.session_id = s.sid and s.paddr = p.addr
order by o.object_id, xidusn desc;
About Me
.............................................................................................................................................
● 本文作者:小麥苗,只專注於資料庫的技術,更注重技術的運用
● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新
● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/
● 本文部落格園地址:http://www.cnblogs.com/lhrbest
● 本文pdf版、個人簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/
● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/
● DBA寶典今日頭條號地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826
.............................................................................................................................................
● QQ群號:230161599(滿)、618766405
● 微信群:可加我微信,我拉大家進群,非誠勿擾
● 聯絡我請加QQ好友(646634621),註明新增緣由
● 於 2017-07-01 09:00 ~ 2017-07-31 22:00 在魔都完成
● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解
● 版權所有,歡迎分享本文,轉載請保留出處
.............................................................................................................................................
● 小麥苗的微店:https://weidian.com/s/793741433?wfr=c&ifr=shopdetail
● 小麥苗出版的資料庫類叢書:http://blog.itpub.net/26736162/viewspace-2142121/
.............................................................................................................................................
使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公眾號(xiaomaimiaolhr)及QQ群(DBA寶典),學習最實用的資料庫技術。
小麥苗的微信公眾號 小麥苗的DBA寶典QQ群1 小麥苗的DBA寶典QQ群2 小麥苗的微店
.............................................................................................................................................
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2142504/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20211019]V$DETACHED_SESSION檢視.txtSession
- V$ACTIVE_SESSION_HISTORY檢視的使用Session
- [20211214]檢視檢視V$ACTIVE_SESSION_HISTORY遇到奇怪問題.txtSession
- 在檢視中使用會話會話
- Cassandra的Session會話Session會話
- 會話技術之 Session會話Session
- 會話層技術-session會話Session
- 10、flask-會話-sessionFlask會話Session
- 瀏覽器檢視Session瀏覽器Session
- 檢視瀏覽器請求的session 瀏覽器怎麼檢視session瀏覽器Session
- Windows檢視登入使用者會話Windows會話
- 檢視當前pg會話連線數會話
- session檢視中wait_timeSessionAI
- ZooKeeper如何模擬會話失效(Session Expired)會話Session
- 令牌Token和會話Session原理與攻略會話Session
- MQTT 持久會話與 Clean Session 詳解MQQT會話Session
- 次世代的會話管理專案 Spring Session會話SpringSession
- nodejs學習08——會話控制 session cookie tokenNodeJS會話SessionCookie
- oracle 會話(session)被鎖瞭解決方法Oracle會話Session
- [20221130]測試訪問檢視v$session幾種情況的效能差異.txtSession
- session和v$session說明Session
- 10.17 V$SESSIONSession
- V$SESSION COMMANDSession
- 檢視V$DATAGUARD_STATS
- 巨杉核心筆記(一)| SequoiaDB 會話(session)簡介筆記會話Session
- python+pytest介面自動化(10)-session會話保持PythonSession會話
- v$Session詳解Session
- 使用dbms_monitor.session_trace_enable跟蹤一個會話Session會話
- PHP 會話(Session)如何實現使用者登陸功能PHP會話Session
- Oracle檢視已被使用的open_cursors&session_cached_cursorsOracleSession
- CWE-384: Session Fixation 會話固定漏洞有哪些修補方法?Session會話
- 10.18 V$SESSION_BLOCKERSSessionBloC
- 10.21 V$SESSION_EVENTSession
- 10.25 V$SESSION_WAITSessionAI
- 會話和鎖資訊查詢檢視 | 全方位認識 sys 系統庫會話
- [20210528]V$INDEXED_FIXED_COLUMN檢視.txtIndex
- [20210418]查詢v$檢視問題.txt
- 10.27 V$SESSION_WAIT_HISTORYSessionAI
- 10.26 V$SESSION_WAIT_CLASSSessionAI