Thursday 30 May 2013

Kill oracle session process in linux and windows platforms

Kill oracle session process in linux and windows platforms :
In various critical situations Oracle DBA has to decide to kill existing session or kill the background process of Oracle database. At this moment remote Oracle DBA should need to terminate session/process called as termination of session of any instance.

If you want kill or terminate process using only operating system command only.How can you kill process in Unix?

In linux and unix :


We can check running processes in Unix and Linux using "ps" command. We are able to get process id from said command.

$ps -ef|grep ora_|grep -v grep 

Now use "kill" command with "-9" syntax to kill process id as given below example.kill command with -9 for ensure not blocking command and surity if execution of "kill" command.

$kill -9 1451

In Windows oracle kill cmd :


For using ORAKILL utility we should need process id from sqlplus. ORAKILL utility is shipped with Oracle software itself. When we install Oracle software same time ORAKILL also is being installed in ORACLE_HOME\bin folder. It can kill process same as "kill -9" command in Unix/Linux. But one drowback of this utility that is we need process id using sqlplus and from v$process,v$session data dictionary views as follows.

SQL> select a.username, b.spid from v$session a, v$process b where a.paddr = b.addr and a.username ='SCOTT';

USERNAME SPID.
-------- ----
SCOTT 1456 

Now we can kill server process of 1456 of scott user using ORAKILL utility from command line of Windows as follows.

C:\> orakill instance_name spid

Example
C:\> orakill orcl 1456

We will get following message in our command prompt of windows.
"Kill of thread id 1456 in instance ORCL successfully signalled[sic]."

In Windows task kill cmd :


But if sometime SQL*Plus doesn't working like database stuck or instance hang situation. We need to terminate Oracle instance. But we are unable to execute command using SQL*Plus "shutdown abort" or our shutdown abort command also stuck in Windows. Then how can we terminate instance? Yes, we can restart instance service from service menu. But if we want to use only command line then how to terminate instance or kill instance or background process.

We can use TASKKILL command for terminating instance. Using tasklist command we can get thread id of Oracle.exe and using TASKKILL command we can terminate or kill instance in command line as follows.

C:\>tasklist 
Image Name PID Session Name Session# Mem Usage
=============== ======== ======== ============
System Idle Process 0 Console 0 16 K
oracle.exe 1456 Console 0 282,100 K
smss.exe 636 Console 0 420 K 

C:\>taskkill /pid 1456 /T 


Best of luck.

Thanks & Regards,

Suresh R
oracle dba.

No comments:

Post a Comment