 |
|
How to kill an Oracle process on Windows
Oracle Database Tips by Donald BurlesonOctober 20, 2015
|
Question: I'm used to
the "kill -9" syntax in UNIX for killing an Oracle process, but
I don't know how to kill an Oracle process on Windows.
Answer: In
Windows Server, we have several options for killing processes.
In UNIX, we can simply issue a kill -9 to kill a running
process. In Windows, it is not always that
straightforward!
We have the ability to use
several methods to kill a process, and many will depend on the
circumstances. For example, we can use the Task Manager
for jobs we have direct permissions on, and then use the Task
Manager called by the at command to kill any others. We
can also kill a process from the command line using the taskkill
or orakill commands. Lastly, we can delete a stuck Windows
Service by finding the process ID using the sc queryex and then
using taskkill.
As a quick
review, you can kill an Oracle session from within Oracle, but
that does not always terminate the OS process. First, you
get the SID and serial number of the session that you want to
kill:
select
spid,
osuser,
s.program
from
v$process p,
v$session s
where
p.addr=s.paddr;
Next, you kill the session from
inside SQL*Plus:
alter system mill session 'mysid,
myserial_no';
You can also invoke the
dbms_sql.kill_session procedure to kill a Windows
session from inside Oracle.
Also see
Kill stuck Windows service using sc queryex and taskkill
Killing a Windows Task
In Windows we have several
utilities, the Oracle-centric "orakill"
utility and the Windows "taskill" program. The Windows
command to kill this session would be as follows.
C:\oracle9i\bin>orakill
ORCL92 768
In this example, the windows thread corresponding to the Oracle
session can be killed in the operating system without ever
logging into the database.
You can also use the Windows
taskkill utility to remove an Oracle Windows process:
c:>tasklist
oracle.exe 9311 Console 0 5,072 K
c:>taskkill /pid 9311
SUCCESS: The process with PID 9311 has been terminated.
Using the Windows Task Manager to Kill a Process
The simplest way to delete a process, if you can tell which you want to
delete, is by using the Task Manager. In the example seen in Figure
9.1, the cmd.exe process is highlighted and then End Process is clicked.
That will kill the process, as long as we have permissions to it.

Figure 9.1
However, sometimes the process you need to kill is running under another
user's credentials and Task Manager will not allow you to kill it.
There is a solution. If you recall from the chapter on Batch Jobs, we
learned that the at command submits jobs as the system user. Here we
use that to our advantage.
To kill a job regardless of owner, we
simply open a command prompt and submit a Task Manager process to start
interactively within the next few minutes.
For example, if it is
9:58am and we need to do this, we tell it to start at 10am (2 minutes
later).
C:\> at 10:00 /interactive
taskmgr.exe
When 10:00am arrives, a Task Manager window will
pop up on your screen, running as System. From there you will have
full permissions to kill any process you need to.
Killing Processes Using taskkill
The way you delete processes from the command prompt is to use the
taskkill command. The syntax is:
C:\> taskkill /PID
So, for example, to delete process ID 223, you would type:
C:\> taskkill /PID 223
The process
ID can be had from using the tasklist command.
|
 |
|
Windows for the Oracle DBA
The landmark book
Windows for the Oracle DBA is a comprehensive overview of
everything an Oracle DBA needs to know to manage Oracle on
Windows. Order directly from Rampant and save 30%.
|
|
See my related notes on killing
Oracle processes here:
|