question

SurendraAdhikari-2570 avatar image
0 Votes"
SurendraAdhikari-2570 asked Cathyji-msft commented

Query optimization

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

sql-server-generalsql-server-transact-sql
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SurendraAdhikari-2570,

Just checking in to see if the answer(s) helped.
If an answer is helpful, please "Accept answer" or "Up-Vote" for the same which might be beneficial to other community members reading this thread.
And If you have further questions or issues please let us know.

0 Votes 0 ·
DanGuzman avatar image
0 Votes"
DanGuzman answered DanGuzman edited

@SurendraAdhikari-2570 , the link @sreejukg 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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

sreejukg avatar image
0 Votes"
sreejukg answered ErlandSommarskog commented
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello sreejukg, the link does not open.

0 Votes 0 ·
ErlandSommarskog avatar image ErlandSommarskog SurendraAdhikari-2570 ·

Hello sreejukg, the link does not open.

That may be a problem at your end. The link works for me.

Then whether the link is applicable to you - I have no idea. When you post a question, you need to include information about your environment. That is, the output of "SELECT @@version", the actual query and the query plan. For this issue, it may also be relevant to know if you are in an Availability Group, and if so, if the query is running against the primary or a readable secondary.

0 Votes 0 ·
Cathyji-msft avatar image
0 Votes"
Cathyji-msft answered

Hi @SurendraAdhikari-2570,

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.