Quantcast
Channel: THWACK: All Content - All Communities
Viewing all articles
Browse latest Browse all 20518

Custom Report - Top SQL for Locking Issues

$
0
0

DESCRIPTION

This procedure will return the top 30 SQL statements for the given instance and date range ordered by total seconds spent waiting on blocks. This report reads summary data, so running it for a time range less than one hour will not yield correct results.

 

Note: See comments inside the procedure for more details on the parameters and methods for calling. Install the stored procedure into the Ignite repository database.

 

STORED PROCEDURE

IF OBJECT_ID('TopSQLforLocking') IS NOT NULL

   DROP PROCEDURE TopSQLforLocking

GO

 

-- TopSQLforLocking PROC

--

-- PARMS '@FROM_DATE', '@TO_DATE', '@INAME'

-- EXAMPLE:

--

-- EXEC TopSQLforLocking 'SEBOX1\SE2008R2','2014-03-15 00:00','2014-03-25 00:00'

 

CREATE PROCEDURE TopSQLforLocking (@INAME VARCHAR(50), @FROM_DATE VARCHAR(16), @TO_DATE VARCHAR(16))

AS

DECLARE @SQL VARCHAR(2000), @DBID VARCHAR(5);

 

BEGIN

   -- get the Instance ID

   SELECT @DBID=id FROM ignite.cond WHERE name=@INAME;

 

   -- create the SQL to execute

   SET @SQL = 'select TOP 30 ss.sqlhash, sum(timesecs) total_seconds '+

           'from ignite.con_sql_sum_'+@DBID+' ss '+

           'inner join ignite.conev_'+@DBID+' ev on ev.id = ss.eventid '+

           'where ev.name like ''LCK%'' '+

           'and ss.datehour between '''+@FROM_DATE+''' and '''+@TO_DATE+''' '+

           'group by ss.sqlhash '+

           'order by sum(timesecs) desc';

  EXEC (@SQL);

END

GO


Viewing all articles
Browse latest Browse all 20518

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>