Question

The query store on our SQL Server 2016 Standard (SP2 CU6) database has gone into ERROR state and we are now trying to get it back online. All of the articles I've seen regarding troubleshooting QS (e.g. this one, and even Microsoft's own docs) suggest to do the following:

ALTER DATABASE [QDS] SET QUERY_STORE = OFF
exec [QDS].dbo.sp_query_store_consistency_check
ALTER DATABASE [QDS] SET QUERY_STORE = ON
ALTER DATABASE [QDS] SET QUERY_STORE (OPERATION_MODE = READ_WRITE)

But the procedure sp_query_store_consistency_check doesn't seem to exist in any form on our instance. What are we missing?

Was it helpful?

Solution

Like the other Query Store related DMVs, functions, etc, sp_query_store_consistency_check is in the "sys" schema, not the dbo schema. I imagine this is just a typo on Tracy's blog. Still, the command should work even when referencing the dbo schema.

You also need to call the procedure from the user database where you have query store enabled. Try this:

USE YourDatabaseName;
GO

EXEC sys.sp_query_store_consistency_check;

Tony mentioned in the comments that he couldn't find the stored procedure definition anywhere. This is typical of extended stored procedures. Running EXEC sp_helptext 'sys.sp_query_store_consistency_check'; on it, even from a DAC connection, returns this:

Text
-----------------
(server internal)

You can see it mentioned in sys.all_objects though:

SELECT 
    [name],
    [type_desc],
    is_ms_shipped
FROM sys.all_objects 
WHERE [name] LIKE '%consistency%';

Results:

name                              type_desc                 is_ms_shipped
--------------------------------- ------------------------- -------------
sp_query_store_consistency_check  EXTENDED_STORED_PROCEDURE 1

My mistake, I just realized that you are on SQL Server 2016. The above procedure was introduced in SQL Server 2017.

The only way I know of to get the Query Store back into a good state in 2016 is to clear out all the data:

ALTER DATABASE [YourDatabaseName] 
SET QUERY_STORE CLEAR ALL;
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top