Solved

cancel execution of very slow update query

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

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  â€¦
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 explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now