Lock Escalation for Sql Server

Lock escalation is the process of converting many fine-grained locks (such as row or page locks) into table locks.

When many locks created on the same table’s row in Same session the Sql Server itself automatically upgrades these locks into a table lock, it is count all locks like page, row and index-level locks on the a single table.

Escalation’s threshold values is 5000 locks (on single table) it’s maintained by Sql Server itself and we no need to change in configuration.  

Note: Escalation cannot occur if a different SPID is currently holding an incompatible table lock.

Lock Escalation Modes:–

  1. Table: Table is the default mode and specifies that lock escalation will be done at table-level granularity.
  2. Auto: Auto mode allows the Database Engine to select the lock escalation granularity that is appropriate for the table schema.
  3. Disable:  allows to disable lock escalation.

How to Check Escalation Modes:–

We can check any specific table’s escalation mode using sys.tables like

select name,object_id,lock_escalation_desc  from sys.tables where name =’saleshead’

How to Check Lock Escalation Modes

Change Escalation Mode: We also can change it using ALTER TABLE statement like

how to Change Lock Escalation Mode

How to check/ trace Escalation: many ways to can trace it now try will profiler

  1. login in profiler and select tsql_locks or also you can use blank template like :
How to check/ trace Escalation using profiler

2. Now Select Lock Escalation Events form “Events Selection” Tab there events lists come according to your selection template In that case I have selected Blank template

Lock Escalation events

3. Finally check where and which query

Finally check where and which query

How to Prevent Locks:

  1. To keep short transactions: Break up large batch operations into several smaller operations. For example, suppose we deleting several hundred thousand old records then we found that it caused a lock escalation that blocked other users.

DELETE FROM sqllogs WHERE datastamp < ‘20190101’

Break above query like that:

SET ROWCOUNT 500

delete_more:

     DELETE FROM sqllogs WHERE datastamp< ‘20190101’

  IF @@ROWCOUNT > 0

           GOTO delete_more

SET ROWCOUNT 0

2. Reduce lock footprint of expensive queries by doing performance tuning and making them efficient.

You may also like...

38 Responses

  1. Datko says:

    It is not my first time to read about Sql Server Locking issue, but this is educating in very simple language,
    Thanks for Post!!

  2. Jessica Cook says:

    It as hard to come by educated people about this subject. However, you sound like you know what you are talking about! Thanks.

  3. Rohita says:

    I am sure this is supper educational post for sql locking issue.

  4. Ormekur says:

    Gracias! Excelente post!

  5. hell says:

    Hello There. This is a really well written article. I will make sure to bookmark it and return to read more of your useful info.
    Thanks for the post. I’ll definitely return.

  6. Vilin Philippe says:

    great work (like).

  7. Justin says:

    good blog for advanced level Sql Server.

  8. now says:

    Normally I do not read post on blogs, however I wish to
    say that this write-up very pressured me to take a look at and do so!
    Your writing taste has been surprised me. Thanks,
    quite nice post.

  9. n95 8511 says:

    Thanks for the terrific information for us.

    Best regards,
    Thompson Hessellund

  10. Sharan Denton says:

    Thanks for taking the time to discuss this, I feel strongly about it as well as love understanding more about this topic. Thanks alot…

  11. blog3002 says:

    I am sure this article has touched hot and core topics, its really really
    good.

  12. Internet Search Engine says:

    Very interesting subject , regards for putting up.

  13. Chang Gheewala says:

    “Great article and right to the point. I don’t know if this is in fact the best place to ask but do you folks have any thoughts on where to get some professional writers? Thank you ??”

  14. ปั้มไลค์ says:

    Like!! Thank you for publishing this awesome article.

  15. Adriene Panton says:

    “I have been absent for a while, but now I remember why I used to love this web site. Thanks , I will try and check back more frequently. How frequently you update your web site?”

  16. chuccku says:

    i’m beginner but its interesting for me.

  17. Shimura says:

    I enjoy looking through Also, thank you for allowing for me to comment!

  18. westacott says:

    its really high quality articles, you have Youtube Chanel?

  19. wblogers says:

    its useful for me, thanks!!

  20. rodney epub says:

    Great post! what is frequency for new post?, actually i’m very excited to your new post:)

  21. mahalia says:

    Useful article to read when considering to SQL Server, thank you

  22. booreaderz says:

    Nice post! Thanks

  23. henrietta says:

    i hope you are specialist of sql server core,as my knowledge it’s very difficult to understand but you have very easily explain with good finishing, thanks .

  24. volkan says:

    easy language and easily understandable and over all book marble , thanks

  25. volkan says:

    its really good articles

  26. joafe says:

    good work

  27. vanmeter says:

    Howdy Author,
    i have read your many post and also waiting for new post because your every post look like experienced worked with knowledgeable.
    thanks for your wonderful knowledge and work.

  28. darrenolvera says:

    I all the time used to study article in news papers but now as I am a user of internet so from
    now I am using net for content, thanks to web.

  29. essiemac says:

    Please can you tell me your white paper or Books name?

  30. Esquerra says:

    supper !!

  31. digital ocean says:

    this article was extremely remarkable,

  32. Thraen says:

    thank ,Great blog 🙂

  33. Beverly says:

    The example is very practical and straight to the point,good article thanks

  34. Sukienki says:

    Very nice info and straight to the point. I don’t know if this is really the best place to ask but do you people have any thoughts on where to hire some professional writers? Thx

  35. Ashish says:

    My friend, you did the great job, thanks for this knowledgeable blog, keep it up

  36. Monique says:

    I got this website from my friend who informed me about this site and now this time I am visiting this web site and reading very informative posts at this time.

  37. Aurora says:

    It is actually a nice and useful piece of information. I’m
    happy that you simply shared this helpful information with us.

    Please keep us informed like this. Thanks for
    sharing.

  38. Certosimo says:

    Great blog article.Really thank you! Cool.

Leave a Reply

Your email address will not be published. Required fields are marked *