Documente Academic
Documente Profesional
Documente Cultură
--------------------------
Author JP Vijaykumar
Date Jan 27th 2009
Modified Jan 29th 2009
/*
One of my procedure is taking long time to complete. I want to kill my job and
re-run the procedure after incorporating HINTS.
/*
I checked the status of my session, and it says 'KILLED',
but still the procedure is running.
*/
1 row selected.
/*
I want to kill the job at the os level.
*/
/*
I found the process id of my job and executed the kill command at os level.
*/
kill -9 159
/*
Then I wondered, why should I go through this hasle to kill my procedure.
Is there a simple way to stop my long running procedure?
I created a flag_jp table with one column flg that hold either 'YES' or 'NO'.
At regular intervals, during the run of my procedure, after committing a certain
number of rows, I check the flg value from my flag_jp table.
If the flg value is 'NO' then I simply exit out of the execution of my procedure.
*/
declare
v_num number(10):=0;
v_flg char(3);
/***********************************
create table scott.flag_jp(flg char(3));
begin
v_num:=v_num+1;
end if;
exception
when others then
dbms_output.put_line(c1.rowid||' '||sqlerrm);
end;
end loop;
end;
/*
After every 1000 rows processed, my procedure checks the flg column value
from the flag_jp table. If the flg value is set to 'NO', then my procedure
stops execution.
Remember, the procedure stops after the current 1000 rows are processed and
committed.
You can change the number of rows processed, in the counter, for change of control
in procedure.
You can incorporate a while loop and update the flg value during every run, if you
like.
*/
#!/usr/bin/ksh
#This script checks for the existence of stop_file in the current directory.
#As long as the file is not found. The script runs.
#When you touch a file with the name stop_file, the execution of the script stops
#touch stop_file
cd /home/oracle/jp
while [ true ]
do
date
ls -ltr
if [ -f stop_file ]; then
exit
fi
sleep 300
done
exit
/*
To stop this shell script run the command
touch /home/oracle/jp/stop_file
No need to find my script's pid
and execute a kill -9 <pid> command.
*/
Happy scripting.
References: http://www.oracle-base.com/articles/misc/KillingOracleSessions.php