
{"id":7945,"date":"2019-09-08T14:24:09","date_gmt":"2019-09-08T14:24:09","guid":{"rendered":"https:\/\/rax-stg-wp-aws.com\/blogs\/microsoft-sql-server-query-store\/"},"modified":"2026-11-03T19:29:10","modified_gmt":"2026-11-03T19:29:10","slug":"microsoft-sql-server-query-store","status":"publish","type":"blogs","link":"https:\/\/www.rackspace.com\/en-gb\/blogs\/microsoft-sql-server-query-store\/","title":{"rendered":"Microsoft SQL Server Query Store"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>Microsoft\u00a9 SQL Server\u00a9 Query Store, as the name suggests, is like a&nbsp;store that captures the database history of executed queries, query runtime&nbsp;execution statistics, and execution plans. Because the data is stored on a disk,&nbsp;you can retrieve the query store data anytime for troubleshooting purposes, and&nbsp;SQL Server restarts do not affect the data. Use Query Store, which was introduced<br \/>\nin SQL Server 2016 and is available in all later editions, to troubleshoot&nbsp;performance issues caused by query plan changes.<\/p>\n<p>\nYou might find baseline data analysis useful for performance troubleshooting,&nbsp;but until Query Store was introduced, that information was not natively&nbsp;available in SQL server. If Query Store is enabled for a database, it keeps&nbsp;information about executed queries along with execution plans and runtime&nbsp;statistics. It is enabled at the database level and can be enabled for all&nbsp;users&#8217; databases and the MSDB system database. Query store-related information&nbsp;and metadata are stored in internal tables within the database itself. There&nbsp;is no need to manage a separate backup of the Query Store because a standard&nbsp;database backup has all the required information. To view Query Store data,&nbsp;you need to have the `View Database State` permission, and you need to have&nbsp;`<em>DB_Owner<\/em>` rights to force and unforce plans. You can view this data through&nbsp;the management studio and through T-SQL.<\/p>\n<p>&nbsp;<strong>Setting Up Query Store<\/strong><\/p>\n<p>Perform the following steps to enable Query Store for a database:<\/p>\n<p>1. Right-click <strong>Database -&gt; Go to Properties<\/strong>.<br \/>\n2. Under <strong>Select a Page<\/strong>, choose <strong>Select Query Store<\/strong>.<br \/>\n3. In the <strong>General<\/strong>&nbsp;section, change <strong>Operation Mode (Requested)<\/strong>&nbsp;from <strong>Off to Read-Write<\/strong>.<br \/>\n4. Leave the other fields in the <strong>Operation Mode (Requested)<\/strong>&nbsp;drop-down box&nbsp;set to the pre-populated default values.<br \/>\n5. Click <strong>Ok<\/strong>&nbsp;in the database properties box to enable Query Store for the selected database.<\/p>\n<p>You can enable Query Store with T-SQL by using the following code:<\/p>\n<p><em>&nbsp; &nbsp; ALTER DATABASE [DB_Name] SET QUERY_STORE = ON;<\/em><\/p>\n<p><strong>&nbsp;Various Configuration Options of Query Store<\/strong><\/p>\n<p>The following list contains descriptions of some Query Store options:<\/p>\n<p>&#8211;&nbsp; &nbsp; <strong>Operation Mode (Requested)<\/strong>&nbsp;has three values: `<em>Off`, `Read Only`<\/em>, and&nbsp;<em>Read Write`<\/em>. When the Query Store has a mode set to `Read`, no new&nbsp;&nbsp; &nbsp;execution plans or query runtime statistics are collected. This mode is for&nbsp;read-only operations related to Query Store. Changing the mode to `Read Write`&nbsp;enables Query Store to gather queries that are executed, execution plans that are used for those queries, and runtime statistics for those queries run in&nbsp;the selected database.<\/p>\n<p>&#8211;&nbsp; &nbsp; <strong>Data Flush Interval (Minutes)<\/strong>&nbsp;allows you to set how frequently the<br \/>\n&nbsp; &nbsp;collected execution plans and query runtime statistics are flushed from<br \/>\n&nbsp; &nbsp;memory to disk. By default, it is set to 15 minutes.<\/p>\n<p>&#8211;&nbsp;&nbsp; &nbsp;<strong>Statistics Collection Interval<\/strong> defines the aggregation interval of<br \/>\n&nbsp; &nbsp;query runtime statistics that should be used inside the Query Store. By<br \/>\n&nbsp; &nbsp;default, it is set to 60 minutes.<\/p>\n<p>&#8211; &nbsp;<strong>Max Size (MB)<\/strong> is used to configure the maximum size of the Query Store.<br \/>\n&nbsp; &nbsp;By default, it is set to 100 MB. The data in Query Store is stored in the<br \/>\n&nbsp; &nbsp;database where the SQL Server Query Store is enabled. Depending on the size<br \/>\n&nbsp; &nbsp;configured here, after Query Store reaches the maximum size, the operation<br \/>\n&nbsp; &nbsp;mode switches to the `Read Only` mode automatically.<\/p>\n<p>&#8211; &nbsp;<strong>Capture Mode<\/strong> helps you choose which type of query to capture in Query<br \/>\n&nbsp; &nbsp;Store. The default option is `All`, which stores every executed query. When<br \/>\n&nbsp; &nbsp;this option is set to `auto`, Query Store tries to triage which query capture,<br \/>\n&nbsp; &nbsp;by priority, and tries to ignore infrequently executed as well as other ad hoc queries.<\/p>\n<p>&#8211; &nbsp;<strong>Stale Query Threshold (Days)<\/strong> is used to define how long data stays in<br \/>\n&nbsp; &nbsp;Query Store. The default value for this mode is 30 days.<\/p>\n<p><strong>&nbsp;Query Store Reports<\/strong><\/p>\n<p>Query Store includes the following reports:<\/p>\n<p>&#8211;&nbsp; &nbsp; <strong>Regressed Queries<\/strong>: Pinpoint queries for which execution metrics have<br \/>\n&nbsp; &nbsp;recently regressed or changed to worse.<br \/>\n&#8211;&nbsp; &nbsp; <strong>Overall Resource Consumptions<\/strong>: Analyze the total resource consumption<br \/>\n&nbsp; &nbsp;for the database for any of execution metrics.<br \/>\n&#8211;&nbsp;&nbsp; &nbsp;<strong>Top Resource Consuming Queries<\/strong>: Queries which have biggest impact on<br \/>\n&nbsp; &nbsp;database resource consumption.<br \/>\n&#8211;&nbsp;&nbsp; &nbsp;<strong>Queries with Forced Plans<\/strong>: Built-in report, that shows all queries with<br \/>\n&nbsp; &nbsp;forced execution plans.<br \/>\n&#8211;&nbsp;&nbsp; &nbsp;<strong>Queries with High Variation<\/strong>: This report shows the queries with the most<br \/>\n&nbsp; &nbsp;frequent parameterization problems.<br \/>\n&#8211;&nbsp;&nbsp; &nbsp;<strong>Tracked Queries<\/strong>: Track the execution of the most important queries in real<br \/>\n&nbsp; &nbsp;time.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture1_39.png\" alt=\"ms sql pic 1\" \/><\/p>\n<p><strong>&nbsp;Forcing Plans with Query Store<\/strong><\/p>\n<p>Because of a plan regression, a query, which was working fine yesterday, might&nbsp;take too long to execute, consume too many resources or time out today. By&nbsp;default, SQL Server keeps the latest execution plan only for queries. Any&nbsp;changes in the schema, statistics, or indexes could change the query execution&nbsp;plan that is used by the Query Optimizer. The plan can be also dropped due to&nbsp;pressure in the plan cache memory.<\/p>\n<p>Query Store stores query plans and statistical information aggregated over time&nbsp;within each monitored database. Unlike the plan cache, Query Store can retain&nbsp;multiple plans per query and maintain a history of query plan changes along&nbsp;with associated stats per plan. By choosing among various execution plans, you&nbsp;can go ahead and force any execution plan. Query Optimizer then uses this forced&nbsp;execution plan only for the upcoming query executions.<br \/>\n&nbsp;<\/p>\n<p>The <strong>Query Store -&gt; Open Top Resource Consuming Queries<\/strong>&nbsp;report lists queries<br \/>\nthat are resource intensive. Let\u2019s select a query for examination:<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture2_26.png\" alt=\"ms sql pic 2\" \/><\/p>\n<p>Hover your mouse over <strong>Plan<\/strong> to see related statistics.&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture3_21.png\" alt=\"mssql pic 3\" \/><\/p>\n<p>Let&#8217;s compare different plans.<\/p>\n<p><strong>Plan 216 details:<\/strong>&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture4_16.png\" alt=\"mssql pic 4\" \/><\/p>\n<p>&nbsp;<strong>Plan 195 details:<\/strong><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture5_14.png\" alt=\"mssql pic 5\" \/><\/p>\n<p>&nbsp;The average duration for Plan 216 is lower, so it can be used to force this plan&nbsp;in further executions. Click on <strong>Force Plan<\/strong>&nbsp;to see a confirmation screen&nbsp;with the message \u201cDo you want to force plan 216 for query 42?\u201d<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture6_12.png\" alt=\"mssql pic 6\" \/><\/p>\n<p>Click <strong>Yes<\/strong>. &nbsp;After the plan is forced, it is highlighted with a checkmark as&nbsp;shown in the following screenshot. In the future, this plan will be used by&nbsp;query optimizer for execution.&nbsp;<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2026\/blog_article_images\/26550-body-Picture7_9.png\" alt=\"mssql pic 7\" \/><\/p>\n<p><strong>Best Practices with Query Store&nbsp;<\/strong><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>&nbsp; &nbsp;Use the latest SQL Server Management Studio to see the latest features and enhancements.<\/li>\n<li>&nbsp; &nbsp;Verify and monitor the Query Store data collection.<\/li>\n<li>&nbsp; &nbsp;Set the <strong>Optimal Query<\/strong>&nbsp;capture mode and revisit the Query Store&nbsp;configuration option as needed to make adjustments.<\/li>\n<li>&nbsp; &nbsp;Avoid using non-parameterized queries.<\/li>\n<li>&nbsp; &nbsp;Check the status of forced plans regularly.<\/li>\n<\/ul>\n<p><strong>&nbsp;Conclusion<\/strong><\/p>\n<p>Query Store is a useful feature introduced in SQL Server 2016. Because tuning performance enhancements is one of the key skills required for every database&nbsp;administrator (DBA), you should learn how to configure and use Query Store.&nbsp;You can also use Query Store to track performance changes and troubleshoot any&nbsp;degradation in query performance by comparing execution plans. You can force a&nbsp;query plan for any query. This overrides the one saved in the plan cache,&nbsp;and thus provide performance benefits. Query Store has no major impact on SQL&nbsp;Server performance because it is used to capture and save queries execution&nbsp;statistics and plans to be viewed later.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft SQL Server Query Store<\/p>\n","protected":false},"author":2,"featured_media":7947,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","format":"standard","meta":{"content-type":"","nid":"26550","content_type":"blog","created_by":"10130","authored_on":"2024-01-29T15:24:09+00:00","field_article_industries":"","tag_category":"Technical","field_blog_author_text":"by Rackspace Techology Staff","seo_description":"Discover the capabilities of Microsoft SQL Server Query Store. Capture query history and plans for performance troubleshooting.\r\n","field_featured_image":"","insights_image":"\/wp-content\/uploads\/2026\/blog_technical_images\/26550-insights_image-general-code-technical-blog-3-insights.jpg","field_partners":"","rxt_platforms":"MySQL","product":"","publisheddate":"2019-09-08T14:24:09","rxt_solutions":"Databases, Data Management, Data Modernization","opengraph_tag":"","x_tag":"","teaser_flag":"Technical Blog","seo_titile":"Microsoft SQL Server Query Store: Performance Monitoring | Rackspace Technology","field_topics":"","field_slug":"microsoft-sql-server-query-store","footnotes":""},"categories":[178],"tags":[204],"class_list":["post-7945","blogs","type-blogs","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-technical"],"_links":{"self":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs"}],"about":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/types\/blogs"}],"author":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/comments?post=7945"}],"version-history":[{"count":3,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7945\/revisions"}],"predecessor-version":[{"id":9785,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/blogs\/7945\/revisions\/9785"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media\/7947"}],"wp:attachment":[{"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/media?parent=7945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/categories?post=7945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rackspace.com\/en-gb\/wp-json\/wp\/v2\/tags?post=7945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}