Solved

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

Posted on 2014-01-07
5
81 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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

627 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