Killing a oracle session

Hi,
I run a oracle query which has gone to deadlock.now i want to kill that session because it's happening frequently.How can i kill my own oracle process without needed DBA privs.
Regards
Anand

Do not confuse between deadlock and hang.
See the difference.
Here a deadlock :
Session 1:
SCOTT@demo102> select empno, ename from emp25;
     EMPNO ENAME
      7369 SMITH
      7499 ALLEN
      7521 WARD
      7566 JONES
      7654 MARTIN
      7698 BLAKE
      7782 CLARK
      7788 SCOTT
      7839 KING
      7844 TURNER
      7876 ADAMS
     EMPNO ENAME
      7900 JAMES
      7902 FORD
      7934 MILLER
14 rows selected.
SCOTT@demo102> begin
  2                update emp25 set ename = 'TEST' where empno=7369;
  3                dbms_lock.sleep(10);
  4                update emp25 set ename = '2' where empno=7499;
  5            end;
  6  /
PL/SQL procedure successfully completed.
SCOTT@demo102> Session 2:
SCOTT@demo102> l
  1  begin
  2      update emp25 set ename = 'TEST' where empno=7499;
  3      dbms_lock.sleep(10);
  4      update emp25 set ename = '2' where empno=7369;
  5* end;
SCOTT@demo102> /
begin
ERROR at line 1:
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at line 4
SCOTT@demo102> As you can see above, there is no wait, neither of both session hang, so you don't need to kill one of them.
Here a hang session :
Session 1:
SCOTT@demo102> update emp25 set ename = 'TEST' where empno=7369;
1 row updated.
SCOTT@demo102> Session 2:
SCOTT@demo102> update emp25 set ename = 'TEST' where empno=7369;=> Wait event (commit/rollback) from session 1.
If user which is owner of session1 go at home, session 2 will wait all the week-end.
You need a third session to unblock situation :
SYS@DEMO102> DECLARE  
  2     CURSOR lcobj_cur IS
  3        select session_id
  4        ,      oracle_username
  5        ,      os_user_name
  6        ,      object_id obj_id
  7        ,      locked_mode
  8        from   V$LOCKED_OBJECT;
  9       
10     CURSOR obj_cur(p_obj_id IN NUMBER) IS
11        select owner||'.'||object_name object_name
12        ,      object_type
13        from dba_objects
14        where object_id = p_obj_id;
15     l_sid    number;
16     l_serial number;
17  BEGIN
18     DBMS_OUTPUT.PUT_LINE(RPAD('Sid',5)||
19                          RPAD('Serial',8)||
20                          RPAD('O-User',10)||
21                          RPAD('OS-User',10)||
22                          RPAD('Owner.Object Name',45)||
23                          RPAD('Object Type',35));
24 
25     DBMS_OUTPUT.PUT_LINE(RPAD('-',1,'-')||
26                          RPAD('-',1,'-')||
27                          RPAD('-',6,'-')||
28                          RPAD('-',6,'-')||
29                          RPAD('-',41,'-')||
30                          RPAD('-',31,'-'));
31 
32     FOR lcobj IN lcobj_cur
33     LOOP
34        FOR obj IN obj_cur(lcobj.obj_id)
35        LOOP
36           select distinct sid, serial# into l_sid, l_serial from v$session where sid= lcobj.session_id;
37           DBMS_OUTPUT.PUT_LINE(RPAD(lcobj.session_id,5)||
38                                RPAD(l_serial,8)||
39                                RPAD(lcobj.oracle_username,10)||
40                                RPAD(lcobj.os_user_name,10)||
41                                RPAD(obj.object_name,45)||
42                                RPAD(obj.object_type,35));
43        END LOOP;
44     END LOOP;
45  END;
46  /
Sid  Serial  O-User    OS-User   Owner.Object Name                            Object Type
147  121     SCOTT     INKASHI\AdSCOTT.EMP25                                  TABLE
152  18      SCOTT     INKASHI\AdSCOTT.EMP25                                  TABLE
PL/SQL procedure successfully completed.
SYS@DEMO102>
SYS@DEMO102> select /*+ ORDERED */
  2     blocker.sid blocker_sid
  3  ,  blocked.sid blocked_sid
  4  ,  TRUNC(blocked.ctime/60) min_blocked
  5  ,  blocked.request
  6  from (select *
  7        from v$lock
  8        where block != 0
  9        and type = 'TX') blocker
10  ,    v$lock            blocked
11  where blocked.type='TX'
12  and blocked.block = 0
13  and blocked.id1 = blocker.id1
14  /
BLOCKER_SID BLOCKED_SID MIN_BLOCKED    REQUEST
        152         147           4          6
SYS@DEMO102>
SYS@DEMO102> alter system kill session '152,18';
System altered.
SYS@DEMO102> Then session1 will be disconnected :
SCOTT@demo102> select * from emp25;
select * from emp25
ERROR at line 1:
ORA-00028: your session has been killed
SCOTT@demo102> And session2 can continue his work :
1 row updated.
SCOTT@demo102> select * from emp25;
     EMPNO ENAME      JOB              MGR HIREDATE        SAL       COMM
    DEPTNO
      7369 TEST       CLERK           7902 17/12/80       8000
        20
...Hope this help,
Nicolas.

Similar Messages

  • How to kill particular Oracle Session from the multiple Session of User

    Hi,
    I am working on Web Application using ASP.NET , C# with Oracle. I am excuting queries from multiple connection of same user. I want to kill particular user session. I have tried to Kill session by using ALTER SYSTEM KILL SESSION 'sid,serial#' it is working fine but how can i identify which session is generated by particular connection so that i can kill that particular session.
    Suppose there us user 'abc' there are multple instance of this user and all are active but same USERNAME. So Please tell me how can i identify that session through which i am executing the query.
    Thanks,
    Nitin

    Some ideas for how to pick the right session:
    -Look at the time the session was connected (logon_time)
    -Look at the time the session last started it's most recent statement (last_call_et)
    -Look at the sql that the session is running (join with sql_address and sql_hash_value over to v$sqltext_with_newlines or one of the other views that show you the sql they are running)
    That usually gets me most of the way, if it's possible to distinguish them. ("Yeah I just started this query and I want you to kill it." is different than "I started five different queries at about the same time and I'm not sure which one I need killed.")

  • Kill all oracle session

    Situation:
    Oracle Forms 9i application, with multiple oracle forms (MDI). When I call a new forms I use OPEN_FORM(v_cm_module, ACTIVATE, session, pl_id) so I create a new oracle session.
    Problem:
    The user open a lot of windows (oracle forms .fmx with diferent sessions each one) in the oracle forms application, when they close the browser window (X botom of the browser, mozilla, internet explorer), the session are still alive (only kill one session....the first I think).
    I know that after 15 minutes oracle kill the rest of the sessions, but if the user was editing a block (locking a record), and close the browser, the table still lock 15 minutes!!!!.
    Any sugestions:???
    Thanks

    Is it necessary to create a session for each form?
    If so you could do the following:
    in the formsweb.cfg set the seperateframe property on true; and place some JavaScript code into the htmlafterform property:
    HTMLafterForm=<script type="text/javascript"> window.moveTo(-10000, -10000); </script>
    now you have a seperate frame, the browser window gets moved to a position where you can't see it ;-). when clicking the X button in the seperate frame the current form will be closed; your MDI application is still running...if you wan't you can write a JavaBean, and get the windowlisteners of the seperate frame and replace them with your own...of course you can close the Browser by right clicking and closing it in the taskbar; but that's a thing you must live with...
    besides that I have no clue how to get rid of those sessions, as I don't you have any event you can act with when closing the Browser. But if so you could save every sid in every when-new-form-instance trigger (you can get it from v$mystat), and when this event occurs you could kill all those sessions (alter system kill session ....) ;-). but as far as I know that's not possible...
    regards
    christian

  • How to kill concurrent request oracle session which is terminated

    Dear,
    In our production environment Concurrent request "Gather Schema Stats" was running 2 days. Hence we cancelled the request.
    Request completed as terminated status. Unfortunately the oracle session of that concurrent request went to "Killed" status. Still utilizing CPU resource.
    If we try, "alter system kill session 'SID,serial#';"
    it gives below message,
    ERROR at line 1:
    ORA-00031: session marked for kill
    Could you please provide steps to kill this oracle session.
    Instance detail:
    Oracle Applications R12.1
    Oracle database 11.1.0.7
    Thanks,
    ...basha
    Edited by: 913932 on Jun 25, 2012 2:32 AM

    In our production environment Concurrent request "Gather Schema Stats" was running 2 days. Hence we cancelled the request.
    Request completed as terminated status. Unfortunately the oracle session of that concurrent request went to "Killed" status. Still utilizing CPU resource.
    If we try, "alter system kill session 'SID,serial#';"
    it gives below message,
    ERROR at line 1:
    ORA-00031: session marked for killTry "alter system kill session 'SID,serial#' immediate".
    Could you please provide steps to kill this oracle session.Concurrent Processing - How to Find Database Session & Process Associated with a Concurrent Program Which is Currently Running. [ID 735119.1]
    Thanks,
    Hussein

  • How to kill oracle session?

    hi there,
    Aside from using tool like TOAD is there a syntax on how to kill oracle session?
    pls help.
    tnx...

    First findout the SID, Serial No for the Particular Session ( syntax is as follows )
    SELECT sid, serial#,osuser, program FROM v$session;
    (Killing the session on SQL Prompt)
    ALTER SYSTEM KILL SESSION 'sid,serial#';
    force to kill the session by adding IMMEDIATE
    ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
    OS Oracle Kill Session
    First findout the SID, SPID for the Particular Session ( SQL syntax is as follows )
    SELECT s.sid,p.spid, s.osuser ,s.program
    FROM v$process p, v$session s
    WHERE p.addr = s.paddr;
    Windows OS Command for kill Session
    orakill SID SPID
    Regs,
    Naresh

  • Killing Oracle Sessions

    Please ignore it. By mistakely i posted this thread here.
    Hi All,
    I want to drop one user. If i made a attempt to drop that user, I rec'd "ORA-01940: cannot drop a user that is currently connected." error. So I checked with sessions with the username. No one is using this user. But it resists some inactive sessions.
    SQL> DROP USER test cascade;
    DROP USER test cascade
    ERROR at line 1:
    ORA-01940: cannot drop a user that is currently connected
    SQL>select sid,serial#,username,status from v$session where schemaname='TEST';
    SID SERIAL# USERNAME STATUS
    131 4026 TEST INACTIVE
    143 29325 TEST INACTIVE
    SQL> alter system kill session '131,4026' immediate;
    system altered.
    SQL>alter system kill session '143,29325' immediate;
    system altered.
    SQL> alter system kill session '131,4026' immediate;
    system altered.
    SQL>alter system kill session '143,29325' immediate;
    system altered.
    SQL> alter system kill session '131,4026' immediate;
    system altered.
    SQL>alter system kill session '143,29325' immediate;
    system altered.
    SQL> alter system kill session '131,4026' immediate;
    system altered.
    SQL>alter system kill session '143,29325' immediate;
    system altered.
    Now. I checked in v$sessions,
    SQL>select sid,serial#,username,status from v$session where schemaname='TEST';
    SID SERIAL# USERNAME STATUS
    139 12982 AGILITY_QA INACTIVE
    141 54482 AGILITY_QA INACTIVE
    It shows some other inactive sessions. so i am trying to kill these 2 sessions again some inactive sessions will show.
    Please assist me to fix that problem.
    Message was edited by:
    Moorthy GS

    Try the output of the query to kill all sessions:
    select 'alter system kill session '''||sid||','||'4026''' immediate;' scr
    from v$session
    where schemaname='TEST' and status <> 'KILLED'
    Regards
    RK

  • Old Oracle Session with Tomcat is not kiiling automatically

    Hi,
    I am facing a problem of increasing inactive oracle sessions with tomcat, Old Oracle sessions with tomcat are visible with new one.
    if somebaody did not restarted tomcat gracefully, then does Oracle keep the session connected or is there any way that whenever any one restarted tomcat abnormally, Oracle session can be killed.
    I had restart the database to kill session.

    Could you please tell me that where do i set this parameter in parameter file or sql net file and what is the recommended value, do you have any document on this.
    Another thing tomcat is in other server machine and my database is in different server machine, killing process in tomcat server machine manually may not kill linux process on oracle database machine and therefore oracle sessions are still there.
    Is it possible?
    Edited by: user605066 on 28-Aug-2008 04:59

  • Killing Parallel Query Session

    Hi,
    I am running Oracle 11.2.0.1.0 on Solaris 5.10.
    Couple of hours ago, I ran a job through DBMS_JOB (Yes, I need to use dbms_schedular), and in the job I used parallel query. Now I want to remove the job. Also I want to clean up the sessions. I can remove the job by doing DBMS_JOB.remove(job id). Is there a way that I kill one parallel query coordinator session, and it would automatically kill all the slave sessions?
    Thanks and regards
    Edited by: Fahd Mirza on Apr 22, 2010 11:57 AM

    Thanks for the answer.
    I have run the following query with output:
    SQL> select ps.sid,s.username,ps.qcsid
    from v$session s, v$px_session ps
    where s.sid=ps.sid
    and s.username='BIADM';  2    3    4
           SID USERNAME                            QCSID
            91 BIADM                                 147
           267 BIADM                                 147
           290 BIADM                                 147
           332 BIADM                                 147
           345 BIADM                                 147
            69 BIADM                                 147
            92 BIADM                                 147
           102 BIADM                                 147
           222 BIADM                                 147
           112 BIADM                                 147
            73 BIADM                                 147
           126 BIADM                                 147
           136 BIADM                                 147
           145 BIADM                                 147
           170 BIADM                                 147
           180 BIADM                                 147
           276 BIADM                                 147
           190 BIADM                                 147
           221 BIADM                                 147
           234 BIADM                                 147
           214 BIADM                                 147
           246 BIADM                                 147
           270 BIADM                                 147
           256 BIADM                                 147
           278 BIADM                                 147
           291 BIADM                                 147
           309 BIADM                                 147
           298 BIADM                                 147
           323 BIADM                                 147
           344 BIADM                                 147
             2 BIADM                                 147
           331 BIADM                                 147
           134 BIADM                                  94
           125 BIADM                                  94
           156 BIADM                                  94
           168 BIADM                                  94
           181 BIADM                                  94
           205 BIADM                                  94
           191 BIADM                                  94
           215 BIADM                                  94
           232 BIADM                                  94
           245 BIADM                                  94
           255 BIADM                                  94
           269 BIADM                                  94
           292 BIADM                                  94
           302 BIADM                                  94
           280 BIADM                                  94
           311 BIADM                                  94
           147 BIADM                                 147
            94 BIADM                                  94
    50 rows selected.If I kill sessions with sid 147 and 94, shouldn'it it be killing all the sessions of BIADM?
    REGARDS

  • Java hibernate oracle sessions never get closed

    Hi all,
    I'm opening some Oracle sessions from a java-hibernate app. When a shutdown my java-hibernate the oracle sessions remain opened, even if the java process is not seen as running with "ps -fea | grep java".
    The problem is that this oracle sessions never die, they remain there and the only way to kill them is to either manually kill oracle process, or to restart the oracle instance or to restart the unix box where oracle resides.
    My java/hibernate app always close the session with a final statement in the source code, no matter what.
    Thanks in advanced.

    Hi all,
    I'm opening some Oracle sessions from a java-hibernate app. When a shutdown my java-hibernate the oracle sessions remain opened, even if the java process is not seen as running with "ps -fea | grep java".
    The problem is that this oracle sessions never die, they remain there and the only way to kill them is to either manually kill oracle process, or to restart the oracle instance or to restart the unix box where oracle resides.
    My java/hibernate app always close the session with a final statement in the source code, no matter what.
    Thanks in advanced.

  • URGENT!!! How to kill a SYS session

    What is the command to kill a SYS session? Let's say someone figured out the SYS password and logged in. Now I want to kill the session. What do I do?
    The ALTER SYSTEM KILL SESSION 'SID,SERIAL#' does not work.
    URGENT!!!!

    Hi,
    >>The ALTER SYSTEM KILL SESSION 'SID,SERIAL#' does not work.
    Why not ?
    C:\>sqlplus sys/******* as sysdba
    SQL*Plus: Release 10.1.0.2.0 - Production on Fri Jun 15 17:06:26 2007
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SYS@ORACLE10> SELECT userenv('ISDBA') from dual;
    USEREN
    TRUE
    SYS@ORACLE10> select sid,serial# from v$session where sid=(select distinct sid from v$mystat);
           SID    SERIAL#
           236      22100
    Other session:
    [pre]
    C:\>sqlplus system/*********
    SQL*Plus: Release 10.1.0.2.0 - Production on Fri Jun 15 17:07:02 2007
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    SYSTEM@ORACLE10> alter system kill session '236,22100';
    System altered.
    Back to one ...
    SYS@ORACLE10> select sysdate from dual;
    select sysdate from dual
    ERROR at line 1:
    ORA-00028: your session has been killedCheers

  • MTS, Killing the user session?

    My db is using MTS connection, while i kill the user session by using alter system kill session, the ever killed process goes to Pseudo status....even i can't kill from unix level because it uses dispatchers...
    is there any way i kill the user processes in MTS, with out going to pseduo status

    Hi,
    AS ORACLE SAID,
    If an active session cannot be interrupted (it is performing network I/O or rolling
    back a transaction), the session cannot be terminated until the operation completes.
    In this case, the session holds all resources until it is terminated. Additionally, the
    session that issues the ALTER SYSTEM statement to terminate a session waits up to
    60 seconds for the session to be terminated. If the operation that cannot be
    interrupted continues past one minute, the issuer of the ALTER SYSTEM statement
    receives a message indicating that the session has been "marked" to be terminated.
    A session marked to be terminated is indicated in V$SESSION with a status of
    KILLED and a server that is something other than PSEUDO.

  • Looking for a script to kill all inactive sessions

    Does anyone have a script to kill all INACTIVE sessions (with EXECUTE IMMEDIATE)?

    I suggest you to specify which OS you are talking about.
    The inactive status on the V$SESSION doesn't mean the user is not doing any thing, it only means the oracle server process is not processing any thing by the time it was queried. On OLTP systems Oracle Server Processes remain INACTIVE for more than 95% of the time, so it is advisable to configure shared servers.
    If you are really concerned about idle time, then I suggest you to configure profiles.
    On the pool mechanism you should address the microsoft side, if this, as far as I understood and guessed, application server is IIS.
    I suggest you further reading on the Killing sessions script and different session status (check the sniped status) here:
    Re: session inactive ??
    Re: make a job to delete the sniped sessions
    Re: How do I put a timeout in my DataBase?
    Re: Killing Session with Locks in Linux
    ~ Madrid

  • Script to monitor oracle sessions

    Hi i am looking for a script to monitor oracle sessions......which should find idle sessions which are idle for more than 25 mins and it should be killed...
    is that possible.
    Thanks

    user11278505 wrote:
    Hi i am looking for a script to monitor oracle sessions......which should find idle sessions which are idle for more than 25 mins and it should be killed...
    is that possible.
    ThanksYes it is, use Resource Manager to manage your users,
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/dbrm.htm#ADMIN027
    HTH
    Aman....

  • Killing Duplicate database session

    Hi
    We are running an Oracle 8i database. Remote users logon onto the database. The line drops and they lose connection. When the line is up again, they reconect successfully. However, there are now two sessions for this user. What can I do to identify the older session on the database for users and kill the older session.
    Thanks

    alter system kill session 'sid,serial#';
    alter system kill session '243,14563'; -- USE THIS
    -- find the session from V$session table and kill the session using SID and SERIAL
    -- check the logon_time to find the older sessions
    select sid,serial#,username,terminal,osuser,program,type,status,last_call_et,logon_time
    from V$session
    where type = 'USER'and username not like '%SYS%';
    Hope this will help.
    Regards
    Asif Kabir

  • Unit Testing and Oracle Sessions

    We have an issue regarding Oracle session and SQL Developer Unit Testing.
    Every time we run a Unit Test in SQLDeveloper a new Oracle session is created. When closing that Unit Test, the session, however, is not disconnected.
    And the only way to close that "Unit Test" session is to close SQLDeveloper.
    This is causing problems with the no. of sessions available to developers.
    Any help would be much appreciated.
    Subboss

    The focus of this forum is report design. The actual testing of reports would be subject to your own internal policies and procedures.
    Jason

Maybe you are looking for