Vous êtes sur la page 1sur 3

KillingOracleSessions

ThereareanumberofwaystokillroguesessionsbothwithinOracleandexternally.
IdentifytheSessiontobeKilled
ALTERSYSTEMKILLSESSION
ALTERSYSTEMDISCONNECTSESSION
TheWindowsApproach
TheUNIXApproach
Relatedarticles.
MultithreadedModelusingTHREADED_EXECUTIONinOracleDatabase12cRelease1(12.1)

IdentifytheSessiontobeKilled
Killingsessionscanbeverydestructiveifyoukillthewrongsession,sobeverycarefulwhenidentifyingthesessiontobekilled.If
youkillasessionbelongingtoabackgroundprocessyouwillcauseaninstancecrash.
Identifytheoffendingsessionusingthe[G]V$SESSIONand[G]V$PROCESSviewsasfollows.
SETLINESIZE100
COLUMNspidFORMATA10
COLUMNusernameFORMATA10
COLUMNprogramFORMATA45
SELECTs.inst_id,
s.sid,
s.serial#,
p.spid,
s.username,
s.program
FROMgv$sessions
JOINgv$processpONp.addr=s.paddrANDp.inst_id=s.inst_id
WHEREs.type!='BACKGROUND';
INST_IDSIDSERIAL#SPIDUSERNAMEPROGRAM

130153859TESTsqlplus@oel511gr2.localdomain(TNSV1V3)
1232873834SYSsqlplus@oel511gr2.localdomain(TNSV1V3)
1403874663oracle@oel511gr2.localdomain(J000)
1381254665oracle@oel511gr2.localdomain(J001)
SQL>
TheSIDandSERIAL#valuesoftherelevantsessioncanthenbesubstitutedintothecommandsinthefollowingsections.

ALTERSYSTEMKILLSESSION
Thebasicsyntaxforkillingasessionisshownbelow.
SQL>ALTERSYSTEMKILLSESSION'sid,serial#';
InaRACenvironment,youoptionallyspecifytheINST_ID,shownwhenqueryingtheGV$SESSIONview.Thisallowsyoutokilla
sessionondifferentRACnode.
SQL>ALTERSYSTEMKILLSESSION'sid,serial#,@inst_id';
TheKILLSESSIONcommanddoesn'tactuallykillthesession.Itmerelyasksthesessiontokillitself.Insomesituations,likewaiting
forareplyfromaremotedatabaseorrollingbacktransactions,thesessionwillnotkillitselfimmediatelyandwillwaitforthecurrent
operationtocomplete.Inthesecasesthesessionwillhaveastatusof"markedforkill".Itwillthenbekilledassoonaspossible.
Inadditiontothesyntaxdescribedabove,youcanaddtheIMMEDIATEclause.

SQL>ALTERSYSTEMKILLSESSION'sid,serial#'IMMEDIATE;
Thisdoesnotaffecttheworkperformedbythecommand,butitreturnscontrolbacktothecurrentsessionimmediately,ratherthan
waitingforconfirmationofthekill.
Ifthemarkedsessionpersistsforsometimeyoumayconsiderkillingtheprocessattheoperatingsystemlevel.Beforedoingthisit's
worthcheckingtoseeifitisperformingarollback.Youcandothisbyrunningthisscript(session_undo.sql).IftheUSED_URECvalue
isdecreasingforthesessioninquestionyoushouldleaveittocompletetherollbackratherthankillingthesessionattheoperating
systemlevel.

ALTERSYSTEMDISCONNECTSESSION
TheALTERSYSTEMDISCONNECTSESSIONsyntaxisanalternativemethodfor
killingOraclesessions.UnliketheKILLSESSIONcommandwhichasksthe
sessiontokillitself,theDISCONNECTSESSIONcommandkillsthededicated
serverprocess(orvirtualcircuitwhenusingSharedSever),whichisequivalentto
killingtheserverprocessfromtheoperatingsystem.Thebasicsyntaxissimilar
totheKILLSESSIONcommandwiththeadditionof
thePOST_TRANSACTIONclause.TheSIDandSERIAL#valuesoftherelevant
sessioncanbesubstitutedintooneofthefollowingstatements.
SQL>ALTERSYSTEMDISCONNECTSESSION'sid,serial#'POST_TRANSACTION;
SQL>ALTERSYSTEMDISCONNECTSESSION'sid,serial#'IMMEDIATE;
ThePOST_TRANSACTIONclausewaitsforongoingtransactionstocompletebefore
disconnectingthesession,whiletheIMMEDIATEclausedisconnectsthesession
andongoingtransactionsarerolledbackimmediately.
ThePOST_TRANSACTIONandIMMEDIATEclausescanbeusedtogether,butthedocumentationstatesthatinthiscase
theIMMEDIATEclauseisignored.Inaddition,thesyntaxdiagramsuggestsbothclausesareoptional,butinreality,oneorbothmust
bespecifiedoryoureceiveanerror.
SQL>altersystemdisconnectsession'30,7';
altersystemdisconnectsession'30,7'
*
ERRORatline1:
ORA02000:missingPOST_TRANSACTIONorIMMEDIATEkeyword
SQL>
Thiscommandmeansyoushouldneverneedtoswitchtotheoperatingsystemtokillsessions,whichreducesthechancesofkilling
thewrongprocess.

TheWindowsApproach
TokillthesessionontheWindowsoperatingsystem,firstidentifythesession,thensubstitutetherelevantSIDandSPIDvaluesinto
thefollowingcommandissuedfromthecommandline.
C:>orakillORACLE_SIDspid
Thesessionthreadshouldbekilledimmediatelyandallresourcesreleased.

TheUNIXApproach
Warning:IfyouareusingtheMultithreadedModelinOracle12c,youshouldnotattempttokilloperatingsystemprocesses.Toknow
why,readthis.
TokillthesessiononUNIXorLinuxoperatingsystems,firstidentifythesession,thensubstitutetherelevantSPIDintothefollowing
command.
%killspid

Ifafterafewminutestheprocesshasn'tstopped,terminatethesessionusingthefollowing.
%kill9spid
IfindoubtcheckthattheSPIDmatchestheUNIXPROCESSIDshownusing.
%psef|grepora
Thesessionthreadshouldbekilledimmediatelyandallresourcesreleased.
Formoreinformationsee:
EndSessionClauses(SyntaxDiagram)
EndSessionClauses(Description)
MultithreadedModelusingTHREADED_EXECUTIONinOracleDatabase12cRelease1(12.1)
Hopethishelps.RegardsTim...
BacktotheTop.

Vous aimerez peut-être aussi