LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   AIX (https://www.linuxquestions.org/questions/aix-43/)
-   -   Killing oracle user process from OS directly ! (https://www.linuxquestions.org/questions/aix-43/killing-oracle-user-process-from-os-directly-4175415840/)

shipon_97 07-10-2012 02:46 AM

Killing oracle user process from OS directly !
 
I am using Oracle 10g on AIX 6.1 . I want to kill the oracle session who are already INACTIVE for the last 25 minutes.
For this reason I run the below query :

select 'kill -9 '||spid " " from v$process where addr in(
select paddr from v$session where program like 'frm%'and status='INACTIVE'and last_call_et>1500
and username not in('ABABILFE','ABABILID','ICT_ARIF','INCHEQS','AIBLIT','AUTOCLEARING'));

The output will come like below :

kill -9 167547
kill -9 182974

Now here I need to run the 'kill' command manually .

But I want to run the above two procedures using One script in Linux/AIx environment . so that I can kill the user process
from the OS directly .

Would any experts will help me regarding this issue .. ..

Waiting for kind reply ... ...

cliffordw 07-10-2012 04:26 AM

Hi there,

Firstly I must say that killing Oracle processes in this way is probably not the best approach to take. Secondly, if you must kill these (or any other) processes from the OS, it's always best to try "kill -15" first, to give the process a chance to handle the request gracefully. "kill -9" should only be used in extreme cases, after trying "kill -15".

If you must kill processes in this way, you could run your SQL query via sqlplus in a script, and either redirect the output to a new script, pipe the output to a loop and run the commands one by one, or put xargs to work.

Using the xargs approach, try these steps:
* It's probably easiest to put the SQL into a separate file, say staleprocesses.sql.
* Change the query to select on the PID, without prepending the "kill -9".
* You'll need to set some options to not show unnecessary information, which I'm afraid I can't help you with - haven't used sqlplus in years.
* Run the query as follows, and check that it outputs ONLY the process ids:
Code:

sqlplus username/password @staleprocesses.sql
* Once this works, run the following to actually kill the processes:
Code:

sqlplus username/password @staleprocesses.sql | xrags kill -9
I hope this helps to get you going on a solution.

crabboy 07-11-2012 12:49 PM

Any reason you can't use the alter command within Oracle?

ALTER SYSTEM KILL SESSION #


All times are GMT -5. The time now is 01:07 PM.