Friday, August 16, 2013

Database -- Why we need the serial# to kill a session

SID ->Session identifier

SERIAL# -> Session serial number. Used to identify uniquely a session's objects. Guarantees that session-level commands are applied to the correct session objects if the session ends and another session begins with the same session ID

To kill a session in Oracle , we use alter system kill session 'serial#,sid'

One question comes to our minds.. Why not using sid alone , as we know sid is a unique identifier..

I will write a short example scenario to explain this..

Suppose you want to kill sid 250.
And you prepared kill statement, as alter system kill session 250 (this is not a correct syntax, but suppose it s a correct synax and it is possible)
--> Here is the important part.
Just before, you execute your kill statement, suppose the the session with sid 250 closed itself. ( For example, it was a toad session, and the user closed its Toad program.).. and just after 1 second, another session is connected to the database and assigned the sid 250.
So when, you execute your kill command you will kill sid 250 , but actually you will do something wrong as sid 250 will belong to another session at that time..

So this is the need for Serial#  in kill command...

No comments :

Post a Comment