What is sysprocesses and what can it do for you?

  • Comments posted to this topic are about the item What is sysprocesses and what can it do for you?

  • Question - how does this relate to sp_who and sp_who2, and the activty monitor in SSMS?

  • Thanks for a great review. For those of us who have been using sysprocesses as well as sp-who, sp_who2 for along time, it never hurts to have a review.

    BTW.. sp_who & sp_who2 use info from sysprocesses.

    sysprocesses goes back to the original Sybase design, so it has been around for a while.

    The more you are prepared, the less you need it.

  • Good review of sysprocess table. Every DBA should know about this table. Though I know a couple of ones who are used to using sp_who2 but does have no idea where the data comes from.

    2005 and 2008 has an extra column request_id.

    SQL DBA.

  • Hi Mark,

    Thanks Andrew and Sanjay.

    The sysprocesses table is wrapped by sp_who* and the activity monitor but they do not give you as much detail, if you look at the definition for sp_who it is:

    CREATE PROCEDURE sys.sp_who

    select spid,

    ecid,

    status,

    loginame=rtrim(loginame),

    hostname,

    blk=convert(char(5),blocked),

    dbname = case

    when dbid = 0 then null

    when dbid 0 then db_name(dbid)

    end

    ,cmd

    ,request_id

    from master.dbo.sysprocesses

    where spid >= @spidlow and spid <= @spidhigh

    so it is useful but I think when troubleshooting issues knowing how to use sysprocessses and what everything means is essential.

    It is also good for scripting because for instance you can join against itself on blocked = spid to get information on what queries are being blocked and also what it is that is blocking them.

    Ed

  • What a co-incidence...

    On thursday, I was struggling to get the Detailed information for each column in sys.sysprocesses. And here we are....

    Very useful article, especially for me.

    Thanks

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Sometimes, winning is not an issue but trying.
    You can check my BLOG
    [font="Arial Black"]here[/font][/url][/right]

  • A friend of mine wanted to conduct a license audit of her installation and used sysprocesses to get the info. On each server she created a DTS job that ran the following query:

    select getdate() as StatsDate, ss.srvname as ServerName,

    rtrim(db.name) as DBName, rtrim(hostname) as HostName,

    rtrim(program_name) as ProgramName, rtrim(nt_domain) as Domain,

    rtrim(nt_username) as UserName,rtrim(net_address) as MACAddress,

    rtrim(loginame) as LoginName

    from master..sysprocesses sp

    join master..sysdatabases db

    on sp.dbid = db.dbid

    cross join master..sysservers ss

    where sp.loginame 'sa'

    order by db.name, hostname, loginame

    then wrote it to a text file. She ran it at the top of the hour, on some days every 5 or 15 minutes, over an extended period of time and collected the scripts on her machine via a scheduled task that ran at 5 minutes after the hour that did this:

    copy C:\SQLUserStats\ConnectionStats.txt + \\server1\c$\SQLUserStats\sqluserstats.txt C:\SQLUserStats\ConnectionStats.txt

    copy C:\SQLUserStats\ConnectionStats.txt + \\server2\c$\SQLUserStats\sqluserstats.txt C:\SQLUserStats\ConnectionStats.txt

    etc.

    Worked like a charm. Suck the text file into a table and you can slice and dice the data to your heart's contentment.

    One thing it would not show: if connections came through a gateway or application server that could spoof a MAC address or user name, you could have several dozen users hidden that you won't readily see. You also wouldn't see users who logged in for less than an hour and didn't cross that top of the hour boundary, so there were days that it ran every 15 minutes or every 5 minutes. Still, it was deemed adequate by her management to give a reasonable number of user connections.

    Regardless, sysprocesses saved a whole lot of work for her.

    -----
    [font="Arial"]Knowledge is of two kinds. We know a subject ourselves or we know where we can find information upon it. --Samuel Johnson[/font]

  • Wayne West (5/5/2009)


    A friend of mine wanted to conduct a license audit of her installation and used sysprocesses to get the info...

    I'm doing something similar. I'm checking sysprocesses every 5 minutes to look for users with certain patterns.

    I ended up here because I have been seeing one user whose sessions sometimes show up without a value in loginame! I used Profiler to watch logins and logouts and I see the session, and there is a value for the login name. When run from SSMS the query has never shown this blank loginame, but I do track it when the query is run from Server Agent.

    Does anyone have any idea how a session could legitimately show up in sysprocesses without a loginame? And if I don't see it in that column can I get it from somewhere else? (the case I know about is an SQL user)

Viewing 8 posts - 1 through 7 (of 7 total)

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