`
fudehai001
  • 浏览: 498782 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

oracle v$locks和v$session的说明

阅读更多
Oracle9i Database Reference
Release 2 (9.2)
Part Number A96536-02


V$LOCK
This view lists the locks currently held by the Oracle database server and outstanding requests for a lock or latch.

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 locks on the system types are held for extremely short periods of time. The system type locks are listed in Table 3-1.

ID1
NUMBER
Lock identifier #1 (depends on type)

ID2
NUMBER
Lock identifier #2 (depends on 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)

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)

CTIME
NUMBER
Time since current mode was granted

BLOCK
NUMBER
The lock is blocking another lock


Table 3-1  Values for the TYPE Column: System Types
System Type Description System Type Description
BL
Buffer hash table instance
NA..NZ
Library cache pin instance (A..Z = namespace)

CF
Control file schema global enqueue
PF
Password File

CI
Cross-instance function invocation instance
PI, PS
Parallel operation

CU
Cursor bind
PR
Process startup

DF
Data file instance
QA..QZ
Row cache instance (A..Z = cache)

DL
Direct loader parallel index create
RT
Redo thread global enqueue

DM
Mount/startup db primary/secondary instance
SC
System commit number instance

DR
Distributed recovery process
SM
SMON

DX
Distributed transaction entry
SN
Sequence number instance

FS
File set
SQ
Sequence number enqueue

HW
Space management operations on a specific segment
SS
Sort segment

IN
Instance number
ST
Space transaction enqueue

IR
Instance recovery serialization global enqueue
SV
Sequence number value

IS
Instance state
TA
Generic enqueue

IV
Library cache invalidation instance
TS
Temporary segment enqueue (ID2=0)

JQ
Job queue
TS
New block allocation enqueue (ID2=1)

KK
Thread kick
TT
Temporary table enqueue

LA .. LP
Library cache lock instance lock (A..P = namespace)
UN
User name

MM
Mount definition global enqueue
US
Undo segment DDL

MR
Media recovery
WL
Being-written redo log instance

 


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 (marked 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)
 

Table 3-3  COMMAND Column of V$SESSION and Corresponding Commands
Number Command Number Command
1
CREATE TABLE
2
INSERT

3
SELECT
4
CREATE CLUSTER

5
ALTER CLUSTER
6
UPDATE

7
DELETE
8
DROP CLUSTER

9
CREATE INDEX
10
DROP INDEX

11
ALTER INDEX
12
DROP TABLE

13
CREATE SEQUENCE
14
ALTER SEQUENCE

15
ALTER TABLE
16
DROP SEQUENCE

17
GRANT OBJECT
18
REVOKE OBJECT

19
CREATE SYNONYM
20
DROP SYNONYM

21
CREATE VIEW
22
DROP VIEW

23
VALIDATE INDEX
24
CREATE PROCEDURE

25
ALTER PROCEDURE
26
LOCK

27
NO-OP
28
RENAME

29
COMMENT
30
AUDIT OBJECT

31
NOAUDIT OBJECT
32
CREATE DATABASE LINK

33
DROP DATABASE LINK
34
CREATE DATABASE

35
ALTER DATABASE
36
CREATE ROLLBACK SEG

37
ALTER ROLLBACK SEG
38
DROP ROLLBACK SEG

39
CREATE TABLESPACE
40
ALTER TABLESPACE

41
DROP TABLESPACE
42
ALTER SESSION

43
ALTER USER
44
COMMIT

45
ROLLBACK
46
SAVEPOINT

47
PL/SQL EXECUTE
48
SET TRANSACTION

49
ALTER SYSTEM
50
EXPLAIN

51
CREATE USER
52
CREATE ROLE

53
DROP USER
54
DROP ROLE

55
SET ROLE
56
CREATE SCHEMA

57
CREATE CONTROL FILE
59
CREATE TRIGGER

60
ALTER TRIGGER
61
DROP TRIGGER

62
ANALYZE TABLE
63
ANALYZE INDEX

64
ANALYZE CLUSTER
65
CREATE PROFILE

66
DROP PROFILE
67
ALTER PROFILE

68
DROP PROCEDURE
70
ALTER RESOURCE COST

71
CREATE SNAPSHOT LOG
72
ALTER SNAPSHOT LOG

73
DROP SNAPSHOT LOG
74
CREATE SNAPSHOT

75
ALTER SNAPSHOT
76
DROP SNAPSHOT

77
CREATE TYPE
78
DROP TYPE

79
ALTER ROLE
80
ALTER TYPE

81
CREATE TYPE BODY
82
ALTER TYPE BODY

83
DROP TYPE BODY
84
DROP LIBRARY

85
TRUNCATE TABLE
86
TRUNCATE CLUSTER

91
CREATE FUNCTION
92
ALTER FUNCTION

93
DROP FUNCTION
94
CREATE PACKAGE

95
ALTER PACKAGE
96
DROP PACKAGE

97
CREATE PACKAGE BODY
98
ALTER PACKAGE BODY

99
DROP PACKAGE BODY
100
LOGON

101
LOGOFF
102
LOGOFF BY CLEANUP

103
SESSION REC
104
SYSTEM AUDIT

105
SYSTEM NOAUDIT
106
AUDIT DEFAULT

107
NOAUDIT DEFAULT
108
SYSTEM GRANT

109
SYSTEM REVOKE
110
CREATE PUBLIC SYNONYM

111
DROP PUBLIC SYNONYM
112
CREATE PUBLIC DATABASE LINK

113
DROP PUBLIC DATABASE LINK
114
GRANT ROLE

115
REVOKE ROLE
116
EXECUTE PROCEDURE

117
USER COMMENT
118
ENABLE TRIGGER

119
DISABLE TRIGGER
120
ENABLE ALL TRIGGERS

121
DISABLE ALL TRIGGERS
122
NETWORK ERROR

123
EXECUTE TYPE
157
CREATE DIRECTORY

158
DROP DIRECTORY
159
CREATE LIBRARY

160
CREATE JAVA
161
ALTER JAVA

162
DROP JAVA
163
CREATE OPERATOR

164
CREATE INDEXTYPE
165
DROP INDEXTYPE

167
DROP OPERATOR
168
ASSOCIATE STATISTICS

169
DISASSOCIATE STATISTICS
170
CALL METHOD

171
CREATE SUMMARY
172
ALTER SUMMARY

173
DROP SUMMARY
174
CREATE DIMENSION

175
ALTER DIMENSION
176
DROP DIMENSION

177
CREATE CONTEXT
178
DROP CONTEXT

179
ALTER OUTLINE
180
CREATE OUTLINE

181
DROP OUTLINE
182
UPDATE INDEXES

183
ALTER OPERATOR
 

 

 

 

Oracle9i Database Performance Tuning Guide and Reference
Release 2 (9.2)
Part Number A96533-02

V$LOCK
This view has a row for every lock held or requested on the system. You should examine this view if you find sessions waiting for the wait event enqueue. If you find sessions waiting for a lock, then the sequence of events could be the following:

Use V$LOCK to find the sessions holding the lock.
Use V$SESSION to find the SQL statements being executed by the sessions holding the lock and waiting for the lock.
Use V$SESSION_WAIT to find what the session holding the lock is blocked on.
Use V$SESSION to get more details about the program and user holding the lock.
Useful Columns for V$LOCK
SID: Identifier of the session holding/requesting the lock
TYPE: Type of lock
LMODE: Lock mode in which the session holds the lock
REQUEST: Lock mode in which the session requests the lock
ID1, ID2: Lock resource identifiers
Common Lock Types
Several common locks are described in this section.

TX: Row Transaction Lock
This lock is required in exclusive mode (mode 6) to change data.
One lock is acquired for each active transaction. It is released when the transaction ends due to a commit or rollback.
If a block containing the row(s) to be changed does not have any ITL (interested transaction list) entries left, then the session requests the lock in shared mode (mode 4). It is released when the session gets an ITL entry for the block.
If any of the rows to be changed are locked by another session, then locking session's transaction lock is requested in exclusive mode. When the locking transaction ends, this request ends, and the rows are covered under the requesting session's existing TX lock.
The lock points to the rollback segment and transaction table entries for the transaction.
Do the following to avoid contention on this enqueue:

To avoid contention on TX-6 enqueues, review the application.
To avoid contention on TX-4 enqueues, consider increasing INITRANS for the object.
TM: DML Lock
This lock is required in exclusive mode for executing any DDL statements on a database object; for example, lock table in exclusive mode, alter table, drop table.
This lock is also acquired in shared mode when executing DML statements such as INSERT, UPDATE, or DELETE. This prevents other sessions from executing a DDL statement on the same object concurrently.
For every object whose data is being changed, a TM lock is required.
The lock points to the object.
To avoid contention on TM enqueues, consider disabling the table lock for the object. Disabling the table lock prevents any DDL from executing on the object.

ST - Space Transaction Lock
There is only one lock for each database (not instance).
This lock is required in exclusive mode for any space management activity (creation or dropping any extents) except with locally managed tablespaces.
Object creation, dropping, extension, and truncation all serialize on this lock.
Most common causes for contention on this lock are sorting to disk (not using true temporary tablespaces) or rollback segment extension and shrinking.
Do the following to avoid contention on this enqueue:

Use true temporary tablespaces, utilizing tempfiles. Temporary segments are not created and dropped after every sort to disk.
Use locally managed tablespaces
Size rollback segments to avoid dynamic extension and shrinking, or use automatic undo management.
Avoid application practices that create and drop database objects.
UL - User Defined Locks
Users can define their own locks.

See Also:
Oracle9i Database Concepts for more information on locks


Common Modes for Request/Lmode
0: None
2: Row Share: used for shared DML locks
4: Share: used for shared TX when waiting for ITL entry
6: Exclusive used for row level, DML locks
Any row in V$LOCK either has LMODE=0 (indicating it is a request) or REQUEST=0 (indicating it is a held lock).

Resource Identifier ID1
For DML locks, ID1 is the object_id.

For TX locks, ID1 points to the rollback segment and transaction table entry.

Join Columns for V$LOCK
Table 24-8 lists the join columns for V$LOCK.

Table 24-8 Join Columns for V$LOCK
Column View Joined Column(s)
SID
V$SESSION
SID

ID1, ID2, TYPE
V$LOCK
ID1, ID2, TYPE

ID1
DBA_OBJECTS
OBJECT_ID

TRUNCID1/65536)
V$ROLLNAME
USN


This is used to find the session holding the lock, if a session is waiting for a lock.
This can be used to find the locked object for DML locks (type = `TM').
This can be used to find the rollback segment in use for row transaction locks (TYPE = `TX'). However, a less cryptic join might be through V$TRANSACTION.
Example 24-11 Finding the Sessions Holding the Lock
Find the (ID1, ID2, type) for sessions waiting for a lock (LMODE=0).

Find the session holding the lock (REQUEST=0) for that ID1, ID2, type.

SELECT lpad(' ',DECODE(request,0,0,1))||sid sess, id1, id2, lmode, request, type
FROM V$LOCK
WHERE id1 IN (SELECT id1 FROM V$LOCK WHERE lmode = 0)
ORDER BY id1,request

SID          ID1        ID2      LMODE    REQUEST TY
------ ---------- ---------- ---------- ---------- --
1237       196705     200493          6          0 TX <- Lock Holder
1256      196705     200493          0          6 TX <- Lock Waiter
1176      196705     200493          0          6 TX <- Lock Waiter
938        589854     201352          6          0 TX <- Lock Holder
1634      589854     201352          0          6 TX <- Lock Waiter

Example 24-12 Finding the Statements being Executed by These Sessions
SELECT sid, sql_hash_value
FROM V$SESSION
WHERE SID IN (1237,1256,1176,938,1634);

SID  SQL_HASH_VALUE
-----  --------------
  938      2078523611 <-Holder
1176      1646972797 <-Waiter
1237      3735785744 <-Holder
1256      1141994875 <-Waiter
1634      2417993520 <-Waiter

Example 24-13 Finding the Text for These SQL Statements
HASH_VALUE SQL_TEXT
---------- ----------------------------------------------------------------
1141994875 SELECT TO_CHAR(CURRENT_MAX_UNIQUE_IDENTIFIER + 1 )   FROM PO_UNI
           QUE_IDENTIFIER_CONTROL  WHERE TABLE_NAME = DECODE(:b1,'RFQ','PO_
           HEADERS_RFQ','QUOTATION','PO_HEADERS_QUOTE','PO_HEADERS') FOR UP
           DATE OF CURRENT_MAX_UNIQUE_IDENTIFIER
1646972797 SELECT TO_CHAR(CURRENT_MAX_UNIQUE_IDENTIFIER + 1 )   FROM PO_UNI
           QUE_IDENTIFIER_CONTROL  WHERE TABLE_NAME = 'PO_HEADERS'  FOR UPD
           ATE OF CURRENT_MAX_UNIQUE_IDENTIFIER
2078523611 select CODE_COMBINATION_ID,  enabled_flag,  nvl(to_char(start_da
           te_active, 'J'), -1),  nvl(to_char(end_date_active, 'J'), -1), S
           EGMENT2||'.'||SEGMENT1||'.'||||SEGMENT6,detail_posting_allowed_f
           lag,summary_flag  from GL_CODE_COMBINATIONS  where CHART_OF_ACCO
           UNTS_ID = 101  and SEGMENT2 in ('000','341','367','388','389','4
           52','476','593','729','N38','N40','Q21','Q31','U21')  order by S
           EGMENT2, SEGMENT1, SEGMENT6
2417993520 select 0 into :b0  from pa_projects where project_id=:b1 for upd
           ate
3735785744 begin 0 := FND_ATTACHMENT_UTIL_PKG.GET_ATCHMT_EXISTS(_ENTITY
           _NAME, _PKEY1, _PKEY2, :L_PKEY3, :L_PKEY4, :L_PKEY5, :L_FUNC
           TION_NAME, :L_FUNCTION_TYPE); end;


The locked sessions' statements show that the sessions 1176 and 1256 are waiting for a lock on the PO_UNIQUE_IDENTIFIER_CONTROL held by session 1237, while session 1634 is waiting for a lock on PA_PROJECTS held by session 938. Query V$SESSION_WAIT, V$SESSION, and V$SESSION_EVENT to get more details about the sessions and users. For example:

Who is holding the lock?
Is the session holding the lock active or idle
Is the session executing long running queries while holding the lock


V$SESSION
This view has one row for every session connected to the database instance. The sessions include user sessions, as well as background processes like DBWR, LGWR, archiver.

See Also:
Oracle9i Database Concepts


Useful Columns for V$SESSION
V$SESSION is basically an information view used for finding the SID or SADDR of a user. However, it has some columns that change dynamically and are useful for examining a user. For example:

SQL_HASH_VALUE, SQL_ADDRESS: These identify the SQL statement currently being executed by the session. If NULL or 0, then the session is not executing any SQL statement. PREV_HASH_VALUE and PREV_ADDRESS identify the previous statement being executed by the session.


--------------------------------------------------------------------------------
Note:
When selecting from SQL*Plus, make sure that you have the column defined with adequate width (11 numbers wide) to see the complete number.

--------------------------------------------------------------------------------


STATUS: This column identifies if the session is:

Active: executing a SQL statement (waiting for/using a resource)
Inactive: waiting for more work (that is, SQL statements)
Killed: marked to be killed
The following columns provide information about the session and can be used to find a session when a combination (one or more) of the following are known:

Session Information
SID: Session identifier, used to join to other columns
SERIAL#: Counter, which is incremented each time a SID is reused by another session (when a session ends and another session starts and uses the same SID)
AUDSID: Auditing session ID uniquely identifies a session over the life of a database. It is also useful when finding the parallel query slaves for a query coordinator (during the PQ execution they have the same AUDSID)
USERNAME: The Oracle user name for the connected session
Client Information
The database session is initiated by a client process that could be running on the database server or connecting to the database across SQL*Net from a middle tier server or even a desktop. The following columns provide information about this client process:

OSUSER: Operating system user name for the client process
MACHINE: Machine where the client process is executing
TERMINAL: Terminal (if applicable) where the client process is running
PROCESS: Process ID of the client process
PROGRAM: Client program being executed by the client process
To display TERMINAL, OSUSER for users connecting from PCs, set the keys TERMINAL, USERNAME in ORACLE.INI or the Windows registry on their PCs if they are not showing up by default.

Application Information
Call the package DBMS_APPLICATION_INFO to set some information to identify the user. This shows up in the following columns:

CLIENT_INFO: Set in DBMS_APPLICATION_INFO
ACTION: Set in DBMS_APPLICATION_INFO
MODULE: Set in DBMS_APPLICATION_INFO
The following V$SESSION columns are also useful:

ROW_WAIT_OBJ#
ROW_WAIT_FILE#
ROW_WAIT_BLOCK#
ROW_WAIT_ROW#
Join Columns for V$SESSION
Table 24-16 is a list of several columns that can be used to join to other fixed views.

Table 24-16 Join Columns for 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


Example 24-21 Finding Your Session
SELECT SID, OSUSER, USERNAME, MACHINE, PROCESS
  FROM V$SESSION
WHERE audsid = userenv('SESSIONID');

  SID OSUSER     USERNAME    MACHINE     PROCESS
----- ---------- ----------- ----------- --------
  398 amerora    PERFSTAT    rgmdbs1     26582

Example 24-22 Finding a Session When the Machine Is Known
SELECT SID, OSUSER, USERNAME, MACHINE, TERMINAL
  FROM V$SESSION
WHERE terminal = 'pts/tl'
   AND machine  = 'rgmdbs1';

SID OSUSER    USERNAME  MACHINE    TERMINAL
---- --------- --------- ---------- ----------
398 amerora   PERFSTAT  rgmdbs1    pts/tl

Example 24-23 Finding the SQL Statement Currently Being Run by a Session
It is a common requirement to find the SQL statement currently being executed by a given session. If a session is experiencing or responsible for a bottleneck, then the statement explains what the session might be doing.

col hash_value form 99999999999
SELECT sql_hash_value hash_value
  FROM V$SESSION WHERE sid = 406;

HASH_VALUE
----------
4249174653
SQL> /

HASH_VALUE
----------
4249174653
SQL> /

HASH_VALUE
----------
4249174653
SQL> /

HASH_VALUE
----------
4249174653


This example waited for five seconds, executed the statement again, and repeated the action couple of times. The same hash_value comes up again and again, indicating that the statement is being executed by the session. As a next step, find the statement text using the view V$SQLTEXT and statement statistics from V$SQLAREA.
分享到:
评论

相关推荐

    有效关闭Oracle死锁进程,和释放状态为killed的session

    在Oracle数据库管理中,处理死锁进程和释放状态为killed的session是一项关键技能,尤其对于维护数据库性能和稳定性至关重要。以下将详细阐述如何通过一系列步骤有效地关闭Oracle死锁进程,以及如何释放状态为killed...

    oracle数据字典关系图

    22. **V$LOCK_ELEMENT 和 V$LOCKS_WITH_COLLISIONS** - 描述:锁定元素和冲突锁定信息。 - 关键字段:`Addr` (V$LOCK_ELEMENT), `Lock_element_addr` (V$LOCKS_WITH_COLLISIONS) - 功能:追踪锁定冲突的情况。 ...

    清除Oracle中长时间持锁的session

    ### 清除Oracle中长时间持锁的Session #### 背景介绍 在Oracle数据库管理过程中,有时会遇到一些长时间占用资源的进程,这些进程可能会导致数据库性能下降甚至某些操作无法执行。通常情况下,如果一个session的状态...

    oracle标准语法速查表

    v$sess_io, v$bsp, v$px_session, v$px_sesstat, v$px_process, v$px_process_sysstat, v$pq_sesstat, v$pq_slave, v$pq_sysstat, v$pq_tqstat - **定义**:会话I/O、并行执行会话、进程等信息。 - **用途**:优化...

    ORACLE Server 8i Quick Reference Card.pdf

    - **锁与并发**: `v$lock`、`v$enqueue_lock`和`v$global_blocked_locks`等视图揭示了锁定机制和并发控制的内部状态。 #### 6. 多线程服务器(MTS) `v$mts`、`v$circuit`和`v$shared_server`等视图涉及到Oracle的...

    oracle常用sql.rar

    - `V$ views`和`DBA_ views`提供丰富的数据库运行状态信息,如`V$SESSION_WAIT`查看等待事件,`V$LOCKS`查看锁信息。 - `SQL Trace`和`10046`事件可以生成详细的执行日志,用于诊断性能问题。 以上只是Oracle SQL...

    《Oracle RAC最佳实践》精华总结

    - 可以通过`V$CR_BLOCK_SERVER`、`V$SESSION_WAIT`和`V$SESSION_WAIT_HISTORY`等视图来识别导致问题的回滚段。 2. **Library Cache Locks**: - 这种锁在PL/SQL和高级队列中较为常见。可以通过查询`V$ENQUEUE_...

    oracle查找死锁

    可以通过查询V$SESSION和V$PROCESS视图来实现这一点: ```sql SELECT SID, SERIAL#, PADDR FROM V$SESSION WHERE SID = '锁定的会话SID'; SELECT SPID FROM V$PROCESS WHERE ADDR = '锁定会话的PADDR'; ``` 这里的...

    检查Oracle数据库被锁的对象的sql语句

    在Oracle数据库管理中,了解如何检查被锁定的对象是至关重要的,因为这直接影响到数据库的性能和可用性。本文将深入探讨两个SQL查询语句,它们分别用于检查数据库表和pkg包是否被锁定,以及如何通过这些查询来识别并...

    oracle常见的锁查询和处理

    Oracle提供了多种视图来监控和管理锁,如`v$transaction`、`v$lock`、`v$enqueue_locks`和`v$session`。这些视图可以帮助识别导致锁冲突的会话信息,查看引起冲突的SQL语句,以及定位被锁定的数据对象。例如,通过`v...

    oracle中关于死锁的处理

    SELECT * FROM V$DB_OBJECT_CACHE WHERE OWNER = 'LLTRADE' AND LOCKS != '0'; ``` - 这条语句用于找出特定模式下的所有已锁定对象。 3. **获取会话信息** - 查询`V$SESSION`与`V$PROCESS`表可以得到会话的...

    快速查找oracle锁对象

    1. **使用V$SESSION和V$LOCK视图**:Oracle提供了一些动态性能视图,如V$SESSION和V$LOCK,它们可以显示当前会话的锁信息。通过查询这些视图,我们可以找到持有或等待锁的会话ID,以及锁的具体类型和状态。 2. **...

    oracle_manage_sql.rar_oracle

    Oracle提供了`V$LOCKED_OBJECT`和`DBA_LOCKS`视图来查看锁定信息。要查看当前被锁定的表,可以使用: ```sql SELECT object_name, lock_type, session_id, session_serial# FROM v$locked_object JOIN dba_...

    oracle存储过程解锁

    通过查询`dba_ddl_locks`和`v$session`视图,再结合`ALTER SYSTEM KILL SESSION`命令,可以有效地解除存储过程的锁定状态,恢复数据库的正常运行。 总结来说,解锁Oracle存储过程的过程涉及到识别锁定会话、查询...

    oracle锁表及解锁

    Oracle中的锁主要有两种类型:表级锁(Table Locks)和行级锁(Row Locks),分别由`TM`和`TX`标识。表级锁通常用于DML操作或DDL操作,而行级锁则是在执行更新、插入或删除等操作时自动产生的。 #### 检查锁定情况 ...

    oracle dba 常用语句

    - `oracle的连接数查看和连接用户的查看.sql`: 查询V$SESSION视图可以获取数据库的连接数和活跃用户信息。 5. **锁与并发控制** - `查看系统锁.sql`: 使用DBA_LOCKS或V$LOCK视图来查看当前的锁定信息,帮助诊断...

    oracle 锁问题

    FROM v$lock L1, v$session S1, v$lock L2, v$session S2 WHERE S1.SID = L1.SID AND S2.SID = L2.SID AND L1.BLOCK = 1 AND L2.REQUEST &gt; 0 AND L1.ID1 = L2.ID1 AND L2.ID2 = L2.ID2; ``` 这个查询结果将清楚地...

    oracle由于对象被锁住无法编译处理

    2. **查找锁定会话**:利用`V$SESSION`和`V$LOCKED_OBJECT`视图,可以找到导致对象锁定的会话ID。 ```sql SELECT s.sid, s.serial#, lo.object_name FROM v$session s, v$locked_object lo WHERE s.saddr = lo....

    Oracle锁 图例

    1. 表级锁:Oracle中的表级锁主要有两种,即排他锁(Exclusive Locks, X locks)和共享锁(Shared Locks, S locks)。排他锁允许一个用户修改表中的数据,而共享锁则允许多个用户同时读取表,但不允许任何写操作。 ...

    Oracle事务、锁表查询及相关实用查询SQL语句

    其中`v$locked_object`视图存储了锁定对象的信息,`v$session`视图提供了会话详情,而`dba_objects`视图则包含了Oracle数据库中所有对象的信息。 2. **查看SQL语句的执行情况**: ```sql SELECT /*+ORDERED*/ sql...

Global site tag (gtag.js) - Google Analytics