agcsupport
asked on
Find current query running in sql server 2005
HI,
I am running SQL profiler to troubleshoot a long running query. I am trying to figure out a query that is taking a very long time. There are a few applications running on this server. I know I can use profiler to get the “SQL:BatchStarting” and the “SQL:BatchCompleted” to capture the TextData and find out the SQL query that is running and how long it took. My question is how can I see the current query that is running in SQL Server without having to wait until it is completed. Some of the queries are taking a very long time (may even abort at the end) and makes it difficult to troubleshoot and find out which one it was. Is there a way to run a SQL Command to see the current running queries on the server?
Hope I was clear enough.
Thanks,
Miguel
FYI: I can do this in Oracle running the following command. Looking for the same in SQL Server.
SELECT
substr(a.username,1,10) UserName,a.sid, substr(a.osuser,1,10) osuser, p.spid OS_PID, a.AUDSID, substr(a.process,1,10) Session_ID,a.serial#,a.Las t_Call_ET, a.command, substr(a.lockwait,1,5) lockwait ,substr(a.machine,1,17) machine ,substr(a.program,1,10) program,b.piece,b.sql_text
FROM
v$session a, v$sqltext_with_newlines b,v$process p
WHERE
a.status = 'ACTIVE' AND a.username <> 'SYS'
AND a.sql_hash_value= b.hash_value
AND a.paddr = p.addr
ORDER BY osuser,sid,piece;
I am running SQL profiler to troubleshoot a long running query. I am trying to figure out a query that is taking a very long time. There are a few applications running on this server. I know I can use profiler to get the “SQL:BatchStarting” and the “SQL:BatchCompleted” to capture the TextData and find out the SQL query that is running and how long it took. My question is how can I see the current query that is running in SQL Server without having to wait until it is completed. Some of the queries are taking a very long time (may even abort at the end) and makes it difficult to troubleshoot and find out which one it was. Is there a way to run a SQL Command to see the current running queries on the server?
Hope I was clear enough.
Thanks,
Miguel
FYI: I can do this in Oracle running the following command. Looking for the same in SQL Server.
SELECT
substr(a.username,1,10) UserName,a.sid, substr(a.osuser,1,10) osuser, p.spid OS_PID, a.AUDSID, substr(a.process,1,10) Session_ID,a.serial#,a.Las
FROM
v$session a, v$sqltext_with_newlines b,v$process p
WHERE
a.status = 'ACTIVE' AND a.username <> 'SYS'
AND a.sql_hash_value= b.hash_value
AND a.paddr = p.addr
ORDER BY osuser,sid,piece;
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Both very usefull. Thanks a lot.
Give it a try if you want to:
http://sqlblog.com/files/folders/release/default.aspx