Solved

how to kill a session in SQLPlus?

Posted on 2004-04-15
8
5,077 Views
Last Modified: 2012-06-27
hi experts,

I want to put the database in restricted mode and kill then kill user session. How do i kill a user session in SqlPlus?

thanks.
0
Comment
Question by:dodowoman
8 Comments
 
LVL 15

Accepted Solution

by:
ishando earned 20 total points
ID: 10838639
alter system kill session 'sid, serial#';

the values for sid and serial# for the session can be found on the v$session view.

0
 
LVL 8

Expert Comment

by:annamalai77
ID: 10839236
hi there


what ishando has given is right

alter system kill session 'sid,serial';

note sid and serial should come in single quotes

eg. alter system kill session '12,24';

where sid and serail can be found in v$session;

regards
annamalai
0
 
LVL 2

Expert Comment

by:CallumT
ID: 10839483
you don't have to put database in restrict mode to kill a session ?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 5

Expert Comment

by:fmonroy
ID: 10839565
no
0
 
LVL 2

Expert Comment

by:n4nazim
ID: 10839585
Hi,

Killing Oracle Sessions
1/ The SQLPlus Approach
2/ The NT Approach
3/ The UNIX Approach

===============================================================
1/ The SQLPlus Approach
Sessions can be killed from within oracle using the ALTER SYSTEM KILL SESSION syntax.

First identify the offending session as follows:

SELECT s.sid,
       s.serial#,
       s.osuser,
       s.program
FROM   v$session s;
 
       SID    SERIAL# OSUSER                         PROGRAM
---------- ---------- ------------------------------ ---------------
         1          1 SYSTEM                         ORACLE.EXE
         2          1 SYSTEM                         ORACLE.EXE
         3          1 SYSTEM                         ORACLE.EXE
         4          1 SYSTEM                         ORACLE.EXE
         5          1 SYSTEM                         ORACLE.EXE
         6          1 SYSTEM                         ORACLE.EXE
        20         60 SYSTEM                         DBSNMP.EXE
        43      11215 USER1                          SQLPLUSW.EXE
        33       5337 USER2                          SQLPLUSW.EXE
The SID and SERIAL# values of the relevant session can then be substituted into the following statement:

  SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';
In some situations the Oracle.exe is not able to kill the session immediately. In these cases the session will be "marked for kill". It will then be killed as soon as possible. If the marked session persists for some time you may consider killing the process at the operating system level.

===============================================================

2/ The NT Approach
To kill the session via the NT operating system, first identify the session as follows:

SELECT s.sid,
       p.spid,
       s.osuser,
       s.program
FROM   v$process p,
       v$session s
WHERE  p.addr = s.paddr;
 
       SID SPID      OSUSER                         PROGRAM
---------- --------- ------------------------------ ---------------
         1 310       SYSTEM                         ORACLE.EXE
         2 300       SYSTEM                         ORACLE.EXE
         3 309       SYSTEM                         ORACLE.EXE
         4 299       SYSTEM                         ORACLE.EXE
         5 302       SYSTEM                         ORACLE.EXE
         6 350       SYSTEM                         ORACLE.EXE
        20 412       SYSTEM                         DBSNMP.EXE
        43 410       USER1                          SQLPLUSW.EXE
        33 364       USER2                          SQLPLUSW.EXE
The SID and SPID values of the relevant session can then be substituted into the following command issued from the command line:

  C:> orakill sid spid
The session thread should be killed immediately and all resources released.

===============================================================
3/ The UNIX Approach
To kill the session via the UNIX operating system, first identify the session in the same way as the NT approach, then substitute the relevant SPID into the following command:

  % kill -9 spid
If in doubt check that the SPID matches the UNIX PROCESSID shown using:

  % ps -ef | grep ora
The session thread should be killed immediately and all resources released.


HTH
Rgds,
Nazim M
0
 
LVL 1

Expert Comment

by:darshan6
ID: 10859825
hi,

n4nazim has given the right method,
u can follow that

regards
sudarshan
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle function works in 11g but not in 12c 21 72
oracle query help 18 99
Oracle - Stored Procedure Privilge access 3 39
Oracle Next Available Number 2 32
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now