How to kill all active and inactive oracle sessions for user

后端 未结 6 903
北海茫月
北海茫月 2021-01-30 14:30

I am trying the below script to kill all active and inactive oracle sessions for user at once but it doesn\'t work. The script executes successfully but does not kill sessions f

6条回答
  •  被撕碎了的回忆
    2021-01-30 14:54

    BEGIN
      FOR r IN (select sid,serial# from v$session where username='user')
      LOOP
          EXECUTE IMMEDIATE 'alter system kill session ''' || r.sid  || ',' 
            || r.serial# || ''' immediate';
      END LOOP;
    END;
    

    This should work - I just changed your script to add the immediate keyword. As the previous answers pointed out, the kill session only marks the sessions for killing; it does not do so immediately but later when convenient.

    From your question, it seemed you are expecting to see the result immediately. So immediate keyword is used to force this.

提交回复
热议问题