Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

758 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

21 Experts available now in Live!

Get 1:1 Help Now