Kill Sessions
In some situations, you might want to terminate current user sessions. For example, you might want to perform an administrative operation and need to terminate all non-administrative sessions.
This section describes the various aspects of terminating sessions, and contains the following topics:
When a session is terminated, the session's transaction is rolled back and resources (such as locks and memory areas) held by the session are immediately released and available to other sessions.
Terminate a current session using the SQL statement ALTER SYSTEM KILL SESSION.
The following statement terminates the session whose system identifier is 7 and serial number is 15:
ALTER SYSTEM KILL SESSION '7,15';
Identifying Which Session to Terminate
To identify which session to terminate, specify the session's index number and serial number. To identify the system identifier (sid) and serial number of a session, query the V$SESSION dynamic performance view.
The following query identifies all sessions for the user jward:
SELECT SID, SERIAL#, STATUS
FROM V$SESSION
WHERE USERNAME = 'JWARD';
SID SERIAL# STATUS
----- --------- --------
7 15 ACTIVE
12 63 INACTIVE
A session is ACTIVE when it is making a SQL call to Oracle. A session is INACTIVE if it is not making a SQL call to Oracle.
See Also: for a description of the status values for a session |
Terminating an Active Session
If a user session is processing a transaction (ACTIVE status) when it is terminated, the transaction is rolled back and the user immediately receives the following message:
ORA-00028: your session has been killed
If, after receiving the ORA-00028 message, a user submits additional statements before reconnecting to the database, Oracle returns the following message:
ORA-01012: not logged on
If an active session cannot be interrupted (it is performing network I/O or rolling back a transaction), the session cannot be terminated until the operation completes. In this case, the session holds all resources until it is terminated. Additionally, the session that issues the ALTER SYSTEM statement to terminate a session waits up to 60 seconds for the session to be terminated. If the operation that cannot be interrupted continues past one minute, the issuer of the ALTER SYSTEM statement receives a message indicating that the session has been "marked" to be terminated. A session marked to be terminated is indicated in V$SESSION with a status of KILLED and a server that is something other than PSEUDO.
Terminating an Inactive Session
If the session is not making a SQL call to Oracle (is INACTIVE) when it is terminated, the ORA-00028 message is not returned immediately. The message is not returned until the user subsequently attempts to use the terminated session.
When an inactive session has been terminated, STATUS in the V$SESSION view is KILLED. The row for the terminated session is removed from V$SESSION after the user attempts to use the session again and receives the ORA-00028 message.
In the following example, an inactive session is terminated. First, V$SESSION is queried to identify the SID and SERIAL# of the session, then the session is terminated.
SELECT SID,SERIAL#,STATUS,SERVER
FROM V$SESSION
WHERE USERNAME = 'JWARD';
SID SERIAL# STATUS SERVER
----- -------- --------- ---------
7 15 INACTIVE DEDICATED
12 63 INACTIVE DEDICATED
2 rows selected.
ALTER SYSTEM KILL SESSION '7,15';
Statement processed.
SELECT SID, SERIAL#, STATUS, SERVER
FROM V$SESSION
WHERE USERNAME = 'JWARD';
SID SERIAL# STATUS SERVER
----- -------- --------- ---------
7 15 KILLED PSEUDO
12 63 INACTIVE DEDICATED
2 rows selected.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/35489/viewspace-84308/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 會話控制利器 gorilla/sessions會話GoSession
- ORA-00018:maximum number of sessions exceedeSession
- [Bash] Kill command
- RedisConf2018記錄–Day1sessionsRedisSession
- 【linux】kill命令模板Linux
- mysql批次kill sessionMySqlSession
- 無腦批量kill sessionSession
- sqlserver kill long time lockSQLServer
- 程式命令ps/top/kill
- 精通 Linux 的 “kill” 命令Linux
- kill 已啟動的程式
- linux之kill命令詳解Linux
- kill與pkill的區別
- kill 指令的執行原理
- linux 檢視程式 kill程式Linux
- HashiConf 2018 視訊資源:主題演講以及Breakout SessionsSession
- 使用pt-kill根據一定的規則來kill連線的方法
- MySQL kill會話不起作用?MySql會話
- linux 下根據埠kill 程式Linux
- [20200319]KILL STATUS ='KILLED'的程式.txt
- Linux kill,killall和killall5Linux
- Percona-Toolkit 之 pt-kill 用法
- 這個殺手不太冷-kill家族
- MySQL: kill 會話的實現原理MySql會話
- Percona-Toolkit 之 pt-kill 低效SQLSQL
- Double Kill!! 資料聯邦修煉之路
- 關於centos9使用yum直接被killCentOS
- 簡述top命令與結束程式kill命令
- Mysql使用kill命令解決死鎖問題MySql
- MySQL:kill和show命令hang住一列MySql
- [20180918]disconnect session和kill session的區別.txtSession
- win10 ie關閉瀏覽器時彈出close sessions怎麼解決Win10瀏覽器Session
- OB運維 | 連線 kill 中的 session_id運維Session
- linux系列之:告訴他,他根本不懂killLinux
- percona-tools 之 pt-kill 引數詳解
- kill 命令在Java應用中使用注意事項Java
- percona 實用工具之pt-kill使用介紹
- 如何在 Linux 上使用 kill 和 killall 來管理程式Linux
- mysql使用KILL命令來終止特定的查詢程序MySql