SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Locking
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Robowski
Posting Yak Master

101 Posts

Posted - 04/26/2013 :  05:58:07  Show Profile  Reply with Quote
Is there any way of getting the SQL that is being run that is causing a locking at any one given time?

I'm aware of sp_who2, sys.dm_tran_locks and sys.sysprocesses to find out who is being locked and by what. But is there anything in SQL that stores the query so some sort of trigger can be build to record it?

I know the obvious answer is the SQL profiler but that will only work during the locking not after its cleared

Cheers

Rob

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/26/2013 :  06:02:02  Show Profile  Reply with Quote
what you could do is to note the process that causes blocking using sp_who2 and then use

DBCC INPUTBUFFER (< the blocking process_id here >)


to get details on statement it was executing

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Robowski
Posting Yak Master

101 Posts

Posted - 04/26/2013 :  06:04:44  Show Profile  Reply with Quote
thanks,

But i'mm looking to automate really, so a trigger will put any locking instances into a table along with what was being locked and by what if that make sense? Could this be done using the DBCC inputbuffer/outputbuffer?

quote:
Originally posted by visakh16

what you could do is to note the process that causes blocking using sp_who2 and then use

DBCC INPUTBUFFER (< the blocking process_id here >)


to get details on statement it was executing

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/26/2013 :  06:25:55  Show Profile  Reply with Quote
you can put same logic inside trigger. put blocking ids in a table and then use dbcc inputbuffer over them to get statements

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Robowski
Posting Yak Master

101 Posts

Posted - 04/26/2013 :  06:33:29  Show Profile  Reply with Quote
Are you aware of any non system tables that hold locking? Can;t put a trigger on sys.sysprocesses

quote:
Originally posted by visakh16

you can put same logic inside trigger. put blocking ids in a table and then use dbcc inputbuffer over them to get statements

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/26/2013 :  06:37:40  Show Profile  Reply with Quote
nope...no user defined tables unless you set one

and data should still come from sysprocesses only.

Why not add a automated jobs which checks the presence of locking according to a schedule and then logs it. You can schedule job to run only at times where you fear locking isues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

Robowski
Posting Yak Master

101 Posts

Posted - 04/26/2013 :  06:39:11  Show Profile  Reply with Quote
There is an issue with the software locking in sql and it is at random times

the below might help em though, im going to read through this.. thanks for the advice though

https://www.simple-talk.com/sql/database-administration/the-dba-as-detective-troubleshooting-locking-and-blocking/
quote:
Originally posted by visakh16

nope...no user defined tables unless you set one

and data should still come from sysprocesses only.

Why not add a automated jobs which checks the presence of locking according to a schedule and then logs it. You can schedule job to run only at times where you fear locking isues

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 04/26/2013 :  06:42:24  Show Profile  Reply with Quote
Thats still only speaks of making it a proc. you still have to schedule it as a job for automating the run as i suggested.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000