1. 程式人生 > >Oracle中V$SESSION等各表的欄位解釋,Oracle官方解釋

Oracle中V$SESSION等各表的欄位解釋,Oracle官方解釋

一、常用的檢視

1.會話相關檢視

View Description

V$PROCESS

Contains information about the currently active processes

V$SESSION

Lists session information for each current session

V$SESS_IO

Contains I/O statistics for each user session

V$SESSION_LONGOPS

Displays the status of various operations that run for longer than 6 seconds (in absolute time). These operations currently include many backup and recovery functions, statistics gathering, and query execution. More operations are added for every Oracle Database release.

V$SESSION_WAIT

Displays the current or last wait for each session

V$SESSION_WAIT_HISTORY

Lists the last ten wait events for each active session

V$WAIT_CHAINS

Displays information about blocked sessions

V$SESSTAT

Contains session statistics

V$RESOURCE_LIMIT

Provides information about current and maximum global resource utilization for some system resources

V$SQLAREA

Contains statistics about shared SQL areas. Contains one row for each SQL string. Provides statistics about SQL statements that are in memory, parsed, and ready for execution

 

2.鎖相關的檢視:

View Description

V$LOCK

Lists the locks currently held by Oracle Database and outstanding requests for a lock or latch

DBA_BLOCKERS

Displays a session if it is holding a lock on an object for which another session is waiting

DBA_WAITERS

Displays a session if it is waiting for a locked object

DBA_DDL_LOCKS

Lists all DDL locks held in the database and all outstanding requests for a DDL lock

DBA_DML_LOCKS

Lists all DML locks held in the database and all outstanding requests for a DML lock

DBA_LOCK

Lists all locks or latches held in the database and all outstanding requests for a lock or latch

DBA_LOCK_INTERNAL

Displays a row for each lock or latch that is being held, and one row for each outstanding request for a lock or latch

V$LOCKED_OBJECT

Lists all locks acquired by every transaction on the system

V$SESSION_WAIT

Lists the resources or events for which active sessions are waiting

V$SYSSTAT

Contains session statistics

V$RESOURCE_LIMIT

Provides information about current and maximum global resource utilization for some system resources

V$SQLAREA

Contains statistics about shared SQL area and contains one row for each SQL string. Also provides statistics about SQL statements that are in memory, parsed, and ready for execution

V$LATCH

Contains statistics for nonparent latches and summary statistics for parent latches

 

二、V$SESSION

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/refrn/V-SESSION.html#GUID-28E2DC75-E157-4C0A-94AB-117C205789B9

 

三、V$SESSION_WAIT

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/refrn/V-SESSION_WAIT.html#GUID-4EDAB293-F3FC-40FE-BC75-4FEE6A4D7705

 

這裡面有個event欄位,event欄位的列舉值可以存在下面的表中,可以這樣查詢:

SELECT name, wait_class FROM V$EVENT_NAME ORDER BY name

 

1. 查詢會話正在等待行鎖的會話:

select event,sid,p1,p2,p3 from v$session_wait where event='enq: TX - row lock contention';

 

三、V$LOCKED_OBJECT

1.簡介及表字段

該表列出每個事務獲取到的所有鎖。它可以展示出哪個會話正在持有鎖,在什麼物件上持有鎖,以及鎖的模式。

Column Datatype Description

XIDUSN

NUMBER

Undo segment number

XIDSLOT

NUMBER

Slot number

XIDSQN

NUMBER

Sequence number

OBJECT_ID

NUMBER

Object ID being locked

SESSION_ID

NUMBER

Session ID

ORACLE_USERNAME

VARCHAR2(128)

Oracle user name

OS_USER_NAME

VARCHAR2(128)

Operating system user name

PROCESS

VARCHAR2(24)

Operating system process ID

LOCKED_MODE

NUMBER

Lock mode. The numeric values for this column map to these text values for the lock modes for table locks:

  • 0 - NONE: lock requested but not yet obtained

  • 1 - NULL

  • 2 - ROWS_S (SS): Row Share Lock

  • 3 - ROW_X (SX): Row Exclusive Table Lock

  • 4 - SHARE (S): Share Table Lock

  • 5 - S/ROW-X (SSX): Share Row Exclusive Table Lock

  • 6 - Exclusive (X): Exclusive Table Lock

See Also: Oracle Database Concepts for more information about lock modes for table locks

CON_ID

NUMBER

The ID of the container to which the data pertains. Possible values include:

  • 0: This value is used for rows containing data that pertain to the entire CDB. This value is also used for rows in non-CDBs.

  • 1: This value is used for rows containing data that pertain to only the root

  • n: Where n is the applicable container ID for the rows containing data

 

2.查詢持有鎖的會話

SELECT USERNAME, LOCKWAIT, STATUS, MACHINE, PROGRAM

  FROM V$SESSION

 WHERE SID IN (SELECT SESSION_ID FROM V$LOCKED_OBJECT);

 

 3.查詢持有鎖的會話正在執行的sql

SELECT
    SQL_TEXT
FROM
    V$SQL
WHERE
    HASH_VALUE IN (
        SELECT
            SQL_HASH_VALUE
        FROM
            V$SESSION
        WHERE
            SID IN (
                SELECT
                    SESSION_ID
                FROM
                    V$LOCKED_OBJECT
            )
    );

4.根據物件名查詢持有該鎖物件的會話

SELECT o.object_name,s.sid, s.serial#
       FROM v$locked_object l, dba_objects o, v$session s
            WHERE l.object_id = o.object_id
                  AND l.session_id = s.sid

      AND o.object_name='SEATINFORMATION';
SEATINFORMATION為本地表的名字。

 

 

四、V$LOCK

1.簡介

該檢視列出當前被oracle持有的鎖。

Column Datatype Description

ADDR

RAW(4 | 8)

Address of lock state object

KADDR

RAW(4 | 8)

Address of lock

SID

NUMBER

Identifier for session holding or acquiring the lock

TYPE

VARCHAR2(2)

Type of user or system lock

The locks on the user types are obtained by user applications. Any process that is blocking others is likely to be holding one of these locks. The user type locks are:

TM - DML enqueue

TX - Transaction enqueue

UL - User supplied

The system type locks are listed in Table 8-1. Be aware that not all types of locks are documented. To find a complete list of locks for the current release, query the V$LOCK_TYPE data dictionary view, described on "V$LOCK_TYPE".

-- 我們主要關注TX 和TM 兩種型別的鎖

--UL 鎖使用者自己定義的,一般很少會定義,基本不用關注

ID1

NUMBER

Lock identifier #1 (depends on type)

ID2

NUMBER

Lock identifier #2 (depends on type)

--- 當lock type 為TM 時,id1 為DML-locked object 的object_id

--- 當lock type 為TX 時,id1 為usn+slot ,而id2 為seq 。

-- 當lock type 為其它時,不用關注

LMODE

NUMBER

Lock mode in which the session holds the lock:

  • 0 - none

  • 1 - null (NULL)

  • 2 - row-S (SS)

  • 3 - row-X (SX)

  • 4 - share (S)

  • 5 - S/Row-X (SSX)

  • 6 - exclusive (X)--大於0時表示 當前會話以某種模式 佔有 該鎖,等於0時表示當前會話正在等待該鎖資源,即表示該會話被阻塞。

 

  • --大於0時表示 當前會話以某種模式 佔有 該鎖,等於0時表示當前會話正在等待該鎖資源,即表示該會話被阻塞。

    往往在發生TX 鎖時,伴隨著TM 鎖,比如一個sid=9 會話擁有一個TM 鎖,一般會擁有一個或幾個TX鎖,但他們的id1 和id2 是不同的,請注意

REQUEST

NUMBER

Lock mode in which the process requests the lock:

  • 0 - none

  • 1 - null (NULL)

  • 2 - row-S (SS)

  • 3 - row-X (SX)

  • 4 - share (S)

  • 5 - S/Row-X (SSX)

  • 6 - exclusive (X)

 


-- 大於0時,表示當前會話被阻塞,其它會話佔有該鎖的模式

CTIME

NUMBER

Time since current mode was granted

BLOCK

NUMBER

Indicates whether the lock in question is blocking other processes. The possible values are:

  • 0 - The lock is not blocking any other processes

  • 1 - The lock is blocking other processes

  • 2 - The lock is not blocking any blocked processes on the local node, but it may or may not be blocking processes on remote nodes. This value is used only in Oracle Real Application Clusters (Oracle RAC) configurations (not in single instance configurations).

CON_ID

NUMBER

The ID of the container to which the data pertains. Possible values include:

  • 0: This value is used for rows containing data that pertain to the entire CDB. This value is also used for rows in non-CDBs.

  • 1: This value is used for rows containing data that pertain to only the root

  • n: Where n is the applicable container ID for the rows containing data

 

2.一個本地的死鎖案例:

從oracle伺服器的trace日誌中看到:

 

 會話432和會話188互相等待。

以下是相關資訊:

2.1 會話432的持有的鎖,被鎖的物件,正在執行的sql:

SELECT *  FROM V$LOCK l where  l.sid = 432;