Oracle Tuning - Kill Long running SessionsIdentifying Long-Running Sessions : There are several methods to identify long-running sessions in Oracle:
WE TAKE THREE TERMINAL
STEP 1 : Create Two Tables & Add Values : create table tesdb1(id int,name varchar2(20)); create table tesdb2(id int,name varchar2(20)); begin for i in 1 .. 10000 loop insert into tesdb1 values(i,i); end loop; commit; end; / PL/SQL procedure successfully completed. begin for i in 1..10000 loop insert into tesdb2 values(i,i); end loop; commit; end; / SQL> commit; Commit complete. SQL> select count(*) from tesdb1; COUNT(*) ---------- 10000 SQL> select count(*) from tesdb2; COUNT(*) ---------- 10000STEP 2 : Select The Table Using Join : SQL> select a.name,b.name from tesdb1 a inner join tesdb2 b on a.id<>b.id;Open another terminal check the top command Top ![]() SQL> select addr from v$process where spid=8813; ADDR ---------------- 0000000065D653B8 SQL> select sql_id from v$session where paddr='0000000065D653B8'; SQL_ID ------------- 131n5bxcwmkgp SQL> select sql_text from v$sql where sql_id='131n5bxcwmkgp'; SQL_TEXT -------------------------------------------------------------------------------- select a.name,b.name from tesdb1 a inner join tesdb2 b on a.id<>b.id SQL> SELECT sid, serial#, sql_id, status from v$session where sql_id='131n5bxcwmkgp'; SID SERIAL# SQL_ID STATUS ---------- ---------- ------------- -------- 237 31657 131n5bxcwmkgp INACTIVEKill the Session : Once you have identified the session to be terminated, use the ALTER SYSTEM KILL SESSION statement. Replace sid and serial# with the values from the identified session. SQL> ALTER SYSTEM KILL SESSION '237,31657'; System altered. SQL>The following error will come in first terminal : ERROR: ORA-00028: your session has been killed 27848235 rows selected. Verify Termination : After executing the ALTER SYSTEM KILL SESSION statement, you can check whether the session has been successfully terminated by querying the v$session view. « Previous Next Topic » (Oracle Tuning - Improve performance on DMLs) |