sys.sysprocesses

  • I was monitoring the sessions through this dmv and found that sometimes even if the session is closed ,it is viewable in the result. Can someone clarify this nature ?

  • how do you determin that the session is closed?

    are you sure its just not SQL reassigning the SPID to a different connection?

  • Check the status column of that corresponding session. and it will provide you the what currently that session is doing.

  • sqlnaive (2/20/2012)


    I was monitoring the sessions through this dmv and found that sometimes even if the session is closed ,it is viewable in the result. Can someone clarify this nature ?

    You can try it yourself. Open two query windows , run separate queries in those windows. Check that both are appearing in the sys.sysprocesses results. Now close one of them & check that it has gone out of the result.


    Sujeet Singh

  • I tried the same actually. I opened two sessions and from one of them I ran one update statement. Once I closed that session with update command, and performed select from sys.sysprocesses, I could see my processid and hostname with the sql_handle which provided me my executed update query.

  • sqlnaive (2/21/2012)


    I tried the same actually. I opened two sessions and from one of them I ran one update statement. Once I closed that session with update command, and performed select from sys.sysprocesses, I could see my processid and hostname with the sql_handle which provided me my executed update query.

    So you can see the status of your session over there. It should be sleeping/Awaiting Command.


    Sujeet Singh

  • Yes. It says sleeping. But then there are other sessions which are not closed but still seen as sleeping. How can I differ between the two ? Should these sessions be there ? Or should there be some different architecture to handle this (like storing historic session information) ?

  • You should not be worried about the Sleeping/Awaiting Commands session unless they are not blocking other sessions. SQL Server does it, so that it can reuse the same connection.


    Sujeet Singh

  • How long these process ids remain there (in case the sessions are closed). I want to check only those session ids which are live, in use or not in use.

  • How long these process ids remain there (in case the sessions are closed). Anyone ?

  • sqlnaive (2/22/2012)


    How long these process ids remain there (in case the sessions are closed). I want to check only those session ids which are live, in use or not in use.

    I would suggest to use this :

    Execute sp_who2 Active

    This will provide you only those session ids which are currently active on the server, not all the sessions. As much as I know many DBAs use just that instead of sys.sysprocesses.


    Sujeet Singh

  • Ditto @Divine , use that sweet thing religiously!

    ______________________________________________________________________________Never argue with an idiot; Theyll drag you down to their level and beat you with experience

  • Agreed - The only thing is that I can use sys.sysprocesses in joins with other tables to get useful information. Else I always has that sp_who[2] option.

  • sqlnaive (2/29/2012)


    Agreed - The only thing is that I can use sys.sysprocesses in joins with other tables to get useful information. Else I always has that sp_who[2] option.

    In that case you can filter those sessions with "Sleeping/Awaiting Command" status in your WHERE clause. However if you could explain your case where you are using sys.sysprocesses in join may be we can provide better option.


    Sujeet Singh

  • select a.spid, b.text from sys.sysprocesses a cross apply sys.dm_exec_sql_text(a.sql_handle) b

    This is the query I'm using. This is giving me even those sessions which are closed in query analyzer.

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply