Solved

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

Posted on 2014-01-07
5
59 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL, How to do aggregation on extracting field and range band field? 2 31
SQL create line numbers for data sampling 11 30
SQLCMD Syntax 2 16
SQL 2012 clustering 9 13
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

828 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