How to fix Query Store in READ_ONLY mode due to read_only reason 262144

Pavel Spitz 30 Reputation points
2024-08-16T08:05:51.0633333+00:00

We are running

Microsoft SQL Server 2022 Enterprise edition version 16.0.4115.5 (X64)

SQL Server has 254 Cores, 7.5 TB RAM dedicated for SQL Server
SQL Server is running in HA cluster -1 primary and 3 secondary replicas (1 synchronous, 2 asynchronous commit)
Number of databases on the SQL Server are 166.

Query store is enabled in all our databases and configured with default values via Microsoft recommendations (meaning documentation) in primary replica only. Exception is MAX_STORAGE_SIZE_MB which is set to approprite value for every database.

Query store on many databases has started automatically switching to READ_ONLY mode and back to READ_WRITE after we installed SQL Server 2022. Switching to READ_ONLY mode is due to readonly_reason= 262144 (i.e. query store internal memory limit was reached).
We tried to find some information about the query store internal memory limit, but there isn't any information about value of the limit value and how this can be increased. We found only information that this value of memory limit can be automatically set by SQL Server engine and changed in according to server size of memory.

The situation on many databases is rather problematic for us, because switching to READ_ONLY mode is depend on the database load and amount of queries. Some of the most heavily loaded databases are switched to READ_ONLY mode practically forever. With this new feature of Query Store, we practically lost information about the queries running there mainly on our most important databases.

Are there any possibilities how to prevent query store automatically switched to READ_ONLY mode due to the reason 262144?

SQL Server Other
{count} vote

4 answers

Sort by: Most helpful
  1. Pavel Spitz 30 Reputation points
    2024-09-05T08:18:43.5233333+00:00

    We have found out the reason why QueryStore is almost silently switched to ReadOnly mode. The cause was a past attempt to eliminate the high spinlock of SOS_CACHESTORE by enabling TF 174. We found it in our logs that the QueryStore problem is temporally correlated with turning on this TF 174. We have now turned it off and performed a Failover and the problem with QueryStore automatically switching to ReadOnly mode has disappeared.

    I apologize you for the longer reaction, but turning off TF and performing Failover was a time-consuming operation. We must always plan the time of the Failover execution with sufficient time in advance.

    4 people found this answer helpful.

  2. Anonymous
    2024-08-16T09:06:58.3233333+00:00

    Hi @Pavel Spitz,

    Thank you for your reaching out and welcome to Microsoft Q&A!

    Are there any possibilities how to prevent query store automatically switched to READ_ONLY mode due to the reason 262144?

    Once the query store is enabled, you really need to monitor things to make sure the settings work for your workload. There are some guidelines in the following documentation: Best Practice with the Query Store. (There is no link to the documentation you mentioned. Maybe it is this article I provide here.)

    You could also refer to this official documentation to improve the management of Query Store.

    https://callihandata.com/2024/06/03/why-did-query-store-switch-to-read_only/

    In addition, it provides steps about Query Store Data Cleanup manually in detail, hope it can help you resolve the issue.

    Feel free to share your issues here if you have any concerns!

    Best regards,

    Lucy Chen


    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".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    https://docs.microsoft.com/en-us/answers/support/email-notifications


  3. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2024-08-16T21:30:39.0433333+00:00

    I would recommend that you open a support case. Given the beefy server you have, I am inclined to think that you have a beefy support contract as well.

    There are several reasons I make this suggestion. One is that this sounds way more advanced than we have knowledge for here in the forums. A qualified escalation engineer may be able to give you good advice.

    It could also be that the answer is "tough luck", but this is the situation you play the card "this is not acceptable for us", and if you play it well enough, Microsoft will have to think of a way to improve the situation.

    Of course, that depends on exactly how much memory of all those 7.5 RAM that Query Store is consuming. A query like

    SELECT * FROM sys.dm_os_memory_clerks  WHERE type LIKE '%QDS%'
    

    may reveal something. My gut feeling that the total will be way below those 7.5 TB. But I've been wrong before.


  4. Pavel Spitz 30 Reputation points
    2024-09-06T11:11:38.5533333+00:00

    I am very sorry for my previous post where I wrote that we had found reason of our problem with query store automatic switching to READ_ONLY mode by turnning off TF174. Our database's query stores on the server have perfectly run without switching about 24 hours, but now this problem has been completely back.

    Now we will contact Microsoft support.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.