Query optimization

Surendra Adhikari 206 Reputation points
2021-10-03T10:36:15.73+00:00

A query is running very slow with wait type dirty_page_table_lock.
How to fix this? please help.

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,713 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,552 questions
{count} votes

Accepted answer
  1. Dan Guzman 9,206 Reputation points
    2021-10-03T11:35:26.417+00:00

    @Surendra Adhikari , the link @Sreeju Nair provided opens for me. I copy/pasted some of the text from the page below for your convenience. Install the latest SP or CU if you are not already done so.

    KB4163087 - FIX: Performance is slow for an Always On AG when you process a read query in SQL Server
    SQL Server 2016 Developer SQL Server 2016 Enterprise More...
    Symptoms
    Assume that you have an Always On Availability Group (AG) in SQL Server 2016 and 2017. When you process a read query on a secondary replica, the performance might be much slower than the primary replica due to frequent DIRTY_PAGE_TABLE_LOCK waits.

    Cause
    This issue occurs because of contention between the read query and the redo thread, and because the table is locked.

    Resolution
    This fix is included in the following updates for SQL Server:

    Cumulative Update 8 for SQL Server 2017

    Cumulative Update 1 for SQL Server 2016 Service Pack 2

    Cumulative Update 9 for SQL Server 2016 Service Pack 1

    Workaround
    To work around this issue you can use a single redo thread instead of a parallel redo thread by enabling Trace Flag 3459.

    More Information
    When read-only queries are running on a readable secondary replica, query threads attempt to apply pending log redo operations and need to collaborate with redo worker threads with DIRTY_PAGE_TABLE_LOCK waits, which can be frequently generated and slow down both redo and query performance if there are concurrent redo workloads. The performance issue associated with DIRTY_PAGE_TABLE_LOCK wait is addressed in the cumulative update release for SQL Server 2016 SP and SQL Server 2017 mentioned in this article.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Sreeju Nair 11,606 Reputation points
    2021-10-03T10:41:30.27+00:00

  2. CathyJi-MSFT 21,091 Reputation points Microsoft Vendor
    2021-10-04T00:47:46.79+00:00

    Hi @Surendra Adhikari ,

    dirty_page_table_lock this wait type is when a thread is waiting for access to the list of dirty pages during parallel redo or a read query on an Availability Group readable secondary replica.

    Did your SQL server instance is in SQL AG environment? And please using select @@version to check the SQL Server version. If your environment is similar to the situation as the MS blog mentioned, please apply the latest SP or CU to your SQL server instance. If not, please describe your environment and issue more clearly to make us better understood your issue.

    By the way, we can download the latest patch for SQL server from this link. We can follow the steps from this MS document to upgrade SQL AG replica instances.


    If the response is helpful, please click "Accept Answer" and upvote it, as this could help other community members looking for similar thread.

    0 comments No comments