{"id":841,"date":"2017-05-31T13:55:48","date_gmt":"2017-05-31T20:55:48","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/erin\/?p=841"},"modified":"2020-11-05T09:39:10","modified_gmt":"2020-11-05T17:39:10","slug":"query-store-trace-flags","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/","title":{"rendered":"Query Store Trace Flags"},"content":{"rendered":"<p>Microsoft <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/database-console-commands\/dbcc-traceon-trace-flags-transact-sql\">maintains a list of supported trace flags<\/a> and I noticed that there are two new ones related to Query Store: 7745 and 7752.\u00a0 The descriptions for these Query Store Trace Flags are pretty straight-forward, but for those of you not familiar with Query Store, I thought I&#8217;d provide some context and details.<\/p>\n<p><strong>7745<\/strong><\/p>\n<p>When you enable and configure Query Store, one setting to consider is <code>DATA_FLUSH_INTERVAL_SECONDS<\/code>.\u00a0 This setting defaults to 900 (15 minutes), and it determines how frequently Query Store data will be flushed to disk.\u00a0 As a reminder, some Query Store data is stored in memory as an optimization.\u00a0 If Query Store had to flush data to disk every time a query executed, Query Store would quickly become your biggest performance problem, therefore data is temporarily stored in memory.\u00a0 The <code>DATA_FLUSH_INTERVAL_SECONDS<\/code> setting controls the maximum amount of time SQL Server will wait to flush data from memory to disk, but know that data could be flushed more frequently (also as an optimization).\u00a0 When I first learned about Query Store, it was my understanding that this setting was a tradeoff between &#8220;how much Query Store data are you willing to lose if your server unexpectedly shuts down&#8221; and &#8220;how much of a performance impact do you want to introduce by having Query Store write data to disk (internal tables in the user database) more frequently&#8221;?\u00a0 Because the Query Store data is not business critical, my advice has been that 15 minutes is a good balance.\u00a0 However, I now know that when you initiate a shutdown of SQL Server, by default it will <strong>wait<\/strong> to write that Query Store data to disk &#8211; and I&#8217;ll be honest in that I don&#8217;t know how long it will wait.\u00a0 In some cases (e.g. a fail over in a HA\/DR scenario), you might not want to wait any longer than absolutely necessary for SQL Server to shut down.\u00a0 In that case, you can either use SHUTDOWN WITH NOWAIT (not what I would recommend at all) or trace flag 7745 to bypass writing any Query Store data still in memory to disk.\u00a0 Using 7745 means that you can lose some Query Store data.<\/p>\n<p><strong>7752<\/strong><\/p>\n<p>When you start SQL Server, it loads some data from the Query Store internal tables into memory (again, this is an optimization to make specific capabilities of Query Store complete quickly).\u00a0 In some cases this is a small amount of data, in other cases, it&#8217;s larger (potentially a few GB), and as such, it can take seconds or minutes to load. As a result, if you execute a query <em>before<\/em> the Query Store data has finished loading, the query <em>will\u00a0not execute<\/em> until the data has been loaded. \u00a0To load the Query Store asynchronously, and still allow queries to execute, use trace flag 7752.\u00a0 With this trace flag enabled, queries can execute while the Query Store data is being loaded asynchronously in the background, however, Query Store is in a read-only state.\u00a0 No query information will be written to Query Store until after the data has been loaded into memory.\u00a0 If you don&#8217;t know if Query Store is taking a long time to load and thus impacting your queries, set up an Extended Events session that captures the WAIT_INFO event, filtering on the QDS_LOADDB wait_type, and have it run at startup (and also have a job that stop the XE session 10 or 15 minutes after SQL Server starts up &#8211; you don&#8217;t need to continuously run this session).\u00a0 After one or more restarts, check the XE output and see if you have any events for the QDS_LOADDB wait type, and if so, add up the total duration for the wait type and compare it against the startup duration for the instance.<\/p>\n<p>Finally, know that the behavior of trace flag 7752 may become the default behavior in a future release &#8211; that&#8217;s yet to be determined &#8211; but if it did, there will ideally be a status change to Query Store to signify that during the asynchronous data load it is in a read-only state.<\/p>\n<p><strong>My thoughts<\/strong><\/p>\n<p>I always expected that I could potentially lose Query Store data, and so I&#8217;m still ok with that.\u00a0 When I ask SQL Server to shut down, I want it to shut down as quickly and efficiently as it always has, so I&#8217;m pretty sure I&#8217;m going to be enabling 7745.<\/p>\n<p>I will also enable trace flag 7752.\u00a0 While I can check to see if I&#8217;m experiencing the QDS_LOADDB, if this will become the default behavior in the future, I might as well adopt it now!<\/p>\n<p><em>Update September 2019: The behavior of <a href=\"https:\/\/docs.microsoft.com\/en-us\/sql\/t-sql\/database-console-commands\/dbcc-traceon-trace-flags-transact-sql?view=sql-server-2017\">trace flag 7752<\/a> will be the default behavior in SQL Server 2019.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Microsoft maintains a list of supported trace flags and I noticed that there are two new ones related to Query Store: 7745 and 7752.\u00a0 The descriptions for these Query Store Trace Flags are pretty straight-forward, but for those of you not familiar with Query Store, I thought I&#8217;d provide some context and details. 7745 When [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Query Store Trace Flags - Erin Stellato<\/title>\n<meta name=\"description\" content=\"There are two trace flags that can be used to modify the default Query Store behavior, related to start up and shut down and what happens with the data.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Query Store Trace Flags - Erin Stellato\" \/>\n<meta property=\"og:description\" content=\"There are two trace flags that can be used to modify the default Query Store behavior, related to start up and shut down and what happens with the data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/\" \/>\n<meta property=\"og:site_name\" content=\"Erin Stellato\" \/>\n<meta property=\"article:published_time\" content=\"2017-05-31T20:55:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-05T17:39:10+00:00\" \/>\n<meta name=\"author\" content=\"Erin Stellato\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Erin Stellato\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/\",\"name\":\"Query Store Trace Flags - Erin Stellato\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\"},\"datePublished\":\"2017-05-31T20:55:48+00:00\",\"dateModified\":\"2020-11-05T17:39:10+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\"},\"description\":\"There are two trace flags that can be used to modify the default Query Store behavior, related to start up and shut down and what happens with the data.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Query Store Trace Flags\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\",\"name\":\"Erin Stellato\",\"description\":\"The SQL Sequel\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\",\"name\":\"Erin Stellato\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g\",\"caption\":\"Erin Stellato\"},\"sameAs\":[\"http:\/\/3.209.169.194\/blogs\/erin\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/author\/erin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Query Store Trace Flags - Erin Stellato","description":"There are two trace flags that can be used to modify the default Query Store behavior, related to start up and shut down and what happens with the data.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/","og_locale":"en_US","og_type":"article","og_title":"Query Store Trace Flags - Erin Stellato","og_description":"There are two trace flags that can be used to modify the default Query Store behavior, related to start up and shut down and what happens with the data.","og_url":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/","og_site_name":"Erin Stellato","article_published_time":"2017-05-31T20:55:48+00:00","article_modified_time":"2020-11-05T17:39:10+00:00","author":"Erin Stellato","twitter_misc":{"Written by":"Erin Stellato","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/","name":"Query Store Trace Flags - Erin Stellato","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website"},"datePublished":"2017-05-31T20:55:48+00:00","dateModified":"2020-11-05T17:39:10+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158"},"description":"There are two trace flags that can be used to modify the default Query Store behavior, related to start up and shut down and what happens with the data.","breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-trace-flags\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/erin\/"},{"@type":"ListItem","position":2,"name":"Query Store Trace Flags"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/","name":"Erin Stellato","description":"The SQL Sequel","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/erin\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158","name":"Erin Stellato","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0c8b485bd54ea26b57e99f79b525f409?s=96&d=mm&r=g","caption":"Erin Stellato"},"sameAs":["http:\/\/3.209.169.194\/blogs\/erin"],"url":"https:\/\/www.sqlskills.com\/blogs\/erin\/author\/erin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/841"}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/comments?post=841"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/841\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/media?parent=841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/categories?post=841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/tags?post=841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}