Oracle 动态视图3 V$SESSION

  每一个连接到数据库实例中的session都拥有一条记录。包括用户session及后台进程如DBWR,LGWR,arcchiver等

 

ColumnDatatypeDescription
SADDRRAW(4 | 8)Session address
SIDNUMBERSession identifier
SERIAL#NUMBER同一个sid被重用时,serial#会增加
AUDSIDNUMBERAuditing session ID
PADDRRAW(4 | 8)关联v$processaddr字段,可以通过这个字段查处当前session对应操作系统的进程的id
USER#NUMBER等于dba_users中的user_idOracle内部进程的user#0
USERNAMEVARCHAR2(30)等于dba_users中的usernameOracle内部进程的username为空
COMMANDNUMBERsession正在执行的SQL ID1代表create table3代表select
OWNERIDNUMBERThe column contents are invalid if the value is 2147483644. Otherwise, this column contains the identifier of the user who owns the migratable session.
 
For operations using Parallel Slaves, interpret this value as a 4-byte value. The low-order 2 bytes of which represent the session number, and the high-order bytes the instance ID of the query coordinator.
TADDRVARCHAR2(8)当前的transaction address。可以用来关联v$transactionaddr字段
LOCKWAITVARCHAR2(8)可以通过这个字段查询出当前正在等待的锁的相关信息。sid & lockwaitv$lock中的sid & kaddr相对应
STATUSVARCHAR2(8)用来判断session状态。Active:正执行SQL语句。Inactive:等待操作。Killed:被标注为删除
SERVERVARCHAR2(9)Server type (DEDICATEDSHAREDPSEUDONONE)
SCHEMA#NUMBERschema user idOracle内部进程的schema#0
SCHEMANAMEVARCHAR2(30)schema usernameOracle内部进程的schemanamesys
OSUSERVARCHAR2(30)客户端操作系统用户名
PROCESSVARCHAR2(12)客户端process id
MACHINEVARCHAR2(64)客户端machine name
TERMINALVARCHAR2(30)客户端执行的terminal name
PROGRAMVARCHAR2(48)客户端应用程序。比如ORACLE.EXE (PMON)或者sqlplus.exe
TYPEVARCHAR2(10)session type (background or user)
SQL_ADDRESSRAW(4 | 8)session正在执行的sql statement,和v$sql中的address, hash_value, sql_id, child_number相对应
SQL_HASH_VALUENUMBER
SQL_IDVARCHAR2(13)
SQL_CHILD_NUMBERNUMBER
PREV_SQL_ADDRRAW(4 | 8)上一次执行的sql statement
PREV_HASH_VALUENUMBER
PREV_SQL_IDVARCHAR2(13)
PREV_CHILD_NUMBERNUMBER
FIXED_TABLE_SEQUENCENUMBERsession完成一个user call后就会增加的一个数值,也就是说,如果session inactive,它就不会增加。因此可以根据此字段的值变化来监控某个时间点以来的session的性能情况。例如,一个小时以前,某个sessionFIXED_TABLE_SEQUENCE10000,而现在是20000,则表明一个小时内其user call比较频繁,可以重点关注此sessionperformance statistics
ROW_WAIT_OBJ#NUMBER被锁定行所在tableobject_id。和dba_objects中的object_id关联可以得到被锁定的table name
ROW_WAIT_FILE#NUMBER被锁定行所在的datafile id。和v$datafile中的file#关联可以得到datafile name
ROW_WAIT_BLOCK#NUMBERIdentifier 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.
ROW_WAIT_ROW#NUMBERsession当前正在等待的被锁定的行
LOGON_TIMEDATETime of logon
LAST_CALL_ETNUMBERIf 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.
PDML_ENABLEDVARCHAR2(3)This column has been replaced by column PDML_STATUS
FAILOVER_TYPEVARCHAR2(13)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
 
FAILOVER_METHODVARCHAR2(10)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
 
FAILED_OVERVARCHAR2(3)Indicates whether the session is running in failover mode and failover has occurred (YES) or not (NO)
RESOURCE_CONSUMER_GROUPVARCHAR2(32)Name of the session's current resource consumer group
PDML_STATUSVARCHAR2(8)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.
PDDL_STATUSVARCHAR2(8)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.
PQ_STATUSVARCHAR2(8)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.
CURRENT_QUEUE_DURATIONNUMBERIf queued (1), the current amount of time the session has been queued. If not currently queued, the value is 0.
CLIENT_IDENTIFIERVARCHAR2(64)Client identifier of the session
BLOCKING_SESSION_STATUSVARCHAR2(11)Blocking session status:
 
VALID
NO HOLDER
GLOBAL
NOT IN WAIT
UNKNOWN
 
BLOCKING_INSTANCENUMBERInstance identifier of blocking session
BLOCKING_SESSIONNUMBERSession identifier of blocking session
SEQ#NUMBERSequence number that uniquely identifies the wait. Incremented for each wait.
EVENT#NUMBEREvent number
EVENTVARCHAR2(64)Resource or event for which the session is waiting
P1TEXTVARCHAR2(64)Description of the first additional parameter
P1NUMBERFirst additional parameter
P1RAWRAW(4)First additional parameter
P2TEXTVARCHAR2(64)Description of the second additional parameter
P2NUMBERSecond additional parameter
P2RAWRAW(4)Second additional parameter
P3TEXTVARCHAR2(64)Description of the third additional parameter
P3NUMBERThird additional parameter
P3RAWRAW(4)Third additional parameter
WAIT_CLASS_IDNUMBERIdentifier of the wait class
WAIT_CLASS#NUMBERNumber of the wait class
WAIT_CLASSVARCHAR2(64)Name of the wait class
WAIT_TIMENUMBERWAIT_TIME <> 0  上次实际等待时间;WAIT_TIME=0  session正在等待当前的事件
SECONDS_IN_WAITNUMBERWAIT_TIME=0  SECONDS_IN_WAIT是在当前等待条件下的等待时间;
WAIT_TIME>0  SECONDS_IN_WAIT是指从上次等待的起始时间到当前时间,SECONDS_IN_WAIT - WAIT_TIME /100 是从上次等待结束时间点到当前时间(即活动时间)
STATEVARCHAR2(19)Wait state:参照WAIT_TIMESECONDS_IN_WAIT字段
 
0 - WAITING (session正在等待当前的事件)
-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 = 上次实际等待时间)
SERVICE_NAMEVARCHAR2(64)Service name of the session
SQL_TRACEVARCHAR2(8)Indicates whether SQL tracing is enabled (ENABLED) or disabled (DISABLED)
SQL_TRACE_WAITSVARCHAR2(5)Indicates whether wait tracing is enabled (TRUE) or not (FALSE)
SQL_TRACE_BINDSVARCHAR2(5)Indicates whether bind tracing is enabled (TRUE) or not (FALSE)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Session的信息:
SID:SESSION标识,常用于连接其它列
SERIAL#:如果某个SID又被其它的session使用的话则此数值自增加(当一个 SESSION结束,另一个SESSION开始并使用了同一个SID)。
AUDSID:审查session ID唯一性,确认它通常也用于当寻找并行查询模式
USERNAME:当前session在oracle中的用户名。

Client信息:
数据库session被一个运行在数据库服务器上或从中间服务器甚至桌面通过SQL*Net连接到数据库的客户端进程启动,下列各列提供这个客户端的信息
OSUSER:客户端操作系统用户名
MACHINE:客户端执行的机器
TERMINAL:客户端运行的终端
PROCESS:客户端进程的ID
PROGRAM:客户端执行的客户端程序
要显示用户所连接PC的 TERMINAL、OSUSER,需在该PC的ORACLE.INI或Windows中设置关键字TERMINAL,USERNAME。

Application信息:
调用DBMS_APPLICATION_INFO包以设置一些信息区分用户。这将显示下列各列。
CLIENT_INFO:DBMS_APPLICATION_INFO中设置
ACTION:DBMS_APPLICATION_INFO中设置
MODULE:DBMS_APPLICATION_INFO中设置

 

示例:

 1 1.查找你的session信息
 2 SQL> SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
 3   2  FROM V$SESSION WHERE audsid = userenv('SESSIONID');
 4 
 5        SID OSUSER     USERNAME   MACHINE         PROCESS
 6 ---------- ---------- ---------- --------------- ------------
 7        134 oracle     SYS        mysolaris       10100
 8        159 Administra SYS        WORKGROUP\THINK 4996:5088
 9 
10 2.当machine已知的情况下查找session
11 SQL> SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
12   2  FROM V$SESSION
13   3  WHERE machine = 'mysolaris';
14 
15        SID OSUSER     USERNAME   MACHINE         TERMINAL
16 ---------- ---------- ---------- --------------- ------------------------------
17        131 oracle                mysolaris       UNKNOWN
18        134 oracle     SYS        mysolaris       pts/2
19        137 oracle                mysolaris       UNKNOWN
20        138 oracle                mysolaris       UNKNOWN
21        141 oracle                mysolaris       UNKNOWN
22        144 oracle                mysolaris       UNKNOWN
23        150 oracle                mysolaris       UNKNOWN
24        151 oracle                mysolaris       UNKNOWN
25        156 oracle                mysolaris       UNKNOWN
26        157 oracle                mysolaris       UNKNOWN
27        160 oracle                mysolaris       UNKNOWN
28 
29        SID OSUSER     USERNAME   MACHINE         TERMINAL
30 ---------- ---------- ---------- --------------- ------------------------------
31        161 oracle                mysolaris       UNKNOWN
32        162 oracle                mysolaris       UNKNOWN
33        163 oracle                mysolaris       UNKNOWN
34        164 oracle                mysolaris       UNKNOWN
35        165 oracle                mysolaris       UNKNOWN
36        166 oracle                mysolaris       UNKNOWN
37        167 oracle                mysolaris       UNKNOWN
38        168 oracle                mysolaris       UNKNOWN
39        169 oracle                mysolaris       UNKNOWN
40        170 oracle                mysolaris       UNKNOWN
41 
42 21 rows selected.
43 
44 SQL> 

  V$SESSION是基础视图,常常同其他视图协同工作,如:v$lock,v$sqlarea,v$sqltext等

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值