v$session中存放了每个连接到数据库实例的信息,包括oracle的一些后台信息。
下列各列提供session的信息,可被用于当一个或多个combination未知时找到session。
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中设置
下列V$SESSION列同样可能会被用到:
ROW_WAIT_OBJ#
ROW_WAIT_FILE#
ROW_WAIT_BLOCK#
ROW_WAIT_ROW#
sql示例:
查询自己的session的信息
SQL> select sid,username from v$session where audsid=userenv('SESSIONID');
SID USERNAME
---------- ------------------------------
101 SYSTEM
查找当前被某个指定session正在运行的sql语句。假设sessionID为101
SQL> select b.sql_text from v$session a,v$sqlarea b where a.sql_hash_value=b.hash_value and a.sid=101;
SQL_TEXT
--------------------------------------------------------------------------------
select b.sql_text from v$session a,v$sqlarea b where a.sql_hash_value=b.hash_val
查看某个进程正在执行什么SQL语句
SQL> select b.sql_text,sid,serial#,osuser,machine from v$session a,v$sqlarea b where a.sql_address=b.address;
SQL_TEXT SID SERIAL# OSUSER MACHINE
-------------------------------------------------------------------------------- ---------- ---------- ------------------------------ ----------------------------------------------------------------
BEGIN EMD_NOTIFICATION.QUEUE_READY(:1, :2, :3); END; 101 1 WIN-5L5F4OLF2L5$ WIN-5L5F4OLF2L5
insert into sys_log values(:1,:2,:3,:4,:5,:6,:7) 167 34 Administrator WIN-JI9BIRR8V0I
insert into sys_log values(:1,:2,:3,:4,:5,:6,:7) 190 11 Administrator WIN-JI9BIRR8V0I
insert into Sys_Log("UID",Name,Item,intime,SessionID,IP,id) values(:1,:2,:3,:4,: 145 4383 Administrator WIN-JI9BIRR8V0I
insert into Sys_Log("UID",Name,Item,intime,SessionID,IP,id) values(:1,:2,:3,:4,: 232 20972 Administrator WIN-JI9BIRR8V0I
select b.sql_text,sid,serial#,osuser,machine from v$session a,v$sqlarea b where 80 14962 ThinkPad WORKGROUP\T410-PC
6 rows selected
--查询前台发出的SQL语句.SQL
SQL> select user_name,sql_text
2 from v$open_cursor
3 where sid in (select sid from (select sid,serial#,username,program from v$session where status='ACTIVE'));
USER_NAME SQL_TEXT
------------------------------ ------------------------------------------------------------
SYS table_4_9_13f5_0_0_0
SYSTEM select length(chr(2000000000)) l4, length(chr(2000000)) l3,
SYS select streams_pool_size_for_estimate s, streams_p
SYS select col#,intcol#,reftyp,stabid,expctoid from refcon$ wher
SYS select timestamp, flags from fixed_obj$ where obj#=:1
SYS select next_run_date, obj#, run_job, sch_job from (select de
This view lists session information for each current session.
Column | Datatype | Description |
---|---|---|
SADDR | RAW(4 | 8) | Session address |
SID | NUMBER | Session identifier |
SERIAL# | NUMBER | 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. |
AUDSID | NUMBER | Auditing session ID |
PADDR | RAW(4 | 8) | Address of the process that owns the session |
USER# | NUMBER | Oracle user identifier |
USERNAME | VARCHAR2(30) | Oracle username |
COMMAND | NUMBER | Command in progress (last statement parsed); for a list of values, see Table 7-5. These values also appear in the AUDIT_ACTIONS table. |
OWNERID | NUMBER | The 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. |
TADDR | VARCHAR2(8) | Address of transaction state object |
LOCKWAIT | VARCHAR2(8) | Address of lock waiting for; null if none |
STATUS | VARCHAR2(8) | Status of the session:
|
SERVER | VARCHAR2(9) | Server type (DEDICATED | SHARED | PSEUDO | NONE ) |
SCHEMA# | NUMBER | Schema user identifier |
SCHEMANAME | VARCHAR2(30) | Schema user name |
OSUSER | VARCHAR2(30) | Operating system client user name |
PROCESS | VARCHAR2(12) | Operating system client process ID |
MACHINE | VARCHAR2(64) | Operating system machine name |
TERMINAL | VARCHAR2(30) | Operating system terminal name |
PROGRAM | VARCHAR2(48) | Operating system program name |
TYPE | VARCHAR2(10) | Session type |
SQL_ADDRESS | RAW(4 | 8) | Used with SQL_HASH_VALUE to identify the SQL statement that is currently being executed |
SQL_HASH_VALUE | NUMBER | Used with SQL_ADDRESS to identify the SQL statement that is currently being executed |
SQL_ID | VARCHAR2(13) | SQL identifier of the SQL statement that is currently being executed |
SQL_CHILD_NUMBER | NUMBER | Child number of the SQL statement that is currently being executed |
PREV_SQL_ADDR | RAW(4 | 8) | Used with PREV_HASH_VALUE to identify the last SQL statement executed |
PREV_HASH_VALUE | NUMBER | Used with SQL_HASH_VALUE to identify the last SQL statement executed |
PREV_SQL_ID | VARCHAR2(13) | SQL identifier of the last SQL statement executed |
PREV_CHILD_NUMBER | NUMBER | Child number of the last SQL statement executed |
MODULE | VARCHAR2(48) | Name of the currently executing module as set by calling the DBMS_APPLICATION_INFO.SET_MODULE procedure |
MODULE_HASH | NUMBER | Hash value of the above MODULE |
ACTION | VARCHAR2(32) | Name of the currently executing action as set by calling the DBMS_APPLICATION_INFO.SET_ACTION procedure |
ACTION_HASH | NUMBER | Hash value of the above action name |
CLIENT_INFO | VARCHAR2(64) | Information set by the DBMS_APPLICATION_INFO.SET_CLIENT_INFO procedure |
FIXED_TABLE_SEQUENCE | NUMBER | 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. |
ROW_WAIT_OBJ# | NUMBER | Object ID for the table containing the row specified in ROW_WAIT_ROW# |
ROW_WAIT_FILE# | NUMBER | 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 . |
ROW_WAIT_BLOCK# | NUMBER | 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 . |
ROW_WAIT_ROW# | NUMBER | 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 . |
LOGON_TIME | DATE | Time of logon |
LAST_CALL_ET | NUMBER | 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 |
PDML_ENABLED | VARCHAR2(3) | This column has been replaced by column PDML_STATUS |
FAILOVER_TYPE | VARCHAR2(13) | Indicates whether and to what extent transparent application failover (TAF) is enabled for the session:
See Also:
|
FAILOVER_METHOD | VARCHAR2(10) | Indicates the transparent application failover method for the session:
|
FAILED_OVER | VARCHAR2(3) | Indicates whether the session is running in failover mode and failover has occurred (YES ) or not (NO ) |
RESOURCE_CONSUMER_GROUP | VARCHAR2(32) | Name of the session's current resource consumer group |
PDML_STATUS | VARCHAR2(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_STATUS | VARCHAR2(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_STATUS | VARCHAR2(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_DURATION | NUMBER | If queued (1 ), the current amount of time the session has been queued. If not currently queued, the value is 0 . |
CLIENT_IDENTIFIER | VARCHAR2(64) | Client identifier of the session |
BLOCKING_SESSION_STATUS | VARCHAR2(11) | Blocking session status:
|
BLOCKING_INSTANCE | NUMBER | Instance identifier of blocking session |
BLOCKING_SESSION | NUMBER | Session identifier of blocking session |
SEQ# | NUMBER | Sequence number that uniquely identifies the wait. Incremented for each wait. |
EVENT# | NUMBER | Event number |
EVENT | VARCHAR2(64) | Resource or event for which the session is waiting See Also: Appendix C, "Oracle Wait Events" |
P1TEXT | VARCHAR2(64) | Description of the first additional parameter |
P1 | NUMBER | First additional parameter |
P1RAW | RAW(4) | First additional parameter |
P2TEXT | VARCHAR2(64) | Description of the second additional parameter |
P2 | NUMBER | Second additional parameter |
P2RAW | RAW(4) | Second additional parameter |
P3TEXT | VARCHAR2(64) | Description of the third additional parameter |
P3 | NUMBER | Third additional parameter |
P3RAW | RAW(4) | Third additional parameter |
WAIT_CLASS_ID | NUMBER | Identifier of the wait class |
WAIT_CLASS# | NUMBER | Number of the wait class |
WAIT_CLASS | VARCHAR2(64) | Name of the wait class |
WAIT_TIME | NUMBER | A nonzero value is the session's last wait time. A zero value means the session is currently waiting. |
SECONDS_IN_WAIT | NUMBER | 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) | Wait state:
|
SERVICE_NAME | VARCHAR2(64) | Service name of the session |
SQL_TRACE | VARCHAR2(8) | Indicates whether SQL tracing is enabled (ENABLED ) or disabled (DISABLED ) |
SQL_TRACE_WAITS | VARCHAR2(5) | Indicates whether wait tracing is enabled (TRUE ) or not (FALSE ) |
SQL_TRACE_BINDS | VARCHAR2(5) | Indicates whether bind tracing is enabled (TRUE ) or not (FALSE ) |
Table 7-5 COMMAND Column of V$SESSION and Corresponding Commands
Number | Command | Number | Command |
---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|