select  * from  v$session select * from v$session where username is not null
这两个应该是查看数据库链接数的语句。
问题:
1.两个语句有何区别。
2.select  * from  v$session 查询出来的字段都什么意思,越详细越好。
3.我想知道都有那些用户当前链接到数据库,以及链接是什么时候建立的,这些信息从那个字段中体现?初学,高手解释的越详细越好,谢谢了。

解决方案 »

  1.   

    [转帖]自CNOUG的jametong V$session 表的妙用^_^
    v$session 表中比较常用的几个字段说明^_^1. sid,serial#
    通过sid我们可以查询与这个session相关的各种统计信息,处理信息.
    a. select * from v$sesstat where sid = :sid; 
    查询用户相关的各种统计信息. 
    select a.sid,a.statistic#,b.name,a.value
    from v$sesstat a,v$statname b
    where a.statistic# = b.statistic#
    and a.sid = :sid;b. 查询用户相关的各种io统计信息
    select * from v$sess_io where sid = :sid;c. 查询用户想在正在打开着的游标变量.
    select * from v$open_cursor where sid = :sid;d. 查询用户当前的等待信息. 以查看当前的语句为什么这么慢/在等待什么资源.
    select * from v$session_wait where sid = :sid ;e. 查询用户在一段时间内所等待的各种事件的信息. 以了解这个session所遇到的瓶颈^_^
    select * from v$session_event where sid = :sid;f. 还有, 就是当我们想kill当前session的时候可以通过sid,serial#来处理.
    alter system kill session ':sid,:serail#';2. paddr.字段, process addr, 通过这个字段我们可以查看当前进程的相关信息, 系统进程id,操作系统用户信息等等.
    select a.pid,a.spid,b.name,b.description,a.latchwait,a.latchspin,a.pga_used_mem,a.pga_alloc_mem,a.pga_freeable_mem,a.pga_max_mem
    from v$process a,v$bgprocess b
    where a.addr = b.paddr(+)
    and a.addr = :paddr3. command 字段, 表明当前session正在执行的语句的类型.请参考reference.4. taddr 当前事务的地址,可以通过这个字段查看当前session正在执行的事务信息, 使用的回滚段信息等^_^
    select b.name rollname,a.*
    from v$transaction a,v$rollname b
    where a.xidusn = b.usn
    and a.addr = '585EC18C';5. lockwait字段, 可以通过这个字段查询出当前正在等待的锁的相关信息.
    select *
    from v$lock
    where (id1,id2) = (
            select id1,id2 from v$lock where kaddr = '57C68C48'
    )6. (sql_address,sql_hash_value) (prev_sql_addr,prev_hash_value) 根据这两组字段, 我们可以查询到当前session正在执行的sql语句的详细信息.select * from v$sqltext where address = :sql_address and hash_value = :sql_hash_value;7.ROW_WAIT_OBJ#,ROW_WAIT_FILE#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#
    可以通过这几个字段查询现在正在被锁的表的相关信息.^_^
    a. 首先得到被锁的的信息
    select * from dba_objects where object_id = :row_wait_obj#;
    b. 根据row_wait_file#可以找出对应的文件的信息.
    select * from v$datafile where file# = :row_wait_file#.
    c. 在根据以上四个字段构造出被锁的字段的rowid信息.
    select dbms_rowid.ROWID_CREATE(1,:row_wait_obj#,:row_wait_file#,:row_wait_block#,:row_wait_row#) from dual;8. logon_time 当前session的登录时间.
    9. last_call_et 该session idle的时间, 每3秒中更新一次^_^[ Last edited by jametong on 2004-11-26 at 11:38 ]
      

  2.   

    from Oracle9i Database Reference================================================================
    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 identify uniquely 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 this 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 3-3. 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 (currently executing SQL), INACTIVE, KILLED (ed to be killed), CACHED (temporarily cached for use by Oracle*XA), SNIPED (session inactive, waiting on the client)
     
    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(9)
     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)
     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
     
    PREV_SQL_ADDR
     RAW(4)
     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
     
    MODULE
     VARCHAR2(48)
     Contains the name of the currently executing module as set by calling the DBMS_APPLICATION_INFO.SET_MODULE procedure
     
    MODULE_HASH
     NUMBER
     The hash value of the above MODULE
     
    ACTION
     VARCHAR2(32)
     Contains the name of the currently executing action as set by calling the DBMS_APPLICATION_INFO.SET_ACTION procedure
     
    ACTION_HASH
     NUMBER
     The 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 ROWID specified in ROW_WAIT_ROW#
     
    ROW_WAIT_FILE#
     NUMBER
     Identifier for the datafile containing the ROWID 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 ROWID 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
     The current ROWID 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
     The last call
     
    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 - the client is able to fail over its session following a disconnect 
    SELECT - the client is able to fail over queries in progress as well 
    See Also:Oracle9i Database Concepts for more information on TAF 
    Oracle9i Net Services Administrator's Guide for information on configuring TAF 
     
    FAILOVER_METHOD
     VARCHAR2(10)
     Indicates the transparent application failover method for the session:NONE - failover is disabled for this session 
    BASIC - the client itself reconnects following a disconnect 
    PRECONNECT - the backup instance can support all connections from every instance for which it is backup 
     
    FAILED_OVER
     VARCHAR2(3)
     Indicates (YES|NO) whether the session is running in failover mode and failover has occurred
     
    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, value is 0.
     
    CLIENT_IDENTIFIER
     VARCHAR2(64)