遠程快速殺死session!,遠程殺死session!

來源:互聯網
上載者:User

遠程快速殺死session!,遠程殺死session!
今天有一個開發的哥們A(不方面透露資訊,暫叫A),在群裡發問:
表中插入大資料量的時候卡住了,一查發現是鎖住了,已經kill session,但是總是解鎖不了,狀態是killed,釋放不了鎖,並且刪除操作的表,也不行,提示資源正忙。
當時只是草率的說:
去os中 直接  kill  -9  spid
後來這位哥們給我發該怎麼弄:
我讓他查: select  spid,username,terminal,program from  v$process where addr in (select  paddr from  v$session  where username=XXX) ;

A給的:

select object_name,machine,s.sid,s.serial# 
from v$locked_object l,dba_objects o ,v$session s
where l.object_id = o.object_id and l.session_id=s.sid;

他同時給我找個:

然後讓他在os下執行:
kill  -9  spid;(LINUX)
orakill 執行個體 thread (Windows)
這時他說他是遠端資料庫,而且不能ssh登陸伺服器主機,這個是挺頭疼的!

我讓他再一次:
alter system kill session '428,310';

alter system kill session '727,862';

alter system kill session '304,365';
此時還沒有解決問題:



這時A說已經解決了:
 alter system kill session '727,862' immediate; 加了一個強制immediate


一般情況下,在殺死一個session時,直接alter  system  kill  session  ‘sid,serial#'
當session還是active的時候,這是將session標識為killed或者pseudo,並不會釋放session所持有的資源,所以會話一直存在(The ALTER SYSTEM statement does not implicitly commit the current transaction.)
官方網站上:(http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_2014.htm#SQLRF00902)
If the session is performing some activity that must be completed, such as waiting for a reply from a remote database or rolling back a transaction, then Oracle Database waits for this activity to complete, marks the session as terminated, and then returns control to you. If the waiting lasts a minute, then Oracle Database marks the session to be terminated and returns control to you with a message that the session is marked to be terminated. ThePMON background process then marks the session as terminated when the activity is complete.
IMMEDIATE Specify IMMEDIATE to instruct Oracle Database to roll back ongoing transactions, release all session locks, recover the entire session state, and return control to you immediately.
通過上面學習了如何遠程快速殺死session,平時習慣於依賴os命令,正好今天上了一課!同時也感謝A!

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.