Solved

cancel execution of very slow update query

Posted on 2013-12-17
4
638 Views
Last Modified: 2014-01-02
i am running an update query -query1  from sqlplus command prompt
that query is taking long it s running since 3 hours  

so i want to cancel/stop that query and rerun another update query that updates the same column as query1 is updating and which is faster than query1...  
so is it ok if i just cancel execution of query1 using Ctrl-C (more than 1 time if required)
and rerun the new query which is faster?
Or
do i have to contact dba to cancel previous transactions or how do i quit running query1

please help thanks a lot
0
Comment
Question by:at999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:David
David earned 200 total points
ID: 39725139
It depends :)

The common case is that another user has a lock on the table(s) you are querying.  Unless you are watching your session's I/O consumption increase...  Depending upon your Oracle version, try and report back the results:

select event,p1,p2,p3 from sys.v$session_wait
     where wait_time=0 and event='enqueue';

But if you are working in a distributed environment (three-tier web service, for example), a control-C is not going to do the wonderful stuff we remember from client-server days.

You (or your DBA) would find and kill the offending session by its id.
0
 

Author Comment

by:at999
ID: 39725158
i am the only one who runs update queries on that table and i have one session opened in toad which just runs sql select queries
and other one in sqlplus from command prompt which i am trying to cancel... pl help
0
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 300 total points
ID: 39725215
OK, in that case you would safe to "kill" the session running the update.  Oracle doesn't offer us a convenient "cancel" command, especially from outside of the session running the update.  That application may (or may not) support using [Ctrl]-c to try to cancel an update that appears to be stuck.

If that doesn't work, your only options to cancel it are:
1. Do an "alter system kill session ..." command from SQL*Plus
2. Do a database shutdown, and restart.

Note that following either of these commands, there may be some time required for Oracle to rollback the uncommitted portion of the update that had been processed.

Here are the commands I use in SQL*Plus to identify, then "kill" a session.  Either copy these lines into a *.SQL file then run that file from the SQL> prompt, or copy these lines into SQL*Plus directly:

column sid format 9999;
column serial# format 9999999;
column "Logon" format a13;
set verify off;
select s.sid, s.serial#, nvl((select p.spid from v$process p where p.addr = s.paddr),'  ?') "Spid",
substr(s.osuser,instr(s.osuser,'\') +1,14) "OsUser", to_char(s.logon_time,'YYMMDD HH24MISS') "Logon"
from v$session s where s.username = upper('&username')
order by s.logon_time, s.sid;
--
Prompt Enter the "SID" and "SERIAL#" values to cancel a session...
alter system kill session '&SID,&SERIAL' immediate;
0
 
LVL 23

Assisted Solution

by:David
David earned 200 total points
ID: 39725289
Side thoughts:  even if you're developing/testing, it's prudent to add a I/O upper limit to your (default) user profile.  IOW, auto-kill a session that churns out of control.

The kill above should work cleanly.  You have the back-door option to force a SHUTDOWN on the instance if necessary.  With a query, having no redo logs, a shutdown force is feasible.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question