开发者

Is there an equivalent to 'mysqladmin processlist' for SQL Server?

开发者 https://www.devze.com 2023-01-06 08:36 出处:网络
I\'ve been trying to formulate a query to help myself identify resource-heavy queries/database/users using SQL Server and haven\'t gotten it down quite yet.I want to build a query that will do what \'

I've been trying to formulate a query to help myself identify resource-heavy queries/database/users using SQL Server and haven't gotten it down quite yet. I want to build a query that will do what 'mysqladmin processlist' would do for MySQL.

I've re开发者_高级运维ferred to this related question but haven't gotten what I really need from it. I'm using sp_who, sp_who2 and queries like this:

select master.dbo.sysprocesses.loginame, 
count(master.dbo.sysprocesses.loginame)
from master.dbo.sysprocesses
group by master.dbo.sysprocesses.loginame

The problem always is that one of these tools doesn't give me everything I need. My goal would be to have a query that would be of this format:

LOGIN, DATABASE, QUERY, CPU, MEM, etc.

If anyone knows how to do this, I would appreciate the help. If anyone has any SQL Server DBA cheatsheets that would be great, too.


Does it have to be done with a sproc call? SQL Server Management Studio (the link is for the express edition, but a full install of SQL Server already has it) has an "Activity Monitor" feature which lists exactly what you want.

Other than that,

EXECUTE sp_who2

Gives you exactly what you asked for: Login, DBName, Command, CPUTime, DiskIO, are all there...

If you want the exact command that a SPID is executing, you can use the

DBCC INPUTBUFFER(spid)

command (sp_who2 just tells you whether it's a DELETE, SELECT, etc)


If you bust out sp_who2, you could extract the fields that you're interested in:

select    
  spid
 ,status 
 ,hostname
 ,program_name
 ,cmd
 ,cpu
 ,physical_io
 ,blocked
 ,dbid
 ,convert(sysname, rtrim(loginame))
        as loginname

      from sys.sysprocesses with (nolock)
      order by cpu desc
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号