Solved

Get a List of Executing Stored Procedures on Sql Server 2008 R2

Posted on 2014-01-07
5
47 Views
Last Modified: 2016-05-31
I need an sql statement I can execute that will return the name of a stored procedure that is currently running against a given database.  This will help me check if I have a hung proc that is killing performance.  We are running MSSQL 2008 R2.  THanks!
0
Comment
Question by:TronGod
5 Comments
 
LVL 15

Accepted Solution

by:
pateljitu earned 125 total points
ID: 39762331
You could configure and use SQL profiler to keep track of stored procedure running for long time.

Also take a look at this article:
http://blogs.msdn.com/b/taylaf/archive/2010/01/25/determine-the-currently-executing-statement-in-a-long-running-sql-stored-procedure.aspx
0
 
LVL 17

Assisted Solution

by:Barry Cunney
Barry Cunney earned 125 total points
ID: 39762483
Hi TronGod,
The following SQL statement is useful for listing all currently executing SQL against the server and lists some helpful information about the related process - it is ordered by cpu, memory and IO so the resource heavy processes should be top of the list
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT 
Hostname
,nt_username
,program_name
,sp.login_time 
,qt.text AS [Parent Query]
,sp.cpu
,sp.memusage 
,sp.physical_io 
,er.total_elapsed_time
,session_Id AS [Spid]
,er.blocking_session_id 
,er.granted_query_memory 
,er.start_time 
,ecid
,DB_NAME(sp.dbid) AS [Database]
,er.status
,er.wait_resource 
,wait_type
,SUBSTRING (qt.text, (er.statement_start_offset/2) + 1, --#1
((CASE WHEN er.statement_end_offset = -1
THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
ELSE er.statement_end_offset
END - er.statement_start_offset)/2) + 1) AS [Individual Query]
,nt_domain
FROM sys.dm_exec_requests er --#2
INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid
CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt
WHERE session_Id > 50
AND session_Id NOT IN (@@SPID)
ORDER BY (sp.cpu + sp.memusage + sp.physical_io) DESC

Open in new window

0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 125 total points
ID: 39762931
You are not going to be able to get the Stored Procedure name, but you can certainly find any long running query in any Stored Procedure and then track the name down from there.  You can do this very easily with a script such as Adam Machanic's Who is Active
0
 
LVL 38

Assisted Solution

by:Jim P.
Jim P. earned 125 total points
ID: 39763805
Another thought is to look at the Confio Ignite Free monitoring SW.

I was using it for a while, and it showed me where issues with our SW that had bad queries.

Our SW had about 700 clients. I found an SP that was selecting from an Employee table without any qualification for the specific client. It was looking at 25K+ records for one user id. Want to talk about a waste of CPU....
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now