Solved

cancel execution of very slow update query

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

627 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