{"id":1089,"date":"2020-02-04T06:30:58","date_gmt":"2020-02-04T14:30:58","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/erin\/?p=1089"},"modified":"2020-02-04T08:49:12","modified_gmt":"2020-02-04T16:49:12","slug":"are-changes-to-query-store-logged","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/","title":{"rendered":"Are Changes to Query Store Logged?"},"content":{"rendered":"<p>The Query Store feature is a bit unique in that its status can change without user interference, which means it is important to understand how changes to Query Store are logged.\u00a0 A couple weeks ago <a href=\"https:\/\/twitter.com\/SQLMCT\/\">John Deardurff<\/a> posted a question on Twitter asking specifically whether the SQL Server ERRORLOG is written to when the OPERATION_MODE changes to READ_ONLY because\u00a0 MAX_STORAGE_SIZE_MB is exceeded.\u00a0 I had never tested to confirm, but I know there is an event in Extended Events that will fire when the limit is reached.\u00a0 I also know that when a user makes a change to a Query Store setting, it is logged in the ERRORLOG.<\/p>\n<h2>User Changes<\/h2>\n<p>With a copy of <a href=\"https:\/\/github.com\/Microsoft\/sql-server-samples\/tree\/master\/samples\/databases\/wide-world-importers\">WideWorldImporters<\/a> restored in my SQL Server 2019 VM, I will create an Extended Events with a few events I think will be relevant:<\/p>\n<p>CREATE EVENT SESSION [XEStatusChange]<br \/>\nON SERVER<br \/>\nADD EVENT qds.query_store_db_settings_changed,<br \/>\nADD EVENT qds.query_store_disk_size_info,<br \/>\nADD EVENT qds.query_store_disk_size_over_limit<br \/>\nADD TARGET package0.event_file(SET filename=N&#8217;C:\\temp\\XEStatus&#8217;,max_file_size=(256))<br \/>\nWITH (MAX_MEMORY=4096 KB, EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS, MAX_DISPATCH_LATENCY=30 SECONDS, MAX_EVENT_SIZE=0 KB, MEMORY_PARTITION_MODE=NONE,&amp;nbsp; TRACK_CAUSALITY=OFF, STARTUP_STATE=OFF);<br \/>\nGO<\/p>\n<p>&nbsp;<\/p>\n<p>Next, we will change the MAX_STORAGE_SIZE_MB to just 5MB.\u00a0 Note that this is an extremely low value that I do not recommend.<\/p>\n<p>USE [master];<br \/>\nGO<br \/>\nALTER DATABASE [WideWorldImporters]<br \/>\nSET QUERY_STORE (<br \/>\nOPERATION_MODE = READ_WRITE,<br \/>\nMAX_STORAGE_SIZE_MB = 5<br \/>\n);<br \/>\nGO<\/p>\n<p>&nbsp;<\/p>\n<p>If we look at the output from Extended Events, we can see that my change to Query Store is logged:<\/p>\n<figure id=\"attachment_1090\" aria-describedby=\"caption-attachment-1090\" style=\"width: 954px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0.jpg\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-1090\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0.jpg\" alt=\"Extended Events output after Query Store MAX_STORAGE_SIZE changed to 5MB via TSQL\" width=\"954\" height=\"57\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0.jpg 954w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0-300x18.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0-768x46.jpg 768w\" sizes=\"(max-width: 954px) 100vw, 954px\" \/><\/a><figcaption id=\"caption-attachment-1090\" class=\"wp-caption-text\">Extended Events output after Query Store MAX_STORAGE_SIZE changed to 5MB via TSQL<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>If we check the ERRORLOG, information about the change exists there as well:<\/p>\n<figure id=\"attachment_1092\" aria-describedby=\"caption-attachment-1092\" style=\"width: 1017px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings2.jpg\"><img decoding=\"async\" class=\"size-full wp-image-1092\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings2.jpg\" alt=\"ERRORLOG entry showing Query Store setting change\" width=\"1017\" height=\"80\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings2.jpg 1017w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings2-300x24.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings2-768x60.jpg 768w\" sizes=\"(max-width: 1017px) 100vw, 1017px\" \/><\/a><figcaption id=\"caption-attachment-1092\" class=\"wp-caption-text\">ERRORLOG entry showing Query Store setting change<\/figcaption><\/figure>\n<h2><\/h2>\n<p>Finally, a quick peek of the Query Store pane in SSMS confirms the settings:<\/p>\n<figure id=\"attachment_1091\" aria-describedby=\"caption-attachment-1091\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSSettings1.jpg\"><img decoding=\"async\" class=\"size-large wp-image-1091\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSSettings1-1024x872.jpg\" alt=\"Query Store Settings\" width=\"1024\" height=\"872\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSSettings1-1024x872.jpg 1024w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSSettings1-300x255.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSSettings1-768x654.jpg 768w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSSettings1.jpg 1177w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-1091\" class=\"wp-caption-text\">Query Store Settings<\/figcaption><\/figure>\n<p>Another quick note: <em>these are not the values I would recommend for a production system<\/em>.\u00a0 For more information on settings, check out my <a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/query-store-settings\/\">Query Store Settings<\/a> post.<\/p>\n<h2>System Changes<\/h2>\n<p>Now we will explore what gets logged when the OPERATION_MODE setting changes from READ_WRITE to READ_ONLY.\u00a0 We will introduce this by running a very ad hoc workload that generates thousands of queries with different literal values.\u00a0 The code exists in the post, <a href=\"https:\/\/sqlperformance.com\/2019\/05\/sql-plan\/perf-impact-adhoc-workload\">Examining the Performance Impact of an Ad Hoc Workload<\/a>, and we will run usp_RandomSelects from multiple threads with the Extended Events session still running.<\/p>\n<p>Within a few minutes, the following events show up in the Live Data View:<\/p>\n<figure id=\"attachment_1093\" aria-describedby=\"caption-attachment-1093\" style=\"width: 998px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSsettings4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1093\" src=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSsettings4.jpg\" alt=\"Extended Events output after MAX_STORAGE_SIZE is exceeded\" width=\"998\" height=\"123\" srcset=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSsettings4.jpg 998w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSsettings4-300x37.jpg 300w, https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QSsettings4-768x95.jpg 768w\" sizes=\"(max-width: 998px) 100vw, 998px\" \/><\/a><figcaption id=\"caption-attachment-1093\" class=\"wp-caption-text\">Extended Events output after MAX_STORAGE_SIZE is exceeded<\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p>If we check the ERRORLOG, there are <strong>no<\/strong> new entries related to Query Store settings.<\/p>\n<h2>Summary<\/h2>\n<p>As you can see, changes to Query Store are logged differently, depending on the type of change.\u00a0 Any Query Store option that is changed by a user using the ALTER DATABASE command is captured in the ERRORLOG.\u00a0 The query_store_db_settings_changed event also fires. When the OPERATION_MODE is changed by the system, because the storage allocated to Query Store is exceeded, the change is not captured in the ERRORLOG, but it is captured with the query_store_disk_size_over_limit event. In addition, the query_store_disk_size_info event, which fires on a regular basis, will also report the max and current size values. If you want to know when Query Store changes to a READ_ONLY state, you will need to set up an Extended Events session to capture it. To be more proactive, I recommend setting up an Agent job that runs on a regular basis to <a href=\"https:\/\/www.sqlskills.com\/blogs\/erin\/monitoring-space-used-by-query-store\/\">monitor the space used<\/a>, and sends an email if it exceeds a certain percentage.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Query Store feature is a bit unique in that its status can change without user interference, which means it is important to understand how changes to Query Store are logged.\u00a0 A couple weeks ago John Deardurff posted a question on Twitter asking specifically whether the SQL Server ERRORLOG is written to when the OPERATION_MODE [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42,46],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Are Changes to Query Store Logged? - Erin Stellato<\/title>\n<meta name=\"description\" content=\"Changes to Query Store are logged differently, depending whether they are user or system initiated, and you&#039;ll want to know what to check to monitor changes\" \/>\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\/are-changes-to-query-store-logged\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Are Changes to Query Store Logged? - Erin Stellato\" \/>\n<meta property=\"og:description\" content=\"Changes to Query Store are logged differently, depending whether they are user or system initiated, and you&#039;ll want to know what to check to monitor changes\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/\" \/>\n<meta property=\"og:site_name\" content=\"Erin Stellato\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-04T14:30:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-04T16:49:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0.jpg\" \/>\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=\"3 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\/are-changes-to-query-store-logged\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/\",\"name\":\"Are Changes to Query Store Logged? - Erin Stellato\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#website\"},\"datePublished\":\"2020-02-04T14:30:58+00:00\",\"dateModified\":\"2020-02-04T16:49:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158\"},\"description\":\"Changes to Query Store are logged differently, depending whether they are user or system initiated, and you'll want to know what to check to monitor changes\",\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/erin\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Are Changes to Query Store Logged?\"}]},{\"@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":"Are Changes to Query Store Logged? - Erin Stellato","description":"Changes to Query Store are logged differently, depending whether they are user or system initiated, and you'll want to know what to check to monitor changes","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\/are-changes-to-query-store-logged\/","og_locale":"en_US","og_type":"article","og_title":"Are Changes to Query Store Logged? - Erin Stellato","og_description":"Changes to Query Store are logged differently, depending whether they are user or system initiated, and you'll want to know what to check to monitor changes","og_url":"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/","og_site_name":"Erin Stellato","article_published_time":"2020-02-04T14:30:58+00:00","article_modified_time":"2020-02-04T16:49:12+00:00","og_image":[{"url":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-content\/uploads\/2020\/02\/QS_settings_0.jpg"}],"author":"Erin Stellato","twitter_misc":{"Written by":"Erin Stellato","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/","url":"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/","name":"Are Changes to Query Store Logged? - Erin Stellato","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#website"},"datePublished":"2020-02-04T14:30:58+00:00","dateModified":"2020-02-04T16:49:12+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/#\/schema\/person\/76170223ffffa1df03fd9be5b66cb158"},"description":"Changes to Query Store are logged differently, depending whether they are user or system initiated, and you'll want to know what to check to monitor changes","breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/erin\/are-changes-to-query-store-logged\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/erin\/"},{"@type":"ListItem","position":2,"name":"Are Changes to Query Store Logged?"}]},{"@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\/1089"}],"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=1089"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/posts\/1089\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/media?parent=1089"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/categories?post=1089"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/erin\/wp-json\/wp\/v2\/tags?post=1089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}