Our developer team was testing a code and discovered that the query was stuck in an infinite loop, thus they requested that the long-running session be terminated. Please assist me in finding and terminating a long-running query.
top of page
bottom of page
To kill the long-running session, we must verify it before killing it, below are the steps to verify and kill.
1. Query V$SESSION supplying the username in CAPS for the session you want to terminate:
SELECT SID, SERIAL#, STATUS, SERVER FROM V$SESSION WHERE USERNAME ='USERNAME';
2. Verify the SQL query which you want to terminate
SELECT SES.SID, SES.SERIAL# SER#, SES.PROCESS OS_ID, SES.STATUS, SQL.SQL_FULLTEXT FROM V$SESSION SES, V$SQL SQL, V$PROCESS PRC WHERE SES.SQL_ID=SQL.SQL_ID AND SES.SQL_HASH_VALUE=SQL.HASH_VALUE AND SES.PADDR=PRC.ADDR AND SES.SID=&Enter_SID;
3. Use the below query to kill the session once you're sure about the SID and SERIAL and have received consent from the application team.
ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
"The IMMEDIATE clause does not affect the work performed by the command, but it returns control back to the current session immediately, rather than waiting for confirmation of the kill. "
You may also read further by clicking on the link mentioned below: