Friday, 22 June 2018

Resolving Dead lock issue and Killing multiple sessions in oracle database

Monitor the trace file for below error:

ORA-00060: Deadlock detected. See Note 60.1 at My Oracle Support for Troubleshooting ORA-60 Errors. More info in file /oracle/product/diag/rdbms/hot122perf/hot122perf/trace/hot122perf_ora_26193.trc.

Check the /oracle/product/diag/rdbms/hot122perf/hot122perf/trace/hot122perf_ora_26193.trc. trace file for which sessions and queries are responsible for the dead lock.

Check the below points.

Deadlock graph:
                                          ------------Blocker(s)-----------  ------------Waiter(s)------------
Resource Name                             process session holds waits serial  process session holds waits serial
TM-00062F19-00000000-00000000-00000000         71    2277    SX        36708      95    2289    SX   SSX  49586
TM-00063099-00000000-00000000-00000000         95    2289    SX        49586      71    2277           S  36708


*** 2019-11-05T21:26:05.452192+05:30
dbkedDefDump(): Starting a non-incident diagnostic dump (flags=0x0, level=1, mask=0x0)
----- Error Stack Dump -----
----- Current SQL Statement for this session (sql_id=az44vw2mszpxa) -----
UPDATE  APPLTTRN partition (P_20191105211342) SET PART_ID='P_20191105212303' WHERE PART_ID='P_20191105211342' AND SRN='126783894839000012' AND ROW_ID='301770296'
----- PL/SQL Stack -----
----- PL/SQL Call Stack -----
  object      line  object
  handle    number  name
0xe5a3f8f0        77  procedure DB2PB847.APP_WINDW_FILTER
0xd1930c80         1  anonymous block



Run the below command to check which session is blocking and which session to be killed.
-------------------------------------------------------------------------------------
select username,machine,osuser,blocking_session,sid,serial#,
wait_class,seconds_in_wait from v$session
where blocking_session is not null order by blocking_session;


To get only sid and serial# of blocking session.

------------------------------------------------
select sid,serial# from v$session where blocking_session is not null;


To kill the blocking session
----------------------------
alter system kill session 'SID,SERIAL#' immediate;

To kill multiple sessions in one go
-------------------------------------------
 set heading off
spool killmultiple.txt

SELECT 'ALTER SYSTEM KILL SESSION '||''''||sid ||','|| serial#||''''||' immediate;'
 FROM v$session
 WHERE status ='INACTIVE' and type != 'BACKGROUND';

spool off

Run the spooled script.

@killmultiple.txt

No comments:

Post a Comment