UKOUG, Oracle Transaction Locks

download UKOUG, Oracle Transaction Locks

of 78

  • date post

    26-Jan-2015
  • Category

    Technology

  • view

    108
  • download

    3

Embed Size (px)

description

 

Transcript of UKOUG, Oracle Transaction Locks

  • 1. Enqueue Waits : Locks Thanks to Doug Burns for much of the Row Lock example Kyle Hailey Kylehailey.com kyle@delphix.com

2. Oaktable World UK Mon Dec 2, Tues Dec 3 3. Who is Kyle Hailey 1990 Oracle 90 support 92 Ported v6 93 France 95 Benchmarking 98 ST Real World Performance 2000 Dot.Com 2001 Quest 2002 Oracle OEM 10gSuccess! First successful OEM design 4. Who is Kyle Hailey 1990 Oracle 90 support 92 Ported v6 93 France 95 Benchmarking 98 ST Real World Performance2000 Dot.Com 2001 Quest 2002 Oracle OEM 10g 2005 Embarcadero DB Optimizer 5. Who is Kyle Hailey 1990 Oracle 90 support 92 Ported v6 93 France 95 Benchmarking 98 ST Real World Performance2000 Dot.Com 2001 Quest 2002 Oracle OEM 10g 2005 Embarcadero DB Optimizer DelphixWhen not being a Geek - Have a little 4 year old boy who takes up all my time 6. Production InstanceDatabaseFile system File systemQAUATInstanceInstanceInstanceDatabaseDatabaseDatabaseFile system File systemFile system File system File systemFile system File systemDevelopment 7. Production InstanceDatabaseFile systemDevelopmentQAUATInstanceInstanceInstanceDatabaseDatabaseDatabase 8. AWR Method Who/WhenSummaryTop 5 Timed Events ~~~~~~~~~~~~~~~~~~ % for Load profile goodTotal Event Waits having a (s) Call Time Time feel for the ---------------------- ------------ application and ----------- --------buffer busy waits 2,748 250 78.72 comparing two 10.16 CPU time 32 periods for changes free buffer waits 1,588 15 4.63 Efficiency 8 ratios 2.51 write complete waits 10 log buffer space 306 misleading carry 1.51 5 ---------------------------------------- 6 over from versiondaysWaitsBig Picture 9. Row Locks 10g+ Top 5 Timed Events Avg %Total ~~~~~~~~~~~~~~~~~~ wait Call Event Waits Time (s) (ms) Time ----------------------------------------- ------------ ----------- ------ -----enq: TX - row lock contention 59 160 2714 41.8 PL/SQL lock timer 4 117 29291 30.6 CPU time 28 7.2 buffer busy waits 1,217 18 15 4.7 log file parallel write 422 11 27 3.0Who is waiting? Who is blocking? What is the SQL? What is the row?Not in AWR report 10. Power of ASH ! v$active_session_history Waiter SESSION_ID SESSION_SERIAL# USER_IDObject CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK#SQL Waiting - SQL_IDBlocker - BLOCKING_SESSION - BLOCKING_SESSION_STATUS - BLOCKING_SESSION_SERIAL#Lock Type and Mode - Event = Type (name) - P1 = Type | Mode 11. Content Part I : Row Locks enq: TX - row lock contention Data in ASH OEM V$lock & v$session ASH Find blocking SQLPart II : Row Locks ?? enq: TX - row lock contention, mode 4Part III : Other TX locks enq: TX - allocate ITL entry enq: TX - index contention enq: TX contentionPart IV : TM locks 12. Lock Types 9i One Wait : enqueue10gTX TM Transaction Table Modification 208 enqueue waits Specific to each type of enqueue select name,wait_class from v$event_name where name like 'enq%' enq: enq: enq: enq: enq: enq: enq: enq: enq: enq:HW SQ SS ST TM TW TX TX TX TXcontention contention contention contention contention contention allocate ITL entry index contention row lock contention contentionConfiguration Configuration Configuration Configuration Application Administrative Configuration Concurrency Application Application 13. Lock Modes # Type --- ------1 Null 2 SS 3 SX 4 S 5 SSX 6 XName --------------------------Null Sub share Sub exclusive Share Share/sub exclusive Exclusive 14. Lock Type and Mode Select parameter1 from v$event_name where name like enq%; Parameter1 ---------Name|mode Select p1, p1raw from v$session where event like 'enq%';P1 P1RAW ---------- -------1415053318 54580006Name: 5458 Hex Decimal 54 = 84 58 = 88ASCII = T = XMode: 0006 Lock = TX 6 15. Type and Mode SELECT SELECT chr(bitand(p1,-16777216)/16777215)|| chr(bitand(p1,-16777216)/16777215)|| chr(bitand(p1, 16711680)/65535) chr(bitand(p1, 16711680)/65535) TYPE, TYPE, mod(p1,16) LMODE mod(p1,16) LMODE from v$session from v$session where event like enq%; where event like enq%; TY LMODE TY LMODE -- ----------- ---------TX 6 TX 6 16. enq: TX - row lock contention, mode 6 To Solve we need, and ASH gives :1. Waiter 2. Blocker 3. Blocking Object 4. Lock Type type Mode1. Blocking SQL : Missing 1.Log miner? 2.Undo ? 17. OEM 10gif P1 = 1415053318 then mode = 6 Then it is a data block row lock 18. enq: TX - row lock contention Mode 6, row in data block User 1 SQL> delete from toto where id = 1;User 2SQL> delete from toto where id =1; Table ID Value foo 1 19. Querying ASH select substr(event,0,20) ash.session_id mod(ash.p1,16) ash.p2 ash.p3 o.object_name o.object_type CURRENT_FILE# CURRENT_BLOCK# ash.SQL_ID BLOCKING_SESSIONlock_name, waiter, lmode, p2, Meaning varies p3, object, otype, filen, blockn, waiting_sql, blockerfrom v$active_session_history ash, all_objects o where event like 'enq: %' and o.object_id (+)= ash.CURRENT_OBJ# /http://ashmasters.comAny enqueue 20. Other Data Sources In real time can also use v$lock v$session (v$session_wait) dba_blockers dba_waiters ?/rdbms/admin/utllockt.sql http://www.evdbt.com/enqwaits.sql 21. Step one: get a lock Session 1 Session_1> select pk_id from test_tab1 where rownum=1 ; PK_ID --------------4051 select pk_id from test_tab1 where pk_id = 4051 for update; 22. Step 2: create a blocker Session 2 Session_2> select pk_id from test_tab1 where pk_id = 4051 for update;Hangs 23. Step 3: release the lock and blocking Session 1 Session_1> commit; Commit complete.Session 2 now continues PK_ID ---------4051 24. Locks in OEM:Application Wait clickOne SQLOne Session 25. Click on ApplicationClick on SQL ID 26. Click on SQLSQL waits for lock gets lock and does I/O to complete 27. Click on Session IDClick on Session ID 28. No info is lock is goneLimited Use : lock is already released 29. Session Before Lock released ClickBlocker Holds lockWaiter 30. ASH data in EM, but missing blocking infoBLOCKING_SESSION_STATUS BLOCKING_SESSION BLOCKING_SESSION_SERIAL# 31. v$lock & v$session during lock wait SQL> select s.sid, s.state, s.event, s.sql_id, l.type, l.lmode 2from v$session s, v$lock l3where s.sid = l.sid4and s.username='TESTUSER'5order by s.sid;SID STATE(+)EVENTSQL_IDTY LMODE---------- ----------- -------------------------------- ------------- -- ----150 WAITINGenq: TX - row lock contention0ut22yp7mh229 TM3150 WAITINGenq: TX - row lock contention0ut22yp7mh229 TX0157 WAITINGSQL*Net message from clientTX6157 WAITINGSQL*Net message from clientTM3Blocker Idle, holds locksWaiter, wants locks 32. v$lock : after commit by Session 1 SQL> select s.sid, s.state, s.event, s.sql_id, l.type, l.lmode 2from v$session s, v$lock l3where s.sid = l.sid4and s.username='TESTUSER'5order by s.sid;SID STATE(+)EVENTSQL_IDTY LMODE---------- ----------- -------------------------------- ------------- -- ----150 WAITINGSQL*Net message from clientTM3150 WAITINGSQL*Net message from clientTX6157 WAITINGSQL*Net message from clientNon-blocking, idleHolds Locks 33. v$active_session_history during and after SQL> select a.sample_time, a.session_id, a.event, a.session_state, a.blocking_session BSID, a.blocking_session_status BSTATUS from v$active_session_history a, dba_users u where u.user_id = a.user_id and u.username = 'TESTUSER'; TIME -------14.59.37 14.59.36 14.59.35 14.59.34 14.59.33 14.59.32 14.59.31 14.59.30 14.59.29SID --150 150 150 150 150 150 150 150 150STATE ------ON_CPU ON_CPU WAITING WAITING WAITING WAITING WAITING WAITING WAITINGa.sql_id,EVENT SQL_ID BSID BSTATUS ----------------------------- ------------- ---- -----------0ut22yp7mh229 NOT IN WAIT 0ut22yp7mh229 NOT IN WAIT db file scattered read 0ut22yp7mh229 NO HOLDER db file scattered read 0ut22yp7mh229 NO HOLDER enq: TX - row lock contention 0ut22yp7mh229 157 VALID enq: TX - row lock contention 0ut22yp7mh229 157 VALID enq: TX - row lock contention 0ut22yp7mh229 157 VALID enq: TX - row lock contention 0ut22yp7mh229 157 VALID enq: TX - row lock contention 0ut22yp7mh229 157 VALIDWhere is the BLOCKER, 157, info in ASH ?NowPast 34. V$active_session_history SQL> select a.sample_time, a.session_id, a.event, a.session_state, a.blocking_session BSID, a.blocking_session_status BSTATUS from v$active_session_history a, dba_users u where u.user_id = a.user_id and u.username = 'TESTUSER'; TIME 22.23.59 22.23.58 22.23.57 22.23.56 22.23.55 22.23.33 22.23.32 22.23.31 22.23.30SID 147 147 147 147 147 148 148 148 148STATE ON CPU WAITING WAITING WAITING WAITING WAITING WAITING WAITING WAITINGSESSION_ID + SESSION_SERIAL# a.sql_id,EVENT enq: TX enq: TX enq: TX enq: TX db file db file db file db file- row lock contention - row lock contention - row lock contention - row lock contention scattered read scattered read scattered read scattered readSQL> select sql_text from v$sql where sql_id='cda14zb83bb5u; sql_id='cda14zb83bb5u; SQL_TEXT -------------------------------------------------------------------------------select count(*) from test_tab1NOTE: Is uniqueSQL_ID BSID BSTATUS 0ut22yp7mh229 NOT IN WAIT 0ut22yp7mh229 148 VALID 0ut22yp7mh229 148 VALID 0ut22yp7mh229 148 VALID 0ut22yp7mh229 148 VALID cda14zb83bb5u NO HOLDER cda14zb83bb5u NO HOLDER cda14zb83bb5u NO HOLDER cda14zb83bb5u NO HOLDER 35. How do we find the SQL that took the lock? 36. Session B update toto set update toto set name = ADAMS name = ADAMS where id = 1; where id = 1;TX Lock Wait for Tx To commitUndo Segment HeaderRedoTable Toto Data Block Data Block Header Header Transaction 1 Session a Row 1Undo Segmentupdate toto set update toto set name = SMITH name = SMITH where id = 1; where id = toto where id Delete from 1; Delete from toto where id = 2; = 2; Delete from toto where id Delete from toto where id 37. Logminer : setup SQL> select group#, thread#, status from v$log; GROUP# THREAD# STATUS ---------- ---------- ---------------1 1 CURRENT 2 1 ACTIVE 3 1 ACTIVE SQL> select group#, member from v$logfile; GROUP# ---------1 2 3MEMBER ------------------