【会话】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;
PO OLED和Oracle 11g推出的驻留连接池(Database Resident Connection Pool)特性相关,驻留连接池提供了数据库层面上的连接池管理机制,为应对高并发、短会话前端应用进行有益的尝试, PO OLED表示使用驻留连接池技术的连接;
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
- >
- >
- >
- >
- >
- >
- >
- >
- >
- >
- >
- >
- >
- >
- >
>
>
>
<
>
&&
&