Database Oracle UNIX

Killing a hung instance

Although you should never kill an Oracle instance from the OS but instead cleanly shut it down, sometimes that is just not possible. Sometimes there is just no option but to kill all the running processes.
This might sound like a daunting task, one instance can have hundreds of processes running against it. But it can actually be quite simple.

Using a combination of the ps, nawk and xargs commands we can kill any process fitting a certain description.
In the example below I list all the processes (ps -ef) then search for any contain the word apache2 (nawk ‘/apache2/), I then print only the second item on each line (print $2) and then pass that to the kill command using xargs.
# ps -ef | nawk '/apache2/ { print $2 }' | xargs -i kill -9 {}
Of course you would need to replace apache2 with something that uniquely identifies the instance you want to kill. I would suggest testing your search by using grep, like this:
# ps -ef | grep apache2
Make sure that lists the instance you want to kill, and only that instance, then use that search criteria between the / in the nawk command.
Good luck!
NOTE : On some systems you might have to use awk instead of nawk. But they do basically the same thing.