2

It is possible to change the SQL Server's default (which is -1 or indefinite period of time) LOCK_TIMEOUT value session-wide.

Is it possible to set LOCK_TIMEOUT default value server-, instance- and/or database-wide? If not, why not?

Aaron Bertrand
182k28 gold badges406 silver badges625 bronze badges
asked Dec 11, 2013 at 8:09
3
  • Wouldn't "server" and "instance" be the same thing? Commented Dec 11, 2013 at 8:14
  • Probably. Really I'd like to set it database-wide or instance-wide. I do not see any sense in impossibility to change indefinite hanging on locked resource behavior or I'd like to understand why it is not configurable. Or might be I am missing this functionality Commented Dec 11, 2013 at 8:53
  • "Instance" and "server" are synonyms in this context as far as opening an instance properties shows a window titled "Server Properties". People seeking for this kind of questions will most probably use "server" keyword in their searching Commented Dec 12, 2013 at 4:04

2 Answers 2

3

No it isn't possible to set this as a default and change it from -1 (no timeout).

If it needs to be changed, you have to be explicit with a call to SET LOCK_TIMEOUT <number of ms for timeout>.

As for why there is no way to alter the default, we can only speculate. But my guess would be that the lack of a timeout would satisfy the majority of requirements for queries, and need to have a lock wait timeout is a pretty corner case scenario, requiring a simple SET statement.

Regardless, you're talking about client-side handling. Not server-side. In fact, most providers that I work with by default enforce a command timeout (i.e. System.Data.SqlClient.SqlCommand.CommandTimeout is set to a default of 30 seconds). Although a bit of a nested requirement with lock requests, it's the same idea.

answered Dec 11, 2013 at 13:25
4
  • Thanks but speculation on satisfying the majority of requirements is wrong. The majority probably uses SQL Server as storage media of out-of-the-box applications without ability to mess with their code base. Even for home-developed apps it is hardly "corner case scenario". And I am talking about database administration ... through its server management Commented Dec 12, 2013 at 0:27
  • Give me a scenario when you would want to use a nondefault lock timeout. Commented Dec 12, 2013 at 0:51
  • It is not on scenario, it is after I set it. From the moment I set it further on Commented Dec 12, 2013 at 2:52
  • As it states in the BOL link Thomas provided it can only be set at the session level. Microsoft provides no other documented method at the database or instance level. Commented Dec 12, 2013 at 4:11
1

Blocking leads to worker thread exhaustion. It is better to allow a lock timeout that is explicit, rather than a command timeout that is ambiguous.

Using Lock timeout set < command timeout you can tell the user they have had a collision with another session. If they reach command timeout it is just a 'heavy' statement.

answered Sep 29, 2023 at 5:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.