Why Query Store Actual Operation Mode is Not Same as Requested? – Interview Question of the Week #248

Question: Why can Query Store’s actual mode differ from its requested mode? The request is the desired setting; the actual state also reflects conditions that prevent Query Store from writing. Check readonly_reason before trying to change it.

A cabinet's contents are visible through glass while a locked door prevents additions

A bank hired me to investigate query regression. After tuning the queries and teaching their team how to use Query Store, I heard from the DBA three days later. Requested mode said Read Write; actual mode said Read Only. They had even restarted the server while looking for an answer.

Original SSMS Query Store properties show actual Read Only and requested Read Write
The original historical SSMS capture shows the mismatch clearly.

In this case the database itself had been marked read-only. Query Store keeps its data in that database, so it couldn’t continue writing its history. The second original capture reveals the cause.

Original SSMS Database Read-Only property is True
For this client, Database Read-Only needed to change from True to False. The old paragraph reversed those values; this caption corrects it.
SELECT name, is_read_only
FROM sys.databases
WHERE database_id = DB_ID();

SELECT desired_state_desc, actual_state_desc, readonly_reason,
       current_storage_size_mb, max_storage_size_mb
FROM sys.database_query_store_options;

-- Historical example only: change a disposable TestDb deliberately,
-- after confirming it should be writable. These commands are not run here.
-- USE master;
-- ALTER DATABASE TestDb SET READ_ONLY WITH NO_WAIT;
-- ALTER DATABASE TestDb SET READ_WRITE WITH NO_WAIT;

Run the diagnostic queries in the affected database. readonly_reason is a bitmap: bit 1 indicates a read-only database, while bit 65536 indicates the configured Query Store storage limit. Other documented reasons include a secondary replica, single-user mode and internal memory limits. The two properties alone do not identify which cause applies.

For this particular case, making the database writable again removed the obstacle, provided its intended design was read-write. Don’t change a deliberate read-only database or secondary just to satisfy the requested Query Store mode. A storage-limit problem needs a different remedy.

The commented TestDb commands preserve the original illustration. NO_WAIT can fail rather than waiting for required locks; it isn’t a general repair button. A service restart didn’t address the client’s database setting and also discarded some transient troubleshooting history.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

Query Store, SQL Scripts, SQL Server, SQL Server Configuration
Previous Post
Retrieve TOP 10 Rows Without Using TOP or LIMIT? – Interview Question of the Week #247
Next Post
How to Use GOTO command in SQL Server? – Interview Question of the Week #249

Related Posts

1 Comment. Leave new

  • Nice post Pinal! This happened to me on and Amazon RDS instance. My DB was not in ReadOnly state, but following your notes, I moved my DB to ReadOnly and then back to ReadWrite state, and that solved the Query Store operation mode issue. Thanks!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.