I’m not sure why, but it appears many of you wish you could take back your SQL queries. It’s like that one time you posted that picture on Facebook and immediately (3 days later) you realized it wasn’t a great career move.
Maybe that data you asked for wasn’t going to be that helpful if it took 3 hours for it to come back. This reminds me of the weather forecasting models can that could be perfect but would take years to run…anyway I’m digressing way too early already.
You run query.
You want to cancel the query.
In fact, you want it to DIE, DIE, DIE!
Let me help you kill yoursel…your query.
You open connection. You submit query. We send it to the database for you. A few moments later, you change your mind and hit the ‘Cancel’ button. We let the database know you changed your mind. Maybe the database hears you and maybe it cancels the query.
It’s the ‘maybe’ part that frustrates people.
Or maybe the client sees the query as cancelled but you still see the server process (PID) running on the server. This is also alarming to folks. PMON is responsible for doing the clean-up there. That’s kind of out-of-scope for this post, but I’m going to say it’s out of the client’s (SQL Developer’s) hands. So let’s get back to the actual query being cancelled.
1. Use the Results Panel Cancel Button
Hitting this button will send the cancel request to the database. The button will activate once something’s running in the worksheet.
2. Using the Task Progress Panel
You might have stuff running in a few different worksheets and editors. You can monitor the progress of all of them using this panel. Open it from the View menu.
3. Open Monitor Sessions and Kill the Session
Find your SID, select the row, right-click, and ‘Kill Session.’ I’ve heard about folks that will just telnet into the server and issue an OS ‘kill XXXX’ to make their session go away, but I don’t recommend this as anything but a last-resort option. Let the database handle the session if at all possible, otherwise be ‘OK’ with the results.
But Why Won’t My Cancel Work?
The database is coded to listen for cancel requests in various places. Apparently for JDBC connections, it’s not listening in as many places as you may like. But, there’s a ‘fix!’
Update for Version 4 and Higher
We’ve made it easier to specify EXACTLY what Oracle HOME (client) to use for your SQL Developer connections. Read more about that here.
Anyways, once you have this sorted, start a new connection, and if you have a compatible Oracle Client on your machine, we’ll use the Oracle Call Interface (OCI) via the ocijdbc driver. Now, one of the few advantages here is that there are MORE ‘listen’ points in the database code for query cancellation requests. I’ve suggested this route for many of our users, and it seems to have done the trick for all of them.
Also, don’t forget to use ‘unshared worksheets‘ if you’re about to run a hairy query – it will run on a dedicated connection and let you use the rest of the tool without holding you up whilst you wait for it to finish.