Locking comparison SQL Server 2017 versus SQL Server 2022

Paolo Taverna 71 Reputation points
2024-04-22T12:53:22.4133333+00:00

We upgraded from SQL Server 2017 to SQL Server 2022. With SQL Server 2022 we are experiencing a lot more and longer locks.

When long lasting locks happens, a lot of process are getting suspended. As soon that the lock is resolved, the processes are like a waterfall. The CPU consumption goes up to 100%, everything becomes slow.

The only way out is to manually stop the long running Execution or to restart the SQL Server instance.

Its a productive environment and it happens twice a week.

Some advise where to start is very appreciated.

Regards

Paolo

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,756 questions
{count} votes

Accepted answer
  1. CosmogHong-MSFT 23,321 Reputation points Microsoft Vendor
    2024-04-23T03:16:37.29+00:00

    Hi @Paolo Taverna

    Besides of Activity Monitor, you could also use SQL Server Locks object counter in Performance Monitor to view current statistics or create a log or alert to monitor locks.

    For example, you can monitor Average Wait Time, Number of deadlocks/sec and Lock Timeouts/sec statistics to determine whether there is a problem with resource contention on SQL Server.

    Also, you can use the sys.dm_exec_requests DMV to obtain detailed information about the requests currently executing on SQL Server.

    See this article for more details: Different techniques to identify blocking in SQL Server.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Paolo Taverna 71 Reputation points
    2024-04-23T06:25:34.9733333+00:00

    I identified the SQL Statement that are causing the locks. Its the same code we used in the SQL Server 2017. Might be a valid explanation, that the Statements are running longer.

    But it feels like the SQL Server 2017 uses a more optimistic locking as the SQL Server 2022


  2. Bruce (SqlWork.com) 56,686 Reputation points
    2024-04-23T22:06:29.7833333+00:00

    generally with later versions of SQLServer you want to switch to snapshot isolation:

    https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/snapshot-isolation-in-sql-server

    select name, snapshot_isolation_state_desc 
    from sys.databases