Sei sulla pagina 1di 5

10/12/2014

howtoresolvea'enq:TXrowlockcontention'event|survivalofthefittest

howtoresolvea'enq:TXrowlockcontention'event
Leaveareply

Senario:twoupdatesessionswereoperatedonthesametable,youwillseeaTXrowlockevent
inthethirdconsolethatonesessionholdtheTXlockresourcewhichotheristryingtorequest.
Normally,therequestercandonothingexceptwaiting,theonlysolutionistorevisetheapplogicon
theresourceholder,letscheckouttheexample.

preparethematerials

DROPTABLEtx_eg;
CREATETABLEtx_eg(numnumber,txtvarchar2(10),sexvarchar2(10))INITRANS1
MAXTRANS1;
INSERTintotx_egVALUES(1,'First','FEMALE');
INSERTintotx_egVALUES(2,'Second','MALE');
INSERTintotx_egVALUES(3,'Third','MALE');
INSERTintotx_egVALUES(4,'Fourth','MALE');
INSERTintotx_egVALUES(5,'Fifth','MALE');
COMMIT

Session#1:
updatetx_egsettxt=Garbagewherenum=1

Session#2:
updatetx_egsettxt=Garbagewherenum=1

DBA#3
selectSID,TYPE,ID1,ID2,LMODE,REQUESTfromv$lockwheretype=TX'
/*displaytheTXlockinfo*/

SQL>selectSID,TYPE,ID1,ID2,LMODE,REQUESTfromv$lockwheretype='TX';

SIDTYID1ID2LMODEREQUEST

147TX52429726106
158TX52429726160
data:text/htmlcharset=utf8,%3Cheader%20class%3D%22entryheader%22%20style%3D%22margin%3A%200px%200px%201.714285714rem%3B%20

1/5

10/12/2014

howtoresolvea'enq:TXrowlockcontention'event|survivalofthefittest

youcansee147isrequestingtheresourceand158istheTXlockresourceholder

select*fromv$lockwheretype=TXandrequest>0
/*displaywhoiswaitingforaTXlock*/
SQL>select*fromv$lockwheretype=TXandrequest>0

ADDRKADDRSIDTYID1ID2LMODEREQUESTCTIMEBLOCK

3043444C30434460147TX5242972610642610

select*fromv$lockwheretype=TXandlmode>0
/*displaywhoisholdingaTXlockandBLOCK=1meansitsblockingasessionwhowantstheTXlock*/

SQL>select*fromv$lockwheretype='TX'andlmode>0;

ADDRKADDRSIDTYID1ID2LMODEREQUESTCTIMEBLOCK

2FA160602FA16084158TX5242972616039881

sid=147istheunluckysessionwhoisblockingandwaitingforTXlock.

selectsid,p1raw,p2,p3,eventfromv$session_waitwherewait_time=0andeventlike%enq%'
/*displaythesidinfoforaenq:TXrowlockcontentionwhoiswaitingfortheTXlockresource*/

SQL>selectsid,p1raw,p2,p3,eventfromv$session_waitwherewait_time=0andeventlike%enq%'

SIDP1RAWP2P3EVENT

14754580006524297261enq:TXrowlockcontention

thisisaenq:TXrowlockcontention,theonlywaytoresolvethisproblemistonotifytheunproper
behaviorofsid=158,commitorrollbackthesession.

youcanusethistoshowsomedetail
//
selectosuser,machine,program,Module,sid,serial#,event,t2.logon_time
fromv$locked_objectt1,v$sessiont2
wheret1.session_id=t2.sidorderbyt2.logon_time

data:text/htmlcharset=utf8,%3Cheader%20class%3D%22entryheader%22%20style%3D%22margin%3A%200px%200px%201.714285714rem%3B%20

2/5

10/12/2014

howtoresolvea'enq:TXrowlockcontention'event|survivalofthefittest

//
selectROW_WAIT_OBJ#,ROW_WAIT_FILE#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#from
v$sessionwheresid=147
/*thewaiteriswaitingforTXlockinordertolockROW_WAIT_ROW
infileROW_WAIT_FILEblockROW_WAIT_BLOCKofobjectROW_WAIT_OBJ
thiscouldbeusedtolocatetheobjectincontention
*/

SQL>selectROW_WAIT_OBJ#,ROW_WAIT_FILE#,ROW_WAIT_BLOCK#,ROW_WAIT_ROW#from
v$sessionwheresid=147
2/

ROW_WAIT_OBJ#ROW_WAIT_FILE#ROW_WAIT_BLOCK#ROW_WAIT_ROW#

5193141440

thesid=147sessionisvisitthe144block#of51931#object.

okletsfigureouttheobjectwhichisincontention

SQL>selectobject_id,object_namefromdba_objectswhereowner=SCOTTandobject_id=51931

OBJECT_IDOBJECT_NAME

51931TX_EG

tableTX_EGofscottwasincontention

afterlocatingtheobjectincontention,youcanfindoutthesessionwhoneedTXlockresource
andmanuallykillitusingaltersystemkillsessionsid,serial#

SQL>selectsid,serial#fromv$sessionwheresid=147

SQL>selectsid,serial#fromv$sessionwheresid=147

SIDSERIAL#

14791
altersystemkillsessionsid,serial#'
data:text/htmlcharset=utf8,%3Cheader%20class%3D%22entryheader%22%20style%3D%22margin%3A%200px%200px%201.714285714rem%3B%20

3/5

10/12/2014

howtoresolvea'enq:TXrowlockcontention'event|survivalofthefittest

//killsessionshouldbeagreedonbydeveloperorwellconsiderated
butthekeytotakeovertheissueistofindouttheimproperlogicoftheTXlockholder

catchthesid=158SQLTEX

//
SELECTSQL_TEXT
FROMv$sqltexta
WHERE(a.HASH_VALUE,a.ADDRESS)IN
(SELECTdecode(sql_hash_value,0,prev_hash_value,sql_hash_value),
decode(sql_hash_value,0,prev_sql_addr,sql_address)
FROMv$sessionb
whereb.sid=&sid
andb.serial#=&serial)

gettheserial#ofsid=158forlocatingthesqltext

SQL>SELECTSQL_TEXT
FROMv$sqltexta
WHERE(a.HASH_VALUE,a.ADDRESS)IN
234(SELECTdecode(sql_hash_value,0,prev_hash_value,sql_hash_value),
decode(sql_hash_value,0,prev_sql_addr,sql_address)
56FROMv$sessionb
whereb.sid=&sid
78andb.serial#=&serial)
9/
Entervalueforsid:158
old7:whereb.sid=&sid
new7:whereb.sid=158
Entervalueforserial:89
old8:andb.serial#=&serial)
new8:andb.serial#=89)

SQL_TEXT

updatetx_egsettxt=Garbagewherenum=1

data:text/htmlcharset=utf8,%3Cheader%20class%3D%22entryheader%22%20style%3D%22margin%3A%200px%200px%201.714285714rem%3B%20

4/5

10/12/2014

howtoresolvea'enq:TXrowlockcontention'event|survivalofthefittest

data:text/htmlcharset=utf8,%3Cheader%20class%3D%22entryheader%22%20style%3D%22margin%3A%200px%200px%201.714285714rem%3B%20

5/5

Potrebbero piacerti anche