Solved

how to kill a session in SQLPlus?

Posted on 2004-04-15
8
5,055 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
no
0
 
LVL 2

Expert Comment

by:n4nazim
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Suggested Solutions

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

762 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

7 Experts available now in Live!

Get 1:1 Help Now