Solved

How to identify locked tables and how to release the locks?

Posted on 2014-02-04
5
280 Views
Last Modified: 2014-02-05
One of the SPs in my database takes long time to execute. The same SP executes faster in another DB. My colleague suggests that the tables could be locked in my DB and I've to release the locks (in which the SP refers) from the tables. How to identify the issue is due to locks and how to release them?

Please do suggest. Thanks.
0
Comment
Question by:Easwaran Paramasivam
5 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 125 total points
Comment Utility
Are the tables (in the two different databases) the SP operate upon identical in structure ?  (An index in one table that isn't in the other can make a vast difference to the time an SP takes to complete).
0
 
LVL 19

Assisted Solution

by:Patricksr1972
Patricksr1972 earned 125 total points
Comment Utility
Hi

Look under management (right click) and select View locks by object.
0
 
LVL 16

Assisted Solution

by:Surendra Nath
Surendra Nath earned 125 total points
Comment Utility
you can use the sp_lock2 stored procedure to find out if there are any locks on the tables involved
if that stored procedure is not already there in your database then you can get it from here

http://support.microsoft.com/kb/255596

I suggest you also try to update the statistics once and see if it resolves the performance issue

sp_updateStats

the above statement will update the stats of all the tables involved...
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 125 total points
Comment Utility
Andy has the most common and easiest to fix problem with slow stored procedures: tables that are not indexed properly.

The difference of speed between 2 databases might be that the amount or the values of the joining and ordering fields are different from one database to another. The amount of traffic can also play a role.

If you find out that locks are the problem, be careful. Locks are usually there for a good reason: to prevent multiple writes to the same data from 2 different sources at the same time. Removing them to speed up things would create more important problems.

Is your application the only one that uses that database? If so review your code for the most common cause of locks: transactions. You might be starting transactions that you do not commit or rollback as soon as the operations are finished, so they are holding locks uselessly. You might also be using transactions in places where they are not needed.

If other applications use that database, try to see if the same thing could not happen in these too.
0
 
LVL 16

Author Closing Comment

by:Easwaran Paramasivam
Comment Utility
Thanks
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

728 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

9 Experts available now in Live!

Get 1:1 Help Now