How to See Rowcounts and Execution Time for In-Flight Queries in SQL Server
I frequently need to see rowcounts and execution time for queries while they’re running. Maybe I’m troubleshooting a slow query …
Read MoreBy Kendra Little on • 3 min read
I recently did a Dear SQL DBA episode answering a question about lock timeouts and memory in SQL Server. I really enjoyed the episode, and thought it would be fun to follow up and show what it looks like if SQL Server doesn’t have enough memory to allocate locks.
You can control how much memory SQL Server allocates for locks using the “locks” configuration option. At least for now: the configuration option is deprecated.
Microsoft recommends that you do NOT change this setting, and let SQL Server manage your locks dynamically.
I agree with them. Don’t mess around with the locks setting.
That being said…
I’m going to change the lock configuration setting so that my SQL Server runs out of memory for locks pretty easily. Here’s my formula for lock memory starvation, using the WideWorldImporters sample database:
BEGIN TRAN
SELECT OrderLineID
FROM Sales.OrderLines WITH (HOLDLOCK, ROWLOCK)
The HOLDLOCK hint tells SQL Server to run in serializable mode for this table. That makes it “hold” locks for the life of the transaction – not just take out and release locks as it rolls through the table.
The ROWLOCK hint tells SQL Server to use the most granular form of locks. SQL Server would “escalate” these locks to the table level so that it wasn’t so granular, but we disallowed that as part of our lock starvation formula.
My instance manages to stream 4837 rows back to me before it fails with this error:
Msg 1204, Level 19, State 4, Line 8 The instance of the SQL Server Database Engine cannot obtain a LOCK resource at this time. Rerun your statement when there are fewer active users. Ask the database administrator to check the lock and memory configuration for this instance, or to check for long-running transactions.
The message comes back to my session. The message is also in the SQL Server error log, with my session_id as the source. And the message is written to the Windows Event Log under Application, too, where it shows as an error.
In my case, though, the problem isn’t that I have too many active users, as the error message suggests. Or even that I don’t have enough memory.
As for me, I’m going to set the ’locks’ setting back to 0, restart my instance, and pretend this never happened.
Copyright (c) 2025, Catalyze SQL, LLC; all rights reserved. Opinions expressed on this site are solely those of Kendra Little of Catalyze SQL, LLC. Content policy: Short excerpts of blog posts (3 sentences) may be republished, but longer excerpts and artwork cannot be shared without explicit permission.