How to kill a running SELECT statement

前端 未结 6 1846
南笙
南笙 2020-11-28 04:51

How can I stop a running SELECT statement by killing the session?

The command is continuously giving me output based on the SELECT statement, I want to stop it in be

6条回答
  •  情深已故
    2020-11-28 05:35

    This is what I use. I do this first query to find the sessions and the users:

    select s.sid, s.serial#, p.spid, s.username, s.schemaname
         , s.program, s.terminal, s.osuser
      from v$session s
      join v$process p
        on s.paddr = p.addr
     where s.type != 'BACKGROUND';
    

    This will let me know if there are multiple sessions for the same user. Then I usually check to verify if a session is blocking the database.

    SELECT SID, SQL_ID, USERNAME, BLOCKING_SESSION, COMMAND, MODULE, STATUS FROM v$session WHERE BLOCKING_SESSION IS NOT NULL;  
    

    Then I run an ALTER statement to kill a specific session in this format:

    ALTER SYSTEM KILL SESSION 'sid,serial#'; 
    

    For example:

    ALTER SYSTEM KILL SESSION '314, 2643';
    

提交回复
热议问题