Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-01-07
5
Medium Priority
?
91 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 500 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 500 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 500 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 500 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

715 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