Oracle database locks enqueue
Today i receive a monitor alert about some locks in one of the databases i manage, so i run this query because is faster than traditional queries based in v$lock view:
SQL> SELECT * FROM dba_waiters where MODE_HELD <>'None' or MODE_REQUESTED <>'Share'; WAITING_SESSION HOLDING_SESSION LOCK_TYPE MODE_HELD MODE_REQUESTED LOCK_ID1 LOCK_ID2 --------------- --------------- -------------------------- ---------------------------------------- ---------------------------------------- ---------- ---------- 398 336 Transaction Exclusive Share 327692 9591040 397 336 Transaction Exclusive Share 327692 9591040 394 336 Transaction Exclusive Share 327692 9591040 373 336 Transaction Exclusive Share 327692 9591040 347 336 Transaction Exclusive Share 327692 9591040 333 336 Transaction Exclusive Share 327692 9591040 316 336 Transaction Exclusive Share 327692 9591040 294 336 Transaction Exclusive Share 327692 9591040 293 336 Transaction Exclusive Share 327692 9591040 242 336 Transaction Exclusive Share 327692 9591040 201 336 Transaction Exclusive Share 327692 9591040 197 336 Transaction Exclusive Share 327692 9591040 194 336 Transaction Exclusive Share 327692 9591040 172 336 Transaction Exclusive Share 327692 9591040 88 336 Transaction Exclusive Share 327692 9591040 57 336 Transaction Exclusive Share 327692 9591040 13 336 Transaction Exclusive Share 327692 9591040 17 rows selected.
As you can see SID=336 is root blocking
So client ask me to kill this session so i killed it by doing..
SQL> SELECT SID, SERIAL#, STATUS, SERVER FROM V$SESSION WHERE SID=336; SID SERIAL# STATUS SERVER ----- ---------- ---------- --------- 336 40580 ACTIVE DEDICATED
An after get needed info to kill session i killed it:
SQL>ALTER SYSTEM KILL SESSION '=336,40580'; Statement processed.
but this session is still running due a rollback is performing... this is because when a DML is launched, Oracle makes changes to the table immediately, even if you don't commit. Old blocks are write to UNDO till you commit or rollback.
This method is good if you commit the transaction, but if you rollback, blocks have to be written back to the base table.. So, for example, imagine you have been running a DML for an hour and after that you do a rollback, then all writes to the datafiles makes during that hour must to be written back again from UNDO tablespace to original datafiles..
column SID format 9999 column SPID format 9999999 column USERNAME format a15 column PROCESS format 99999 column MACHINE format a15 column PROGRAM format a55 column STATUS format a10 col LOGON_TIME for a27 select S.INST_ID,S.SID, P.SPID, S.USERNAME, S.MACHINE, S.PROGRAM, S.STATUS, to_char(LOGON_TIME, 'Dy DD-Mon-YYYY HH24:MI:SS') LOGON_TIME from gv$session S, gv$process P where P.addr=S.paddr and S.INST_ID=P.INST_ID and S.SID=336;SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> SQL> INST_ID SID SPID USERNAME MACHINE PROGRAM STATUS LOGON_TIME ---------- ----- ------------ --------------- --------------- ------------------------------------------------------- ---------- --------------------------- 1 336 22569 ORA_app hostname02 serverSDM@hostname02 (TNS V1-V3) KILLED Fri 29-Sep-2017 17:04:18
So after kill session, we can see it running on database in killed status...
Comments
Post a Comment