Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Find Locked objects with high waitstats Expand / Collapse
Author
Message
Posted Friday, September 27, 2013 1:40 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Friday, May 23, 2014 9:25 AM
Points: 184, Visits: 852
Hi,

I have a SQL JOB that takes almost 8 hours to complete. I could find that when this runs there are a lot of waits. Screenshot is attached.
I would like to know on which objects these locks and latches are occurring and if possible the SQL statement involved.
These locks and latches are not being kept for a long duration, so it is hard to track from sysprocesses.

Thanks in Advance !


Sanz

  Post Attachments 
Capture.JPG (4 views, 27.01 KB)
Post #1499232
Posted Friday, September 27, 2013 3:36 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 5:23 AM
Points: 15,660, Visits: 28,046
The options are, query the dynamic management objects (DMO) such as sys.dm_exec_requests while the query is running in order to see which locks are taking a long time during execution. You can combine that DMO with others to see the query, the locked objects and the execution plan. The other option would be to set up extended events to capture information. That one is going to be much tougher. What you would need to do is start with the lock_acquired event. You can combine that with lock_released and look for pairings that exceed a certain value. It's going to be a bit of work to set up, but you can narrow right down to specific events that way. You should be able to combine that data with rpc_completed and sql_batch_completed to also capture the queries involved.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1499274
Posted Friday, September 27, 2013 5:07 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 4:45 AM
Points: 2,931, Visits: 2,951
Hi,

It's easy with extended events (XE) in sql server 2012 by help of its GUI. It should be possible with XE 2008 R2, but you'll have to write some code (easier if you can find a gui for sql 2008 r2).
Another option is to use some code in a scheduled job and collect data for a certain period.

I use the following code to catch locks:

SELECT 
L1.resource_type ,
DB_NAME(L1.resource_database_id) AS DatabaseName ,
CASE L1.resource_type
WHEN 'OBJECT' THEN OBJECT_NAME(L1.resource_associated_entity_id,L1.resource_database_id)
WHEN 'DATABASE' THEN 'DATABASE'
ELSE CASE
WHEN L1.resource_database_id = DB_ID() THEN
(SELECT
OBJECT_NAME(object_id, L1.resource_database_id)
FROM sys.partitions
WHERE hobt_id = L1.resource_associated_entity_id
)
ELSE NULL
END
END AS ObjectName ,
L1.resource_description ,
L1.request_session_id ,
L1.request_mode ,
L1.request_status
FROM
sys.dm_tran_locks AS L1
JOIN sys.dm_tran_locks AS L2 ON L1.resource_associated_entity_id = L2.resource_associated_entity_id
WHERE
L1.request_status <> L2.request_status
AND ( L1.resource_description = L2.resource_description
OR ( L1.resource_description IS NULL AND L2.resource_description IS NULL)
)
ORDER BY
L1.resource_database_id ,
L1.resource_associated_entity_id ,
L1.request_status ASC;




Regards,
IgorMi




Igor Micev,
SQL Server developer at Seavus
www.seavus.com
Post #1499311
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse