Terminating Sessions

来源:互联网 发布:如何做淘宝客赚钱 编辑:程序博客网 时间:2024/06/06 12:57
Terminating Sessions

当一个会话被终止时,该会话所有的事务会被回滚,相应的资源(locks memory areas)也会立即被释放。
sql statement :alter system kill session '7,15';
    

1.确定哪些会话需要终止
   SELECT SID, SERIAL#,STATUS
  FROM V$SESSION
  WHERE USERNAME = 'JWARD';

SID   SERIAL#   STATUS
-----  --------- --------   
        15    ACTIVE  
12        63    INACTIVE


 ACTIVE   --》making a SQL call to Oracle Database.
INACTIVE  --》 not making a SQL call to thedatabase  


2.干掉session
    alter systemkill session '7,15';

注意:An active session cannot be interrupted when it is performingnetwork I/O or rolling back a transaction. Such a session cannot beterminated until the operation completes. In this case, the sessionholds all resources until it is terminated.



Additionally, the
session that issues the  ALTER SYSTEM statement toterminate a session waits up to 60 seconds for the session to beterminated. If  the operation that cannot beinterrupted continues past one minute, the issuer ofthe  ALTER SYSTEM statement receives a messageindicating that the session has been marked to be terminated. Asession marked to be terminated is indicated in V$SESSION with astatus of  KILLED  and a serverthat is something other than  PSEUDO 。


3.干掉an Inactive Session

SELECT SID,SERIAL#,STATUS,SERVER
   FROM V$SESSION
   WHERE USERNAME ='JWARD';

SID   SERIAL#  STATUS    SERVER
-----  -------- ---------  ---------
         15  INACTIVE  DEDICATED
  12       63  INACTIVE  DEDICATED
2 rows selected.

ALTER SYSTEM KILL SESSION '7,15';
Statement processed.



确定下session 是否已经被kill了

SELECT SID, SERIAL#, STATUS, SERVER
   FROM V$SESSION
   WHERE USERNAME ='JWARD';

SID   SERIAL#  STATUS    SERVER
-----  -------- ---------  ---------
         15 KILLED    PSEUDO
  12       63  INACTIVE  DEDICATED
2 rows selected.

                                 
原创粉丝点击