Open 3 Session:
Sql> select Sid from V$mystat where Rownum=1;
Sid ---------- 29
Sql>
Sql> select Sid from V$mystat where Rownum=1;
Sid ---------- 35
Sql>
Sql> select Sid from V$mystat where Rownum=1;
Sid ---------- 38
Sql>
Updating the T-table operation with SessionID 29 Sql> Update T set name= ' QQ ' where id = 2;
1 row updated.
Sql> Query transactions: Select Xidusn,xidslot,xidsqn,status from V$transaction; 5 1099 ACTIVE Indicates that there is currently an active transaction
The following is the transaction information generated by querying a connection of SessionID to 29: Select Sid,type,id1,id2, Decode (lmode,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Lock_mode, Decode (request,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Request_mode,block From V$lock where sid=29;
SID, TYPE, ID1, ID2, Lock_mode, Request_mode, BLOCK AE 0 Share None 0 TM745850 Row Exclusive None 0//table-level lock TX 327710 1099 Exclusive None 0//row-level lock The SID indicates that Sessionid,type represents the type of lock, ID2 indicates the number of times the transaction slot is overwritten, and the information in ID1 contains two kinds of information: 1. Transaction table 2. Rows in a transaction table Pass: Disassemble the ID1 Select Trunc (327710/power (2,16)) as Undo_blk#,bitand (327710,to_number (' ffff ', ' xxxx ') + 0 as slot# from dual; undo_blk#, slot#5 30//shows the information of the transaction, which also shows that ID1 represents two kinds of information. Lock_mode represents the mode of the lock, request_mode whether the lock is requested, block indicates which transaction is lockedSelect Owner,object_name,object_id,object_type,created,last_ddl_time,status,namespace from Dba_objects where OBJECT _id=74585;//Locked Object OWNER, object_name, object_id, Object_type, CREATED, Last_ddl_time, STATUS, NAMESPACE SYS t 74585 t ABLE 2 February-December-14 April-January -15 VALID 1 for TM locks, ID1 indicates that objects that are locked are ID,ID2 always 0 For a TX lock, ID1 represents the rollback segment number used by the transaction and the corresponding record number in the Transaction table, ID2 indicates the number of times the record number has been reused (wrap) Update t table operation using SessionID for 35:sql> update T set name= ' WW ' where id = 2; No execution results are locked. The following is the transaction information generated by querying SessionID for connections of 29, 35: Select Sid,type,id1,id2, Decode (lmode,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Lock_mode, Decode (request,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Request_mode,block From V$lock where SID in (29,35) Order by Sid; SID, TYPE, ID1, ID2, Lock_mode, Request_mode, BLOCK29 TM 74585 0 Row Exclusive None 0 AE 0 Share None 0 TX 327710 1099 Exclusive None 1//lock a transaction TM 74585 0 Row Exclusive None 0 AE 0 Share None 0 29 TX 327710 1099 None Exclusive 0//request an exclusive lock, because the top one is locked in a lock. Update t table operation using SessionID for 38:sql> update T set name= ' WW ' where id = 2; No execution results, no indication is locked. Query the V$enqueue_lock to get the session information in the locked queue: Select Sid,type, Decode (request,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Request_mode From V$enqueue_lock where SID in (35,38); SID, TYPE, request_mode35 AE None + AE None TX Exclusive Exclusive TXyou know that the SessionID for 35,38 need to be locked for x lock. Query the relationships between several locks:Select A.sid Blocker_sid,a.serial#,a.username as Blocker_username,b.type, Decode (b.lmode,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Lock_mode, B.ctime as time_held,c.sid as Waiter_sid, Decode (c.request,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ' ) Request_mode, C.ctime time_waited From V$lock B, V$enqueue_lock C, v$session a where A.sid = B.sid and b.id1= c.id1 (+) and B.id2 = C.id2 (+) and c.type (+) = ' tx ' and b.type = ' tx ' and B.block = 1 Order by Time_held, time_waited; Blocker_sid, serial#, Blocker_username, TYPE, Lock_mode, Time_held, Waiter_sid, Request_mode, time_waited 29 55 7 SYS TX Exclusive 2452 Exclusive 274 557 SYS TX Exclusive 2452 Exclusive 712blocker_sid: SessionID of the lock for 29,blo Cker_username: The user name of the lock is sys,type: The type of lock is TX (row-level lock) Lock_mode: The model of the lock is an exclusive lock, Time_held: The duration of the lock is waiter_sid: Which SessionID lock waits for the lock, Request_mode: The type of request lock, time_waited: Request time through the above information can know the lock time held by a connection, if the time is too long to indicate that there is a problem with the connection, you can kill the connection alter system kill session ' 29,557';//The first parameter Blocker_sid, the second is the serial# parameter One transaction modifies multiple rows, resulting in a TX lock Select Sid from V$mystat where Rownum=1; Sql> Update T set name= ' RR ' where id=2;
1 row updated.
Sql> Update T set name= ' RR ' where id=2;
1 row updated.
Sql> Update T set name= ' RR ' where id=2;
1 row updated.
Sql>
Select Sid,type,id1,id2, Decode (lmode,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Lock_mode, Decode (request,0, ' None ', 1, ' Null ', 2, ' Row Share ', 3, ' Row Exclusive ', 4, ' share ', 5, ' Share Row Exclusive ', 6, ' Exclusive ') Request_mode,block From V$lock where sid=38;
SID, TYPE, ID1, ID2, Lock_mode, Request_mode, BLOCK38 AE 0 Share None 0 0 TM 74585 0 Row Exclusive None 327680 TX 1099 Exclusive None 0 The total number of TX locks that can be obtained is determined by the initialization parameter transactions, and the number of TM locks that can be obtained is determined by the initialization parameter dml_locks: Select Name,value from V$parameter where name in (' Transactions ', ' dml_locks ');
NAME, Valuedml_locks 1084 Transactions 271 Querying for Resource usage: Select Resource_name as "R_n", current_utilization as "C_u", max_utilization as "M_u", initial_allocation as "I_u" From V$resource_limit where resource_name in (' Transactions ', ' dml_locks '); R_n, C_u, M_u, I_u dml_locks 1 1 1084 Transactions 1 1 271 The above parameters can be known that the Dml_locks resource is currently using 1 and most of the time only used 1, the largest resource is 1084transactions ibid, through this can determine the resource settings is If the value of M_u equals or is close to I_u, it is necessary to increase the I_u value because the total number of TX locks that can be obtained is determined by the initialization parameter transactions, and the number of TM locks that can be obtained is determined by the initialization parameters Dml_locks |