You can watch the replay for this IDERA Live webcast, Leverage the Query Store for Better SQL Server Performance, on the IDERA Resource Center, http://ow.ly/bHys50A4rH8.
SQL Server’s Query Store, since its introduction with SQL Server 2016, is becoming better utilized by database administrators to review the history and performance of SQL queries. The Query Store collects useful information for SQL queries such as run time statistics and execution plans for analysis and reporting. Join this session with Bullett Manale to learn more about how the Query Store works, how to configure it, and how IDERA’s SQL Diagnostic Manager can leverage the Query Store to improve the performance of SQL queries.
Speaker: Bullett Manale is IDERA’s Director of Sales Engineering, has been working in technology for over 25 years. Starting as a tech support technician for Iomega supporting their backup software, he has since been a technical trainer and consultant for Deloitte, a sales engineer at Centerbeam, and a project manager at Shell Oil Company.
DB_Owner is required for forcing a query plan as well as other administrative commands like flush interval
The unique query plan and query text, if new, will directly be passed to ASYNC Writer which will write it to disk. The query run time statistics will not be directly written to the ASYNC Writer. The query run time statistics will be written at a specific time interval that is set in the Data Flush Interval (Minutes) option.
https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-database-query-store-options-transact-sql?view=sql-server-2017
APPLIES TO: SQL Server (starting with 2016) Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse
Returns the Query Store options for this database.
Applies to: SQL Server ( SQL Server 2016 (13.x) through SQL Server 2017), SQL Database.
Column nameData typeDescriptiondesired_statesmallintIndicates the desired operation mode of Query Store, explicitly set by user.0 = OFF 1 = READ_ONLY2 = READ_WRITEdesired_state_descnvarchar(60)Textual description of the desired operation mode of Query Store:OFFREAD_ONLYREAD_WRITEactual_statesmallintIndicates the operation mode of Query Store. In addition to list of desired states required by the user, actual state can be an error state.0 = OFF 1 = READ_ONLY2 = READ_WRITE3 = ERRORactual_state_descnvarchar(60)Textual description of the actual operation mode of Query Store.OFFREAD_ONLYREAD_WRITEERRORThere are situations when actual state is different from the desired state:- If the database is set to read-only mode or if Query Store size exceeds its configured quota, Query Store may operate in read-only mode even if read-write was specified by the user.- In extreme scenarios Query Store can enter an ERROR state because of internal errors. If this happens, Query Store can be recovered by executing the sp_query_store_consistency_check stored procedure in the affected database.readonly_reasonintWhen the desired_state_desc is READ_WRITE and the actual_state_desc is READ_ONLY, readonly_reason returns a bit map to indicate why the Query Store is in readonly mode.1 - database is in read-only mode2 - database is in single-user mode4 - database is in emergency mode8 - database is secondary replica (applies to Always On and Azure SQL Database geo-replication). This value can be effectively observed only on readable secondary replicas65536 - the Query Store has reached the size limit set by the MAX_STORAGE_SIZE_MB option.131072 - The number of different statements in Query Store has reached the internal memory limit. Consider removing queries that you do not need or upgrading to a higher service tier to enable transferring Query Store to read-write mode.Applies to: Azure SQL Database.262144 - Size of in-memory items waiting to be persisted on disk has reached the internal memory limit. Query Store will be in read-only mode temporarily until the in-memory items are persisted on disk. Applies to: Azure SQL Database.524288 - Database has reached disk size limit. Query Store is part of user database, so if there is no more available space for a database, that means that Query Store cannot grow further anymore.Applies to: Azure SQL Database. To switch the Query Store operations mode back to read-write, see Verify Query Store is Collecting Query Data Continuously section of Best Practice with the Query Store.current_storage_size_mbbigintSize of Query Store on disk in megabytes.flush_interval_secondsbigintThe period for regular flushing of Query Store data to disk in seconds. Default value is 900 (15 min).Change by using the ALTER DATABASE <database> SET QUERY_STORE (DATA_FLUSH_INTERVAL_SECONDS = <interval>)statement.interval_length_minutesbigintThe statistics aggregation interval in minutes. Arbitrary values are not allowed . Use one of the following: 1, 5, 10, 15, 30, 60, and 1440 minutes. The default value is 60minutes.max_storage_size_mbbigintMaximum disk size for the Query Store in megabytes (MB). Default value is 100 MB.For SQL Database Premium edition, default is 1 GB and for SQL Database Basic edition, default is 10 MB.Change by using the ALTER DATABASE <database> SET QUERY_STORE (MAX_STORAGE_SIZE_MB = <size>)statement.stale_query_threshold_daysbigintNumber of days that queries with no policy settings are kept in Query Store. Default value is 30. Set to 0 to disable the retention policy.For SQL Database Basic edition, default is 7 days.Change by using the ALTER DATABASE <database> SET QUERY_STORE ( CLEANUP_POLICY = ( STALE_QUERY_THRESHOLD_DAYS = <value> ) )statement.max_plans_per_querybigintLimits the maximum number of stored plans. Default value is 200. If the maximum value is reached, Query Store stops capturing new plans for that query. Setting to 0 removes the limitation with regards to the number of captured plans.Change by using the ALTER DATABASE<database> SET QUERY_STORE (MAX_PLANS_PER_QUERY = <n>)statement.query_capture_modesmallintThe currently active query capture mode:1 = ALL - all queries are captured. This is the default configuration value for SQL Server (SQL Server 2016 (13.x) through SQL Server 2017).2 = AUTO - capture relevant queries based on execution count and resource consumption. This is the default configuration value for SQL Database.3 = NONE - stop capturing new queries. Query Store will continue to collect compile and runtime statistics for queries that were captured already. Use this configuration cautiously since you may miss to capture important queries.query_capture_mode_descnvarchar(60)Textual description of the actual capture mode of Query Store:ALL (default for SQL Server 2016 (13.x))AUTO (default for SQL Database)NONEsize_based_cleanup_modesmallintControls whether cleanup will be automatically activated when total amount of data gets close to maximum size:0 = OFF - size based cleanup won't be automatically activated.1 = AUTO - size based cleanup will be automatically activated when size on disk reaches 90 percent of max_storage_size_mb. This is the default configuration value.Size based cleanup removes the least expensive and oldest queries first. It stops when approximately 80 percent of max_storage_size_mb is reached.size_based_cleanup_mode_descnvarchar(60)Textual description of the actual size-based cleanup mode of Query Store:OFF AUTO (default)wait_stats_capture_modesmallintControls whether Query Store performs capture of wait statistics: 0 = OFF 1 = ONApplies to: SQL Server 2017 (14.x) through SQL Server 2017.wait_stats_capture_mode_descnvarchar(60)Textual description of the actual wait statistics capture mode: OFF ON (default)Applies to: SQL Server 2017 (14.x) through SQL Server 2017.