V$session 和V$process

简介:

V$SESSION

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:
  • 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

SERVER VARCHAR2(9) Server type (DEDICATEDSHAREDPSEUDONONE)
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 theDBMS_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 theDBMS_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 ofROW_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 ofROW_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 STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

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:
  • 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:

FAILOVER_METHOD VARCHAR2(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_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:
  • VALID

  • NO HOLDER

  • GLOBAL

  • NOT IN WAIT

  • UNKNOWN

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. IfWAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, andSECONDS_IN_WAIT - WAIT_TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19) 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) 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)

 

 

 

 

V$PROCESS

This view contains information about the currently active processes. While the LATCHWAIT column indicates what latch a process is waiting for, the LATCHSPINcolumn indicates what latch a process is spinning on. On multi-processor machines, Oracle processes will spin on a latch before waiting on it.

Column Datatype Description
ADDR RAW(4 | 8) Address of process state object
PID NUMBER Oracle process identifier
SPID VARCHAR2(12) Operating system process identifier
USERNAME VARCHAR2(15) Operating system process username. Any two-task user coming across the network has "-T" appended to the username.
SERIAL# NUMBER Process serial number
TERMINAL VARCHAR2(30) Operating system terminal identifier
PROGRAM VARCHAR2(48) Program in progress
TRACEID VARCHAR2(255) Trace file identifier
BACKGROUND VARCHAR2(1) 1 for a background process; NULL for a normal process
LATCHWAIT VARCHAR2(8) Address of latch the process is waiting for; NULL if none
LATCHSPIN VARCHAR2(8) Address of the latch the process is spinning on; NULL if none
PGA_USED_MEM NUMBER PGA memory currently used by the process
PGA_ALLOC_MEM NUMBER PGA memory currently allocated by the process (including free PGA memory not yet released to the operating system by the server process)
PGA_FREEABLE_MEM NUMBER Allocated PGA memory which can be freed
PGA_MAX_MEM NUMBER Maximum PGA memory ever allocated by the process

 

 

V$SESSION中的常用列

V$SESSION是基础信息视图,用于找寻用户SID或SADDR。不过,它也有一些列会动态的变化,可用于检查用户。如例:
SQL_HASH_VALUE,SQL_ADDRESS:这两列用于鉴别默认被session执行的SQL语句。如果为null或0,那就说明这个session没有执行任何SQL语句。PREV_HASH_VALUE和PREV_ADDRESS两列用来鉴别被session执行的上一条语句。

注意:当使用SQL*Plus进行选择时,确认你重定义的列宽不小于11以便看到完整的数值。

STATUS:这列用来判断session状态是:
Achtive:正执行SQL语句(waiting for/using a resource)
Inactive:等待操作(即等待需要执行的SQL语句)
Killed:被标注为删除

下列各列提供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#

V$SESSION中的连接列

Column View Joined Column(s) 
SID V$SESSION_WAIT,,V$SESSTAT,,V$LOCK,V$SESSION_EVENT,V$OPEN_CURSOR SID
(SQL_HASH_VALUE, SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
(PREV_HASH_VALUE, PREV_SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
TADDR V$TRANSACTION ADDR
PADDR V$PROCESS ADDR

 

示例:
1.查找你的session信息
SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
FROM V$SESSION WHERE audsid = userenv('SESSIONID');

2.当machine已知的情况下查找session
SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
FROM V$SESSION
WHERE terminal = 'pts/tl' AND machine = 'rgmdbs1';

查找当前被某个指定session正在运行的sql语句。假设sessionID为100
select b.sql_text 
from v$session a,v$sqlarea b 
where a.sql_hash_value=b.hash_value and a.sid=100
寻找被指定session执行的SQL语句是一个公共需求,如果session是瓶颈的主要原因,那根据其当前在执行的语句可以查看session在做些什么。

 

.如果数据库瓶颈是系统资源(如:cpu,内存),并且占用资源最多的用户总是停留在某几个服务进程,那么进行如下诸项:

1>.找出资源进程
2>.找出它们的session,你必须将进程与会话联系起来。
3>.找出为什么session占用了如此多的资源

2.SQL跟踪文件名是基于服务进程的操作系统进程ID。要找出session的跟踪文件,你必须将session与服务进程联系起来。
3.某些事件,如rdbms ipc reply,鉴别session进程的Oracle进程ID在等什么。要发现这些进程在做什么,你必须找出它们的session。
4.你所看到的服务器上的后台进程(DBWR,LGWR,PMON等)都是服务进程。要想知道他们在做什么,你必须找到他们的session。

V$PROCESS中的常用列
ADDR:进程对象地址
PID:oracle进程ID
SPID:操作系统进程ID

V$PROCESS中的连接列
Column View Joined Column(s) 
ADDR V$SESSION PADDR

示例:
1.查找指定系统用户在oracle中的session信息及进程id,假设操作系统用户为:junsansi
select s.sid,s.SERIAL#, s.username,p.spid
from v$session s, v$process p
where s.osuser = 'junsansi'
and s.PADDR = p.ADDR

2.查看锁和等待
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

附注:
在linux环境可以通过ps查看进程信息包括pid,windows中任务管理器的PID与v$process中pid不能一一对应,这块在oracleDocument中也没有找到介绍,后来google了一下,有资料介绍说是由于windows是多线程服务器,每个进程包含一系列线程。这点于unix等不同,Unix每个Oralce进程独立存在,在Nt上所有线程由Oralce进程衍生。
要在windows中显示oracle相关进程pid,我们可以通过一个简单的sql语句来实现。
SELECT s.SID, p.pid, p.spid signaled, s.osuser, s.program
FROM v$process p, v$session s
WHERE p.addr = s.paddr;

SID PID SIGNALED OSUSER PROGRAM 
1 2 2452 SYSTEM ORACLE.EXE 
2 3 2460 SYSTEM ORACLE.EXE 
3 4 2472 SYSTEM ORACLE.EXE 
4 5 2492 SYSTEM ORACLE.EXE 
5 6 2496 SYSTEM ORACLE.EXE 
6 7 2508 SYSTEM ORACLE.EXE 
7 8 2520 SYSTEM ORACLE.EXE 
8 9 2524 SYSTEM ORACLE.EXE 
10 12 1316 JSSjunsansi PlSqlDev.exe 
9 13 3420 JSSjunsansi PlSqlDev.exe 
13 14 660 JSSjunsansi PlSqlDev.exe

还可以通过和 v$bgprocess 连接查询到后台进程的名字: 
SELECT s.SID SID, p.spid threadid, p.program processname, bg.NAME NAME
FROM v$process p, v$session s, v$bgprocess bg
WHERE p.addr = s.paddr
AND p.addr = bg.paddr
AND bg.paddr <> '00';

SID THREADID PROCESSNAME NAME 
1 2452 ORACLE.EXE PMON 
2 2460 ORACLE.EXE DBW0 
3 2472 ORACLE.EXE LGWR 
4 2492 ORACLE.EXE CKPT 
5 2496 ORACLE.EXE SMON 
6 2508 ORACLE.EXE RECO 
7 2520 ORACLE.EXE CJQ0 
8 2524 ORACLE.EXE QMN0

Eygle大师写了一段sql脚本getsql.sql,用来获取指定pid正在执行的sql语句,在此也附注上来。
REM getsql.sql
REM author eygle
REM 在windows上,已知进程ID,得到当前正在执行的语句
REM 在windows上,进程ID为16进制,需要转换,在UNIX直接为10进制
SELECT /*+ ORDERED */
sql_text
FROM v$sqltext a
WHERE (a.hash_value, a.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 b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))
ORDER BY piece ASC

 

http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2088.htm

http://junsansi.itpub.net/post/29894/292372

 

 

V$SESSION

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:
  • 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

SERVER VARCHAR2(9) Server type (DEDICATEDSHAREDPSEUDONONE)
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 theDBMS_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 theDBMS_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 ofROW_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 ofROW_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 STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

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:
  • 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:

FAILOVER_METHOD VARCHAR2(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_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:
  • VALID

  • NO HOLDER

  • GLOBAL

  • NOT IN WAIT

  • UNKNOWN

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. IfWAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, andSECONDS_IN_WAIT - WAIT_TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19) 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) 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)

 

 

 

 

V$PROCESS

This view contains information about the currently active processes. While the LATCHWAIT column indicates what latch a process is waiting for, the LATCHSPINcolumn indicates what latch a process is spinning on. On multi-processor machines, Oracle processes will spin on a latch before waiting on it.

Column Datatype Description
ADDR RAW(4 | 8) Address of process state object
PID NUMBER Oracle process identifier
SPID VARCHAR2(12) Operating system process identifier
USERNAME VARCHAR2(15) Operating system process username. Any two-task user coming across the network has "-T" appended to the username.
SERIAL# NUMBER Process serial number
TERMINAL VARCHAR2(30) Operating system terminal identifier
PROGRAM VARCHAR2(48) Program in progress
TRACEID VARCHAR2(255) Trace file identifier
BACKGROUND VARCHAR2(1) 1 for a background process; NULL for a normal process
LATCHWAIT VARCHAR2(8) Address of latch the process is waiting for; NULL if none
LATCHSPIN VARCHAR2(8) Address of the latch the process is spinning on; NULL if none
PGA_USED_MEM NUMBER PGA memory currently used by the process
PGA_ALLOC_MEM NUMBER PGA memory currently allocated by the process (including free PGA memory not yet released to the operating system by the server process)
PGA_FREEABLE_MEM NUMBER Allocated PGA memory which can be freed
PGA_MAX_MEM NUMBER Maximum PGA memory ever allocated by the process

 

 

V$SESSION中的常用列

V$SESSION是基础信息视图,用于找寻用户SID或SADDR。不过,它也有一些列会动态的变化,可用于检查用户。如例:
SQL_HASH_VALUE,SQL_ADDRESS:这两列用于鉴别默认被session执行的SQL语句。如果为null或0,那就说明这个session没有执行任何SQL语句。PREV_HASH_VALUE和PREV_ADDRESS两列用来鉴别被session执行的上一条语句。

注意:当使用SQL*Plus进行选择时,确认你重定义的列宽不小于11以便看到完整的数值。

STATUS:这列用来判断session状态是:
Achtive:正执行SQL语句(waiting for/using a resource)
Inactive:等待操作(即等待需要执行的SQL语句)
Killed:被标注为删除

下列各列提供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#

V$SESSION中的连接列

Column View Joined Column(s) 
SID V$SESSION_WAIT,,V$SESSTAT,,V$LOCK,V$SESSION_EVENT,V$OPEN_CURSOR SID
(SQL_HASH_VALUE, SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
(PREV_HASH_VALUE, PREV_SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
TADDR V$TRANSACTION ADDR
PADDR V$PROCESS ADDR

 

示例:
1.查找你的session信息
SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
FROM V$SESSION WHERE audsid = userenv('SESSIONID');

2.当machine已知的情况下查找session
SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
FROM V$SESSION
WHERE terminal = 'pts/tl' AND machine = 'rgmdbs1';

查找当前被某个指定session正在运行的sql语句。假设sessionID为100
select b.sql_text 
from v$session a,v$sqlarea b 
where a.sql_hash_value=b.hash_value and a.sid=100
寻找被指定session执行的SQL语句是一个公共需求,如果session是瓶颈的主要原因,那根据其当前在执行的语句可以查看session在做些什么。

 

.如果数据库瓶颈是系统资源(如:cpu,内存),并且占用资源最多的用户总是停留在某几个服务进程,那么进行如下诸项:

1>.找出资源进程
2>.找出它们的session,你必须将进程与会话联系起来。
3>.找出为什么session占用了如此多的资源

2.SQL跟踪文件名是基于服务进程的操作系统进程ID。要找出session的跟踪文件,你必须将session与服务进程联系起来。
3.某些事件,如rdbms ipc reply,鉴别session进程的Oracle进程ID在等什么。要发现这些进程在做什么,你必须找出它们的session。
4.你所看到的服务器上的后台进程(DBWR,LGWR,PMON等)都是服务进程。要想知道他们在做什么,你必须找到他们的session。

V$PROCESS中的常用列
ADDR:进程对象地址
PID:oracle进程ID
SPID:操作系统进程ID

V$PROCESS中的连接列
Column View Joined Column(s) 
ADDR V$SESSION PADDR

示例:
1.查找指定系统用户在oracle中的session信息及进程id,假设操作系统用户为:junsansi
select s.sid,s.SERIAL#, s.username,p.spid
from v$session s, v$process p
where s.osuser = 'junsansi'
and s.PADDR = p.ADDR

2.查看锁和等待
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

附注:
在linux环境可以通过ps查看进程信息包括pid,windows中任务管理器的PID与v$process中pid不能一一对应,这块在oracleDocument中也没有找到介绍,后来google了一下,有资料介绍说是由于windows是多线程服务器,每个进程包含一系列线程。这点于unix等不同,Unix每个Oralce进程独立存在,在Nt上所有线程由Oralce进程衍生。
要在windows中显示oracle相关进程pid,我们可以通过一个简单的sql语句来实现。
SELECT s.SID, p.pid, p.spid signaled, s.osuser, s.program
FROM v$process p, v$session s
WHERE p.addr = s.paddr;

SID PID SIGNALED OSUSER PROGRAM 
1 2 2452 SYSTEM ORACLE.EXE 
2 3 2460 SYSTEM ORACLE.EXE 
3 4 2472 SYSTEM ORACLE.EXE 
4 5 2492 SYSTEM ORACLE.EXE 
5 6 2496 SYSTEM ORACLE.EXE 
6 7 2508 SYSTEM ORACLE.EXE 
7 8 2520 SYSTEM ORACLE.EXE 
8 9 2524 SYSTEM ORACLE.EXE 
10 12 1316 JSSjunsansi PlSqlDev.exe 
9 13 3420 JSSjunsansi PlSqlDev.exe 
13 14 660 JSSjunsansi PlSqlDev.exe

还可以通过和 v$bgprocess 连接查询到后台进程的名字: 
SELECT s.SID SID, p.spid threadid, p.program processname, bg.NAME NAME
FROM v$process p, v$session s, v$bgprocess bg
WHERE p.addr = s.paddr
AND p.addr = bg.paddr
AND bg.paddr <> '00';

SID THREADID PROCESSNAME NAME 
1 2452 ORACLE.EXE PMON 
2 2460 ORACLE.EXE DBW0 
3 2472 ORACLE.EXE LGWR 
4 2492 ORACLE.EXE CKPT 
5 2496 ORACLE.EXE SMON 
6 2508 ORACLE.EXE RECO 
7 2520 ORACLE.EXE CJQ0 
8 2524 ORACLE.EXE QMN0

Eygle大师写了一段sql脚本getsql.sql,用来获取指定pid正在执行的sql语句,在此也附注上来。
REM getsql.sql
REM author eygle
REM 在windows上,已知进程ID,得到当前正在执行的语句
REM 在windows上,进程ID为16进制,需要转换,在UNIX直接为10进制
SELECT /*+ ORDERED */
sql_text
FROM v$sqltext a
WHERE (a.hash_value, a.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 b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))
ORDER BY piece ASC

 

http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2088.htm

http://junsansi.itpub.net/post/29894/292372

 

 

V$SESSION

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:
  • 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

SERVER VARCHAR2(9) Server type (DEDICATEDSHAREDPSEUDONONE)
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 theDBMS_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 theDBMS_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 ofROW_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 ofROW_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 STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

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:
  • 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:

FAILOVER_METHOD VARCHAR2(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_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:
  • VALID

  • NO HOLDER

  • GLOBAL

  • NOT IN WAIT

  • UNKNOWN

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. IfWAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, andSECONDS_IN_WAIT - WAIT_TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19) 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) 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)

 

 

 

 

V$PROCESS

This view contains information about the currently active processes. While the LATCHWAIT column indicates what latch a process is waiting for, the LATCHSPINcolumn indicates what latch a process is spinning on. On multi-processor machines, Oracle processes will spin on a latch before waiting on it.

Column Datatype Description
ADDR RAW(4 | 8) Address of process state object
PID NUMBER Oracle process identifier
SPID VARCHAR2(12) Operating system process identifier
USERNAME VARCHAR2(15) Operating system process username. Any two-task user coming across the network has "-T" appended to the username.
SERIAL# NUMBER Process serial number
TERMINAL VARCHAR2(30) Operating system terminal identifier
PROGRAM VARCHAR2(48) Program in progress
TRACEID VARCHAR2(255) Trace file identifier
BACKGROUND VARCHAR2(1) 1 for a background process; NULL for a normal process
LATCHWAIT VARCHAR2(8) Address of latch the process is waiting for; NULL if none
LATCHSPIN VARCHAR2(8) Address of the latch the process is spinning on; NULL if none
PGA_USED_MEM NUMBER PGA memory currently used by the process
PGA_ALLOC_MEM NUMBER PGA memory currently allocated by the process (including free PGA memory not yet released to the operating system by the server process)
PGA_FREEABLE_MEM NUMBER Allocated PGA memory which can be freed
PGA_MAX_MEM NUMBER Maximum PGA memory ever allocated by the process

 

 

V$SESSION中的常用列

V$SESSION是基础信息视图,用于找寻用户SID或SADDR。不过,它也有一些列会动态的变化,可用于检查用户。如例:
SQL_HASH_VALUE,SQL_ADDRESS:这两列用于鉴别默认被session执行的SQL语句。如果为null或0,那就说明这个session没有执行任何SQL语句。PREV_HASH_VALUE和PREV_ADDRESS两列用来鉴别被session执行的上一条语句。

注意:当使用SQL*Plus进行选择时,确认你重定义的列宽不小于11以便看到完整的数值。

STATUS:这列用来判断session状态是:
Achtive:正执行SQL语句(waiting for/using a resource)
Inactive:等待操作(即等待需要执行的SQL语句)
Killed:被标注为删除

下列各列提供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#

V$SESSION中的连接列

Column View Joined Column(s) 
SID V$SESSION_WAIT,,V$SESSTAT,,V$LOCK,V$SESSION_EVENT,V$OPEN_CURSOR SID
(SQL_HASH_VALUE, SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
(PREV_HASH_VALUE, PREV_SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
TADDR V$TRANSACTION ADDR
PADDR V$PROCESS ADDR

 

示例:
1.查找你的session信息
SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
FROM V$SESSION WHERE audsid = userenv('SESSIONID');

2.当machine已知的情况下查找session
SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
FROM V$SESSION
WHERE terminal = 'pts/tl' AND machine = 'rgmdbs1';

查找当前被某个指定session正在运行的sql语句。假设sessionID为100
select b.sql_text 
from v$session a,v$sqlarea b 
where a.sql_hash_value=b.hash_value and a.sid=100
寻找被指定session执行的SQL语句是一个公共需求,如果session是瓶颈的主要原因,那根据其当前在执行的语句可以查看session在做些什么。

 

.如果数据库瓶颈是系统资源(如:cpu,内存),并且占用资源最多的用户总是停留在某几个服务进程,那么进行如下诸项:

1>.找出资源进程
2>.找出它们的session,你必须将进程与会话联系起来。
3>.找出为什么session占用了如此多的资源

2.SQL跟踪文件名是基于服务进程的操作系统进程ID。要找出session的跟踪文件,你必须将session与服务进程联系起来。
3.某些事件,如rdbms ipc reply,鉴别session进程的Oracle进程ID在等什么。要发现这些进程在做什么,你必须找出它们的session。
4.你所看到的服务器上的后台进程(DBWR,LGWR,PMON等)都是服务进程。要想知道他们在做什么,你必须找到他们的session。

V$PROCESS中的常用列
ADDR:进程对象地址
PID:oracle进程ID
SPID:操作系统进程ID

V$PROCESS中的连接列
Column View Joined Column(s) 
ADDR V$SESSION PADDR

示例:
1.查找指定系统用户在oracle中的session信息及进程id,假设操作系统用户为:junsansi
select s.sid,s.SERIAL#, s.username,p.spid
from v$session s, v$process p
where s.osuser = 'junsansi'
and s.PADDR = p.ADDR

2.查看锁和等待
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

附注:
在linux环境可以通过ps查看进程信息包括pid,windows中任务管理器的PID与v$process中pid不能一一对应,这块在oracleDocument中也没有找到介绍,后来google了一下,有资料介绍说是由于windows是多线程服务器,每个进程包含一系列线程。这点于unix等不同,Unix每个Oralce进程独立存在,在Nt上所有线程由Oralce进程衍生。
要在windows中显示oracle相关进程pid,我们可以通过一个简单的sql语句来实现。
SELECT s.SID, p.pid, p.spid signaled, s.osuser, s.program
FROM v$process p, v$session s
WHERE p.addr = s.paddr;

SID PID SIGNALED OSUSER PROGRAM 
1 2 2452 SYSTEM ORACLE.EXE 
2 3 2460 SYSTEM ORACLE.EXE 
3 4 2472 SYSTEM ORACLE.EXE 
4 5 2492 SYSTEM ORACLE.EXE 
5 6 2496 SYSTEM ORACLE.EXE 
6 7 2508 SYSTEM ORACLE.EXE 
7 8 2520 SYSTEM ORACLE.EXE 
8 9 2524 SYSTEM ORACLE.EXE 
10 12 1316 JSSjunsansi PlSqlDev.exe 
9 13 3420 JSSjunsansi PlSqlDev.exe 
13 14 660 JSSjunsansi PlSqlDev.exe

还可以通过和 v$bgprocess 连接查询到后台进程的名字: 
SELECT s.SID SID, p.spid threadid, p.program processname, bg.NAME NAME
FROM v$process p, v$session s, v$bgprocess bg
WHERE p.addr = s.paddr
AND p.addr = bg.paddr
AND bg.paddr <> '00';

SID THREADID PROCESSNAME NAME 
1 2452 ORACLE.EXE PMON 
2 2460 ORACLE.EXE DBW0 
3 2472 ORACLE.EXE LGWR 
4 2492 ORACLE.EXE CKPT 
5 2496 ORACLE.EXE SMON 
6 2508 ORACLE.EXE RECO 
7 2520 ORACLE.EXE CJQ0 
8 2524 ORACLE.EXE QMN0

Eygle大师写了一段sql脚本getsql.sql,用来获取指定pid正在执行的sql语句,在此也附注上来。
REM getsql.sql
REM author eygle
REM 在windows上,已知进程ID,得到当前正在执行的语句
REM 在windows上,进程ID为16进制,需要转换,在UNIX直接为10进制
SELECT /*+ ORDERED */
sql_text
FROM v$sqltext a
WHERE (a.hash_value, a.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 b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))
ORDER BY piece ASC

 

http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2088.htm

http://junsansi.itpub.net/post/29894/292372

 

 

V$SESSION

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:
  • 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

SERVER VARCHAR2(9) Server type (DEDICATEDSHAREDPSEUDONONE)
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 theDBMS_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 theDBMS_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 ofROW_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 ofROW_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 STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

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:
  • 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:

FAILOVER_METHOD VARCHAR2(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_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:
  • VALID

  • NO HOLDER

  • GLOBAL

  • NOT IN WAIT

  • UNKNOWN

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. IfWAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, andSECONDS_IN_WAIT - WAIT_TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19) 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) 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)

 

 

 

 

V$PROCESS

This view contains information about the currently active processes. While the LATCHWAIT column indicates what latch a process is waiting for, the LATCHSPINcolumn indicates what latch a process is spinning on. On multi-processor machines, Oracle processes will spin on a latch before waiting on it.

Column Datatype Description
ADDR RAW(4 | 8) Address of process state object
PID NUMBER Oracle process identifier
SPID VARCHAR2(12) Operating system process identifier
USERNAME VARCHAR2(15) Operating system process username. Any two-task user coming across the network has "-T" appended to the username.
SERIAL# NUMBER Process serial number
TERMINAL VARCHAR2(30) Operating system terminal identifier
PROGRAM VARCHAR2(48) Program in progress
TRACEID VARCHAR2(255) Trace file identifier
BACKGROUND VARCHAR2(1) 1 for a background process; NULL for a normal process
LATCHWAIT VARCHAR2(8) Address of latch the process is waiting for; NULL if none
LATCHSPIN VARCHAR2(8) Address of the latch the process is spinning on; NULL if none
PGA_USED_MEM NUMBER PGA memory currently used by the process
PGA_ALLOC_MEM NUMBER PGA memory currently allocated by the process (including free PGA memory not yet released to the operating system by the server process)
PGA_FREEABLE_MEM NUMBER Allocated PGA memory which can be freed
PGA_MAX_MEM NUMBER Maximum PGA memory ever allocated by the process

 

 

V$SESSION中的常用列

V$SESSION是基础信息视图,用于找寻用户SID或SADDR。不过,它也有一些列会动态的变化,可用于检查用户。如例:
SQL_HASH_VALUE,SQL_ADDRESS:这两列用于鉴别默认被session执行的SQL语句。如果为null或0,那就说明这个session没有执行任何SQL语句。PREV_HASH_VALUE和PREV_ADDRESS两列用来鉴别被session执行的上一条语句。

注意:当使用SQL*Plus进行选择时,确认你重定义的列宽不小于11以便看到完整的数值。

STATUS:这列用来判断session状态是:
Achtive:正执行SQL语句(waiting for/using a resource)
Inactive:等待操作(即等待需要执行的SQL语句)
Killed:被标注为删除

下列各列提供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#

V$SESSION中的连接列

Column View Joined Column(s) 
SID V$SESSION_WAIT,,V$SESSTAT,,V$LOCK,V$SESSION_EVENT,V$OPEN_CURSOR SID
(SQL_HASH_VALUE, SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
(PREV_HASH_VALUE, PREV_SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
TADDR V$TRANSACTION ADDR
PADDR V$PROCESS ADDR

 

示例:
1.查找你的session信息
SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
FROM V$SESSION WHERE audsid = userenv('SESSIONID');

2.当machine已知的情况下查找session
SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
FROM V$SESSION
WHERE terminal = 'pts/tl' AND machine = 'rgmdbs1';

查找当前被某个指定session正在运行的sql语句。假设sessionID为100
select b.sql_text 
from v$session a,v$sqlarea b 
where a.sql_hash_value=b.hash_value and a.sid=100
寻找被指定session执行的SQL语句是一个公共需求,如果session是瓶颈的主要原因,那根据其当前在执行的语句可以查看session在做些什么。

 

.如果数据库瓶颈是系统资源(如:cpu,内存),并且占用资源最多的用户总是停留在某几个服务进程,那么进行如下诸项:

1>.找出资源进程
2>.找出它们的session,你必须将进程与会话联系起来。
3>.找出为什么session占用了如此多的资源

2.SQL跟踪文件名是基于服务进程的操作系统进程ID。要找出session的跟踪文件,你必须将session与服务进程联系起来。
3.某些事件,如rdbms ipc reply,鉴别session进程的Oracle进程ID在等什么。要发现这些进程在做什么,你必须找出它们的session。
4.你所看到的服务器上的后台进程(DBWR,LGWR,PMON等)都是服务进程。要想知道他们在做什么,你必须找到他们的session。

V$PROCESS中的常用列
ADDR:进程对象地址
PID:oracle进程ID
SPID:操作系统进程ID

V$PROCESS中的连接列
Column View Joined Column(s) 
ADDR V$SESSION PADDR

示例:
1.查找指定系统用户在oracle中的session信息及进程id,假设操作系统用户为:junsansi
select s.sid,s.SERIAL#, s.username,p.spid
from v$session s, v$process p
where s.osuser = 'junsansi'
and s.PADDR = p.ADDR

2.查看锁和等待
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

附注:
在linux环境可以通过ps查看进程信息包括pid,windows中任务管理器的PID与v$process中pid不能一一对应,这块在oracleDocument中也没有找到介绍,后来google了一下,有资料介绍说是由于windows是多线程服务器,每个进程包含一系列线程。这点于unix等不同,Unix每个Oralce进程独立存在,在Nt上所有线程由Oralce进程衍生。
要在windows中显示oracle相关进程pid,我们可以通过一个简单的sql语句来实现。
SELECT s.SID, p.pid, p.spid signaled, s.osuser, s.program
FROM v$process p, v$session s
WHERE p.addr = s.paddr;

SID PID SIGNALED OSUSER PROGRAM 
1 2 2452 SYSTEM ORACLE.EXE 
2 3 2460 SYSTEM ORACLE.EXE 
3 4 2472 SYSTEM ORACLE.EXE 
4 5 2492 SYSTEM ORACLE.EXE 
5 6 2496 SYSTEM ORACLE.EXE 
6 7 2508 SYSTEM ORACLE.EXE 
7 8 2520 SYSTEM ORACLE.EXE 
8 9 2524 SYSTEM ORACLE.EXE 
10 12 1316 JSSjunsansi PlSqlDev.exe 
9 13 3420 JSSjunsansi PlSqlDev.exe 
13 14 660 JSSjunsansi PlSqlDev.exe

还可以通过和 v$bgprocess 连接查询到后台进程的名字: 
SELECT s.SID SID, p.spid threadid, p.program processname, bg.NAME NAME
FROM v$process p, v$session s, v$bgprocess bg
WHERE p.addr = s.paddr
AND p.addr = bg.paddr
AND bg.paddr <> '00';

SID THREADID PROCESSNAME NAME 
1 2452 ORACLE.EXE PMON 
2 2460 ORACLE.EXE DBW0 
3 2472 ORACLE.EXE LGWR 
4 2492 ORACLE.EXE CKPT 
5 2496 ORACLE.EXE SMON 
6 2508 ORACLE.EXE RECO 
7 2520 ORACLE.EXE CJQ0 
8 2524 ORACLE.EXE QMN0

Eygle大师写了一段sql脚本getsql.sql,用来获取指定pid正在执行的sql语句,在此也附注上来。
REM getsql.sql
REM author eygle
REM 在windows上,已知进程ID,得到当前正在执行的语句
REM 在windows上,进程ID为16进制,需要转换,在UNIX直接为10进制
SELECT /*+ ORDERED */
sql_text
FROM v$sqltext a
WHERE (a.hash_value, a.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 b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))
ORDER BY piece ASC

 

http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2088.htm

http://junsansi.itpub.net/post/29894/292372

 

 

V$SESSION

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:
  • 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

SERVER VARCHAR2(9) Server type (DEDICATEDSHAREDPSEUDONONE)
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 theDBMS_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 theDBMS_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 ofROW_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 ofROW_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 STATUS is currently INACTIVE, then the value represents the elapsed time in seconds since the session has become inactive.

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:
  • 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:

FAILOVER_METHOD VARCHAR2(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_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:
  • VALID

  • NO HOLDER

  • GLOBAL

  • NOT IN WAIT

  • UNKNOWN

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. IfWAIT_TIME > 0, then SECONDS_IN_WAIT is the seconds since the start of the last wait, andSECONDS_IN_WAIT - WAIT_TIME / 100 is the active seconds since the last wait ended.
STATE VARCHAR2(19) 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) 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)

 

 

 

 

V$PROCESS

This view contains information about the currently active processes. While the LATCHWAIT column indicates what latch a process is waiting for, the LATCHSPINcolumn indicates what latch a process is spinning on. On multi-processor machines, Oracle processes will spin on a latch before waiting on it.

Column Datatype Description
ADDR RAW(4 | 8) Address of process state object
PID NUMBER Oracle process identifier
SPID VARCHAR2(12) Operating system process identifier
USERNAME VARCHAR2(15) Operating system process username. Any two-task user coming across the network has "-T" appended to the username.
SERIAL# NUMBER Process serial number
TERMINAL VARCHAR2(30) Operating system terminal identifier
PROGRAM VARCHAR2(48) Program in progress
TRACEID VARCHAR2(255) Trace file identifier
BACKGROUND VARCHAR2(1) 1 for a background process; NULL for a normal process
LATCHWAIT VARCHAR2(8) Address of latch the process is waiting for; NULL if none
LATCHSPIN VARCHAR2(8) Address of the latch the process is spinning on; NULL if none
PGA_USED_MEM NUMBER PGA memory currently used by the process
PGA_ALLOC_MEM NUMBER PGA memory currently allocated by the process (including free PGA memory not yet released to the operating system by the server process)
PGA_FREEABLE_MEM NUMBER Allocated PGA memory which can be freed
PGA_MAX_MEM NUMBER Maximum PGA memory ever allocated by the process

 

 

V$SESSION中的常用列

V$SESSION是基础信息视图,用于找寻用户SID或SADDR。不过,它也有一些列会动态的变化,可用于检查用户。如例:
SQL_HASH_VALUE,SQL_ADDRESS:这两列用于鉴别默认被session执行的SQL语句。如果为null或0,那就说明这个session没有执行任何SQL语句。PREV_HASH_VALUE和PREV_ADDRESS两列用来鉴别被session执行的上一条语句。

注意:当使用SQL*Plus进行选择时,确认你重定义的列宽不小于11以便看到完整的数值。

STATUS:这列用来判断session状态是:
Achtive:正执行SQL语句(waiting for/using a resource)
Inactive:等待操作(即等待需要执行的SQL语句)
Killed:被标注为删除

下列各列提供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#

V$SESSION中的连接列

Column View Joined Column(s) 
SID V$SESSION_WAIT,,V$SESSTAT,,V$LOCK,V$SESSION_EVENT,V$OPEN_CURSOR SID
(SQL_HASH_VALUE, SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
(PREV_HASH_VALUE, PREV_SQL_ADDRESS) V$SQLTEXT, V$SQLAREA, V$SQL (HASH_VALUE, ADDRESS)
TADDR V$TRANSACTION ADDR
PADDR V$PROCESS ADDR

 

示例:
1.查找你的session信息
SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
FROM V$SESSION WHERE audsid = userenv('SESSIONID');

2.当machine已知的情况下查找session
SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
FROM V$SESSION
WHERE terminal = 'pts/tl' AND machine = 'rgmdbs1';

查找当前被某个指定session正在运行的sql语句。假设sessionID为100
select b.sql_text 
from v$session a,v$sqlarea b 
where a.sql_hash_value=b.hash_value and a.sid=100
寻找被指定session执行的SQL语句是一个公共需求,如果session是瓶颈的主要原因,那根据其当前在执行的语句可以查看session在做些什么。

 

.如果数据库瓶颈是系统资源(如:cpu,内存),并且占用资源最多的用户总是停留在某几个服务进程,那么进行如下诸项:

1>.找出资源进程
2>.找出它们的session,你必须将进程与会话联系起来。
3>.找出为什么session占用了如此多的资源

2.SQL跟踪文件名是基于服务进程的操作系统进程ID。要找出session的跟踪文件,你必须将session与服务进程联系起来。
3.某些事件,如rdbms ipc reply,鉴别session进程的Oracle进程ID在等什么。要发现这些进程在做什么,你必须找出它们的session。
4.你所看到的服务器上的后台进程(DBWR,LGWR,PMON等)都是服务进程。要想知道他们在做什么,你必须找到他们的session。

V$PROCESS中的常用列
ADDR:进程对象地址
PID:oracle进程ID
SPID:操作系统进程ID

V$PROCESS中的连接列
Column View Joined Column(s) 
ADDR V$SESSION PADDR

示例:
1.查找指定系统用户在oracle中的session信息及进程id,假设操作系统用户为:junsansi
select s.sid,s.SERIAL#, s.username,p.spid
from v$session s, v$process p
where s.osuser = 'junsansi'
and s.PADDR = p.ADDR

2.查看锁和等待
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

附注:
在linux环境可以通过ps查看进程信息包括pid,windows中任务管理器的PID与v$process中pid不能一一对应,这块在oracleDocument中也没有找到介绍,后来google了一下,有资料介绍说是由于windows是多线程服务器,每个进程包含一系列线程。这点于unix等不同,Unix每个Oralce进程独立存在,在Nt上所有线程由Oralce进程衍生。
要在windows中显示oracle相关进程pid,我们可以通过一个简单的sql语句来实现。
SELECT s.SID, p.pid, p.spid signaled, s.osuser, s.program
FROM v$process p, v$session s
WHERE p.addr = s.paddr;

SID PID SIGNALED OSUSER PROGRAM 
1 2 2452 SYSTEM ORACLE.EXE 
2 3 2460 SYSTEM ORACLE.EXE 
3 4 2472 SYSTEM ORACLE.EXE 
4 5 2492 SYSTEM ORACLE.EXE 
5 6 2496 SYSTEM ORACLE.EXE 
6 7 2508 SYSTEM ORACLE.EXE 
7 8 2520 SYSTEM ORACLE.EXE 
8 9 2524 SYSTEM ORACLE.EXE 
10 12 1316 JSSjunsansi PlSqlDev.exe 
9 13 3420 JSSjunsansi PlSqlDev.exe 
13 14 660 JSSjunsansi PlSqlDev.exe

还可以通过和 v$bgprocess 连接查询到后台进程的名字: 
SELECT s.SID SID, p.spid threadid, p.program processname, bg.NAME NAME
FROM v$process p, v$session s, v$bgprocess bg
WHERE p.addr = s.paddr
AND p.addr = bg.paddr
AND bg.paddr <> '00';

SID THREADID PROCESSNAME NAME 
1 2452 ORACLE.EXE PMON 
2 2460 ORACLE.EXE DBW0 
3 2472 ORACLE.EXE LGWR 
4 2492 ORACLE.EXE CKPT 
5 2496 ORACLE.EXE SMON 
6 2508 ORACLE.EXE RECO 
7 2520 ORACLE.EXE CJQ0 
8 2524 ORACLE.EXE QMN0

Eygle大师写了一段sql脚本getsql.sql,用来获取指定pid正在执行的sql语句,在此也附注上来。
REM getsql.sql
REM author eygle
REM 在windows上,已知进程ID,得到当前正在执行的语句
REM 在windows上,进程ID为16进制,需要转换,在UNIX直接为10进制
SELECT /*+ ORDERED */
sql_text
FROM v$sqltext a
WHERE (a.hash_value, a.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 b
WHERE b.paddr = (SELECT addr
FROM v$process c
WHERE c.spid = TO_NUMBER ('&pid', 'xxxx')))
ORDER BY piece ASC

 

http://docs.oracle.com/cd/B19306_01/server.102/b14237/dynviews_2088.htm

http://junsansi.itpub.net/post/29894/292372

 

 


本文转自茄子_2008博客园博客,原文链接:http://www.cnblogs.com/xd502djj/archive/2012/07/10/2585005.html,如需转载请自行联系原作者。


目录
相关文章
|
5天前
|
机器学习/深度学习 TensorFlow 算法框架/工具
Gaussian Process
【6月更文挑战第14天】
14 4
|
1月前
|
TensorFlow 算法框架/工具 Python
完美解决丨RuntimeError: create_session() called before __init__().
完美解决丨RuntimeError: create_session() called before __init__().
|
网络协议
Job for named.service failed because the control process exited with error code.
Job for named.service failed because the control process exited with error code.
633 0
|
网络协议
Job for named.service failed because the control process exited with error code.怎么解决
本篇内容记录了如何解决Job for named.service failed because the control process exited with error code.的问题。
3268 0
Job for named.service failed because the control process exited with error code.怎么解决
|
关系型数据库 Java MySQL
|
SQL Oracle 关系型数据库