Configuring Query Store

As shown in the previous section, to enable Query Store you need to set only one parameter or click once. When you do this, you have enabled it with default values for all of its parameters. There is a collection of Query Store options that can be configured. Again, you can set them through SSMS or Transact-SQL. However, some of them have different names and even metrics in both tools. Here is a list of configurable Query Store parameters:

  • Operation Mode defines the operation mode of the Query Store. Only two modes are supported: READ_WRITE and READ_ONLY. The default value is READ_WRITE, which means that Query Store collects query plans and runtime statistics and writes them to the disk. READ_ONLY mode makes sense only when the collected info in the Query Store exceeds the maximum allocated space for it. In this case, the mode is set to READ_ONLY automatically. The name of the parameter in the ALTER DATABASE Transact-SQL statement is OPERATION_MODE.
  • Max Size (MB) determines the space in megabytes allocated to the Query Store. The parameter data type is bigint; the default value is 100. The name of the parameter in the ALTER DATABASE Transact-SQL statement is STORAGE_SIZE_MB.
  • Statistics Collection Interval defines a fixed time window at which runtime execution statistics data is aggregated into the Query Store. The parameter data type is bigint; the default value is 60.The name of the parameter in the ALTER DATABASE Transact-SQL statement is INTERVAL_LENGTH_MINUTES.
  • Data Flush Interval (Minutes) determines the frequency at which data written to the Query Store is persisted to disk. The parameter data type is bigint; the default value is 15. The minimum value is 1 minute. If you want to use it in the ALTER DATABASE Transact-SQL statement its name is DATA_FLUSH_INTERVAL_SECONDS. As you can see, in Transact-SQL you need to use seconds, and in SSMS minutes as the parameter metric. It seems that consistency is lost somewhere between these two configuration modes.
  • Query Store Capture Mode defines the scope of queries that will be captured. The parameter data type is nvarchar, and it has the following values: AUTO (only relevant queries based on execution count and resource consumption are captured), ALL (all queries are captured), and NONE (new queries are not captured, only info about already captured queries). The default value is ALL. The name of the parameter in the ALTER DATABASE Transact-SQL statement is QUERY_CAPTURE_MODE.
  • Stale Query Threshold (Days) controls the retention period of persisted runtime statistics and inactive queries. The parameter data type is bigint; the default value is 30 days. When you use Transact-SQL you need to know that this parameter is a part of another parameter called CLEANUP_POLICY. The following Transact-SQL code configures the Stale Query Threshold parameter for Query Store in the WideWorldImporters database to 60 days:
ALTER DATABASE WideWorldImporters 
SET QUERY_STORE (CLEANUP_POLICY = (STALE_QUERY_THRESHOLD_DAYS = 60)); 
  • Size Based Cleanup Mode controls whether cleanup will be automatically activated when the total amount of data gets close to the maximum size. The parameter data type is nvarchar, and it has the following values: AUTO (size-based cleanup will be automatically activated when its size on the disk reaches 90% of max_storage_size_mb)). Size-based cleanup removes the least expensive and oldest queries first. It stops at approximately 80% of max_storage_size_mb, ALL (all queries are captured) and OFF (size based cleanup won't be automatically activated). The default value is OFF. The name of the parameter in the ALTER DATABASE Transact-SQL statement is SIZE_BASED_CLEANUP_MODE.
  • MAX_PLANS_PER_QUERY determines the maximum number of plans maintained for a single query. The parameter data type is int; the default value is 200. This parameter is inconsistently implemented, too. It is not even shown on the Query Store property page and can be set only using Transact-SQL.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.52.208