Solved

cancel execution of very slow update query

Posted on 2013-12-17
4
573 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

820 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