Kill several session

Hello

There are 100 sessions are active in the database, which is the best way to kill all the session using a single query.

is it possible or not?

Yes, with a bit of Pl/Sql, something like this (connected as SYS)

SQL> declare
  2     str varchar2(100);
  3  begin
  4     for S in (select sid,serial# from v$session where username is not null
  5         and username != 'SYS')
  6     loop
  7         str := 'alter system kill session '||chr(39)||S.sid||','||S.serial#||chr(39);
  8         execute immediate str;
  9     end loop;
 10  end;

Tags: Database

Similar Questions

  • It is safe to kill idle session?

    Hello
    Recently working on the production environment I've met customer number of connection problem as follows

    sqlplus username/password

    SQL * more: release 9.2.0.4.0 - Production Wed Feb 25 15:46:31 2004

    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

    ERROR:
    ORA-00020: maximum number of processes (%s) exceeded


    After trying several times I connected and identified about 250 idle sessions of the only user of view V$ session.
    I have questions about this scenario.

    (1) I guess that inactive session consume processes, that triggered this error. Please correct me if I'm wrong.
    (2) is it safe to kill these idle without the approval of customers sessions because their status says they are 'INACTIVE '?
    (3) if not then, when idle, do these sessions are certain activities of long durations and because of their laziness oracle mark as inactive?

    My apologies for being naïve... :) Thanks in advance...

    Ashish payet wrote:

    (2) is it safe to kill these idle without the approval of customers sessions because their status says they are 'INACTIVE '?

    Yes - in a perspective of database instance. Oracle is very robust. It does not choke when a user session suddenly disappear.

    Course from the point of view of the customer? Not really. The client may always require this session - it may even have a unique transaction to validate.

    From a point of view s/n? Joy. Let me count the ways of contentment by waving the old lead pipe and killing sessions... ;-)

    (3) if not then, when idle, do these sessions are certain activities of long durations and because of their laziness oracle mark as inactive?

    You can watch the session $ v and that there should be a column that contains the current state of waiting for event time / elapsed (take a look at the Oracle Reference guide). If this wait state is SQL * Net client message or similar and the wait state has quite a long time (you set this number), then it would be wrong to kill the session in order to allow new.

    Another option is looking at shared server sessions. Here is the light weight in comparison to the server by default. For example a sessions 100 user may be services by 2 dispatchers and 10 shared - server process that oppose an almost 10 x more charge of a 100 process heavy process.

  • How to kill the session running from work processes

    How to kill the session work processes running... What is the process to be programmed

    BEGIN
      FOR c IN (
      SELECT s.sid,
      s.serial#
      FROM v$session s
      WHERE s.username = 'your_user_name'
      )
      LOOP
      EXECUTE IMMEDIATE 'alter system kill session ''' ||
      c.sid || ',' || c.serial# || '''';
      END LOOP;
    END;

  • kill all sessions owned by a user


    Hi guys

    can someone help me with the script to kill all sessions belong scott username in a database.

    Thank you all in advance

    Hello

    There you go

    create or replace procedure kill_sessions(p_username varchar2) is
    begin
      for rec in (select 'ALTER SYSTEM KILL SESSION ''' || sid || ', ' || serial# || '''' txt from v$session where username=p_username) loop
          execute immediate rec.txt;
       end loop;
    end;
    /
    

    Best regards

    Nikolai

  • Who killed my session and when?

    Hi gurus,

    Could you tell me how can I check which killed my session and when two days before? Which table should I interview?

    Any input will be appreciated.


    Thank you.

    H_innocent wrote:
    Hi gurus,

    Could you tell me how can I check which killed my session and when two days before?

    You can't unless you have auditing enabled for ALTER SYSTEM.

    Which table should I interview?

    There is no table to the query, unless you already had the above verification enabled. In this case, see SYS. AUD$.

    Hope that helps,

    -Mark

  • How to kill a session

    Hello

    Can you please give me a consultant how to kill a session?

    Thanks in adv
    SA

    Hello

    Pls find out with this query...! and use edit commond to kill a session.

    SELECT s.inst_id,
           s.sid,
           s.serial#,
           p.spid,
           s.username,
           s.program
    FROM   gv$session s
           JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
    WHERE  s.type != 'BACKGROUND'
    
    Kill session
    ************
    
    ALTER SYSTEM KILL SESSION 'sid,serial#@inst_id';
    

    KPR

  • Why can't I kill this session?

    DB version: 10.2.0.4
    Operating system: Solaris SPARC (5.10)
    Number of nodes of CARS: 2



    I wanted to kill the session that was connected to the Instance 2 below.
    So, I first connected to instance1 tried running the command below.


    -Connected to Instance1
    SQL:orcl1 > ALTER SYSTEM KILL SESSION '586,53926,@2' IMMEDIATE;
    ALTER SYSTEM KILL SESSION '586,53926,@2' IMMEDIATE
    *
    ERROR at line 1:
    ORA-00026: missing or invalid session ID
    Tried running of instance2 and succeeded after removing the part of ID of Instance of KILL command

    -Connected on Instance2 from the
    SQL:orcl2 > ALTER SYSTEM KILL SESSION '586,53926,@2' IMMEDIATE;
    ALTER SYSTEM KILL SESSION '586,53926,@2' IMMEDIATE
    *
    ERROR at line 1:
    ORA-00026: missing or invalid session ID
    
    
    SQL:orcl2 > ALTER SYSTEM KILL SESSION '586,53926' immediate;
    
    System altered.
    I can't kill a session connected to Instance2 from the 1st Instance using the syntax
    ALTER SYSTEM KILL SESSION 'sid,serial,@inst_id' IMMEDIATE;
    ?

    Hello

    session function kill via. another instance introduced with 11 GR 1 material.

    If this does not work in 10.2

    Concerning
    Sebastian

  • How to kill a session by the non privileged user

    Hello

    I use the oracle 10.2.0.3 version.

    I have to give privileged kill session to a user non-preferred, below 2 ways, I know that this can be done with.

    1. by giving change the system to this user privilege.

    2. by creating a procedure in any user with DBA privileges, which has the statement to execute immediate change the system kill session & by granting execute this procedure to this user.

    Apart from the above two ways, I heard that there is a procedure/priviledge etc. also well integrated into Oracle. Which can be granted to individual users.

    No idea if there is something of this kind?


    Thanks in advance.

    Best regards
    Oratest

    Each session has a partner gets server process created in OS that Oracle creates (the setting of the dedicated server), so if you kill even the session in Oracle and the corresponding operating system process is not killed, then the session is marked for KILL and do not get killed instantly or marked as snipped.

    Also, there is no explicit privilege in Oracle to grant only the ability to kill session, you will need to ALTER SYSTEM privilege and, of course, it gives you much more capacity than to simply kill the session and therefore impossible to give all users who does not keep a database.

  • How to kill the session during the export of data from the database in essbase

    Hi all

    I actually tried to export all the data for essbase DB but it takes almost 25 hrs still his past.
    Please suggest me how to kill this session. I tried to kill him but his does not work...

    Really appreciate if somebody gives answer for that...

    Thank you...

    Me...

    Your only option is to go to the Task Manager/Unix command line and kill the ESSSVR.exe process. This process is blocked and all of the demolitions that you issue of EAS/MaxL won't fix.

    Kind regards

    Cameron Lackpour

  • kill v$ session.

    HelloW everyone.

    I'm looking for help as how to kill v$ session using oracle forms?
    any help or if there is no FMB please any help would be greatly appreciated.

    Tic Tac Toe

    Tic Tac Toe,

    Try,

    SELECT UTL_INADDR.GET_HOST_ADDRESS(NVL(TERMINAL, MACHINE)) IP_ADDRESS, LOGON_TIME, STATUS FROM V$SESSION WHERE SID = 
    

    Kind regards

    Manu.

  • kill the session.

    Hi all

    I want to kill session through Toad. What someone has knowledge of the toad that how to kill session from there?
    I was using my form if the cause of something its closed and my user is still active then cany help me how to kill the session or active users?

    Thanks in advance.

    Sarah

    You must have DBA privileges to perform this activity.

    using toad, click Session browser, expand the program to the title of the list of programs, select the process; on the top of the page, click Kill (cross icon)

    HTH...

  • Kill a session caused instance bouncing

    Our database is 2 CARS db knots. The version is 10.2.0.3. The database servers are windows 2003 servers. Recently, I tried to kill a session using 'alter system kill session..' to kill a user session but caused the corresponding instance bounced. I created a TAR with Oracle and downloaded alert logs, trace files and files of $ORACLE_HOME/log / < name of the node - > /racg directory. But Oracle has not found anything to explain why the instance was restarted. He said that I may have killed an Oracle background process. My questions are:

    (1) can you use command 'alter system kill session..' to kill Oracle process? If you can that happen if you had killed a? Just cause the instance to stop and start?
    (2) I tried to find the session that I killed in gv$ active_session_history, but they are too old for exist. I was wondering is there anywhere I found this kind of info.

    Thanks a lot for your help.

    Shirley

    I don't think that you can kill a background session with ALTER SYSTEM:

    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    
    SQL> select sid, serial#, program from v$session where program like '%SMON%';
    
           SID    SERIAL# PROGRAM
    ---------- ---------- ------------------------------
            43          1 ORACLE.EXE (SMON)
    
    SQL> alter system kill session '43,1';
    alter system kill session '43,1'
    *
    ERROR at line 1:
    ORA-00029: session is not a user session
    

    But you can always kill with a command to the operating system:

      1  select spid, osuser, s.program
      2  from v$process p , v$session s
      3  where p.addr=s.paddr
      4* and s.sid=43
    SQL> /
    
    SPID         OSUSER
    ------------ ------------------------------
    PROGRAM
    ----------------------------------------------------------------
    2620         Système
    ORACLE.EXE (SMON)
    
    SQL> exit
    Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Produ
    ction
    
    C:\>orakill 
    
    Usage:  orakill sid thread
    
      where sid    = the Oracle instance to target
            thread = the thread id of the thread to kill
    
      The thread id should be retrieved from the spid column of a query such as:
    
            select spid, osuser, s.program from
            v$process p, v$session s where p.addr=s.paddr
    
    C:\>orakill XE 2620
    
    Kill of thread id 2620 in instance XE successfully signalled.
    
    C:\>sqlplus / as sysdba
    
    SQL*Plus: Release 10.2.0.1.0 - Production on Tue Feb 23 18:47:12 2010
    
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    
    Connected to an idle instance.
    

    -Online Forum was killed. Alert log says:

    Tue Feb 23 18:47:10 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_pmon_2512.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:10 2010
    PMON: terminating instance due to error 474
    Tue Feb 23 18:47:10 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_q001_3208.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:10 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_ckpt_2580.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:11 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_dbw0_2556.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:11 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_lgwr_2572.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:12 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_reco_2652.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:12 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_mman_2540.trc:
    ORA-00474: SMON process terminated with error
    
    Tue Feb 23 18:47:12 2010
    Errors in file c:\oraclexe\app\oracle\admin\xe\bdump\xe_psp0_2520.trc:
    ORA-00474: SMON process terminated with error
    
    Instance terminated by PMON, pid = 2512
    

    Edited by: P. Forstmann on 23 Feb. 2010 18:50

  • Kill the Session procedure file

    Hello

    I want to develop a process where the user can shoot session by themselves.

    Currently I use the following script to kill all idle sessions.

    If I try to create a procedure and pass in the form, it gives me an error

    EXECUTE IMMEDIATE does not work.

    Set serveroutput on

    declare

    sqlStmt VARCHAR2 (1000);

    BEGIN

    For x in (SELECT SID, SERIAL # FROM V$ SESSION WHERE STATUS = 'INACTIVE' AND last_call_et > 300) loop

    sqlStmt: = ' EDIT the SYSTEM KILL SESSION "' | X.SId | «, » || X.Serial # | " ' ;

    dbms_output.put_line (sqlStmt);

    EXECUTE IMMEDIATE sqlStmt;

    End loop;

    end;

    Sandy

    Dear SPathak ,

    Try to add IMMEDIATE too in the KILL statement. So the code will be

    declare
         sqlStmt VARCHAR2(1000);
    BEGIN
         For x in (SELECT SID,SERIAL# FROM V$SESSION WHERE STATUS='INACTIVE' AND last_call_et > 300) loop
              sqlStmt := 'ALTER SYSTEM KILL SESSION ''' || X.SId || ',' || X.Serial# || ''' IMMEDIATE' ;
              dbms_output.put_line( sqlStmt );
              EXECUTE IMMEDIATE sqlStmt;
         End loop;
    end;
    

    Manu.

  • What is the best practice for managing for results in doubles because of several sessions

    I work with PowerCLI 5.0.  I quite often find that I have a few sessions open at the same time connected to a server that hosts a particular virtual machine and vCenter.  I ran into a problem when I tried the cmdlet Add-USBController of VMware vSphere PowerCLI Reference book.

    The following lines are (roughly) in the extract cmdlet of the book:

    $vmView get - vm 'test ' | Get-View

    $vmView.ReconfigVM_Task ($spec)

    I got the following error "method call failed because [System.Object []] contains a method named"ReconfigVM_Task"" etc.

    It turns out that I was getting an array of vmViews for 'test' (instead of one), because I had a connection to the host and vCenter.  Once I deleted the host sessions, the script worked well.

    So now my question - what is the best way to mitigate this in my scripts? At least, I guess I need to make sure that I received only an object in the view of the GET. should I remove all duplicates? kill all other sessions when I run the script?

    Thank you

    Maureen

    The best method is to use the server parameter on cmdlets where it is available, in this way, you can limit the objects returned to this server for vSphere.

    If you have multiple sessions on the same server from vSphere open, you could direct the result of a Select-Object cmdlet.

    Like this

    Get-VM-name MyVM-Server $vcenter | Select - 1 first

  • Users connect in several sessions, even if they are not allowed to...

    Does anyone know what would cause the SAME user to log on multiple sessions even if we do not allow several connections in our environment from view?

    We've seen a lot with view 4.6.1 and sometimes with View 5.1.1.

    According to me, the question is the desktop VM is selected for the user by the broker is busy doing something (100% CPU) and Agent of the view in the virtual machine is unable to process the request of the broker in a timely. I believe that the broker gives up after a few seconds of no response from the officer and then selects another available office.

    So if the user disconnected from their office and then come back later, but their office has a blocked process in a loop and using 100% of CPU, the agent has a hard time getting back to the broker for the broker gives up and chooses another office.

    Desktop computers that we use are WinXP SP3 with 1 vCPU and 2 GB of ram.

Maybe you are looking for