Solved

cancel execution of very slow update query

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle 12c patching 1 87
Oracle and DateTime math 6 39
oracle RMAN - trying to duplicate a database 5 30
Email query results in HTML 6 20
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
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…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

803 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