Upload
randall-may
View
2
Download
0
Embed Size (px)
DESCRIPTION
Killing session
Citation preview
KillingOracleSessionsThereareanumberofwaystokillroguesessionsbothwithinOracleandexternally.
IdentifytheSessiontobeKilledALTERSYSTEMKILLSESSIONALTERSYSTEMDISCONNECTSESSIONTheWindowsApproachTheUNIXApproach
Relatedarticles.
MultithreadedModelusingTHREADED_EXECUTIONinOracleDatabase12cRelease1(12.1)
IdentifytheSessiontobeKilled
Killingsessionscanbeverydestructiveifyoukillthewrongsession,sobeverycarefulwhenidentifyingthesessiontobekilled.Ifyoukillasessionbelongingtoabackgroundprocessyouwillcauseaninstancecrash.
Identifytheoffendingsessionusingthe[G]V$SESSIONand[G]V$PROCESSviewsasfollows.
SETLINESIZE100COLUMNspidFORMATA10COLUMNusernameFORMATA10COLUMNprogramFORMATA45
SELECTs.inst_id,s.sid,s.serial#,p.spid,s.username,s.programFROMgv$sessionsJOINgv$processpONp.addr=s.paddrANDp.inst_id=s.inst_idWHEREs.type!='BACKGROUND';
INST_IDSIDSERIAL#[email protected](TNSV1V3)[email protected](TNSV1V3)[email protected](J000)[email protected](J001)
SQL>
TheSIDandSERIAL#valuesoftherelevantsessioncanthenbesubstitutedintothecommandsinthefollowingsections.
ALTERSYSTEMKILLSESSION
Thebasicsyntaxforkillingasessionisshownbelow.
SQL>ALTERSYSTEMKILLSESSION'sid,serial#';
InaRACenvironment,youoptionallyspecifytheINST_ID,shownwhenqueryingtheGV$SESSIONview.ThisallowsyoutokillasessionondifferentRACnode.
SQL>ALTERSYSTEMKILLSESSION'sid,serial#,@inst_id';
TheKILLSESSIONcommanddoesn'tactuallykillthesession.Itmerelyasksthesessiontokillitself.Insomesituations,likewaitingforareplyfromaremotedatabaseorrollingbacktransactions,thesessionwillnotkillitselfimmediatelyandwillwaitforthecurrentoperationtocomplete.Inthesecasesthesessionwillhaveastatusof"markedforkill".Itwillthenbekilledassoonaspossible.
Inadditiontothesyntaxdescribedabove,youcanaddtheIMMEDIATEclause.
SQL>ALTERSYSTEMKILLSESSION'sid,serial#'IMMEDIATE;
Thisdoesnotaffecttheworkperformedbythecommand,butitreturnscontrolbacktothecurrentsessionimmediately,ratherthanwaitingforconfirmationofthekill.
Ifthemarkedsessionpersistsforsometimeyoumayconsiderkillingtheprocessattheoperatingsystemlevel.Beforedoingthisit'sworthcheckingtoseeifitisperformingarollback.Youcandothisbyrunningthisscript(session_undo.sql).IftheUSED_URECvalueisdecreasingforthesessioninquestionyoushouldleaveittocompletetherollbackratherthankillingthesessionattheoperatingsystemlevel.
ALTERSYSTEMDISCONNECTSESSION
TheALTERSYSTEMDISCONNECTSESSIONsyntaxisanalternativemethodforkillingOraclesessions.UnliketheKILLSESSIONcommandwhichasksthesessiontokillitself,theDISCONNECTSESSIONcommandkillsthededicatedserverprocess(orvirtualcircuitwhenusingSharedSever),whichisequivalenttokillingtheserverprocessfromtheoperatingsystem.ThebasicsyntaxissimilartotheKILLSESSIONcommandwiththeadditionofthePOST_TRANSACTIONclause.TheSIDandSERIAL#valuesoftherelevantsessioncanbesubstitutedintooneofthefollowingstatements.
SQL>ALTERSYSTEMDISCONNECTSESSION'sid,serial#'POST_TRANSACTION;SQL>ALTERSYSTEMDISCONNECTSESSION'sid,serial#'IMMEDIATE;
ThePOST_TRANSACTIONclausewaitsforongoingtransactionstocompletebeforedisconnectingthesession,whiletheIMMEDIATEclausedisconnectsthesessionandongoingtransactionsarerolledbackimmediately.
ThePOST_TRANSACTIONandIMMEDIATEclausescanbeusedtogether,butthedocumentationstatesthatinthiscasetheIMMEDIATEclauseisignored.Inaddition,thesyntaxdiagramsuggestsbothclausesareoptional,butinreality,oneorbothmustbespecifiedoryoureceiveanerror.
SQL>altersystemdisconnectsession'30,7';altersystemdisconnectsession'30,7'*ERRORatline1:ORA02000:missingPOST_TRANSACTIONorIMMEDIATEkeyword
SQL>
Thiscommandmeansyoushouldneverneedtoswitchtotheoperatingsystemtokillsessions,whichreducesthechancesofkillingthewrongprocess.
TheWindowsApproach
TokillthesessionontheWindowsoperatingsystem,firstidentifythesession,thensubstitutetherelevantSIDandSPIDvaluesintothefollowingcommandissuedfromthecommandline.
C:>orakillORACLE_SIDspid
Thesessionthreadshouldbekilledimmediatelyandallresourcesreleased.
TheUNIXApproach
Warning:IfyouareusingtheMultithreadedModelinOracle12c,youshouldnotattempttokilloperatingsystemprocesses.Toknowwhy,readthis.
TokillthesessiononUNIXorLinuxoperatingsystems,firstidentifythesession,thensubstitutetherelevantSPIDintothefollowingcommand.
%killspid
Ifafterafewminutestheprocesshasn'tstopped,terminatethesessionusingthefollowing.
%kill9spid
IfindoubtcheckthattheSPIDmatchestheUNIXPROCESSIDshownusing.
%psef|grepora
Thesessionthreadshouldbekilledimmediatelyandallresourcesreleased.
Formoreinformationsee:
EndSessionClauses(SyntaxDiagram)EndSessionClauses(Description)MultithreadedModelusingTHREADED_EXECUTIONinOracleDatabase12cRelease1(12.1)
Hopethishelps.RegardsTim...
BacktotheTop.