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.