{"id":704,"date":"2014-03-25T13:28:54","date_gmt":"2014-03-25T17:28:54","guid":{"rendered":"http:\/\/binary-world.com\/blogs\/?p=704"},"modified":"2014-03-25T13:28:54","modified_gmt":"2014-03-25T17:28:54","slug":"measure-io-database-files-filegroup-fn_virtualfilestats","status":"publish","type":"post","link":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/","title":{"rendered":"Measure the I\/O load on database files and file group using fn_virtualfilestats"},"content":{"rendered":"<p>Here is the script which can give you SQL Server file IO Statistics for each file and file group. Using this data you can find out <strong>sql server read\/write performance of your disks<\/strong>.<\/p>\n<pre class=\"brush: sql; gutter: true; first-line: 1; highlight: []; html-script: false\">\r\nDECLARE @TotalIO    BIGINT,\r\n    @TotalBytes BIGINT,\r\n    @TotalStall BIGINT\r\n\r\nSELECT @TotalIO  = SUM(NumberReads + NumberWrites),\r\n       @TotalBytes = SUM(BytesRead + BytesWritten),\r\n       @TotalStall = SUM(IoStallMS)\r\nFROM ::FN_VIRTUALFILESTATS(NULL, NULL)\r\n\r\nSELECT [DbName] = DB_NAME([DbId]),\r\n      (SELECT name FROM sys.master_files\r\n        WHERE database_id = [DbId]\r\n              and FILE_ID = [FileId]) filename,\r\n    [%ReadWrites]       = (100 * (NumberReads + NumberWrites) \/ @TotalIO),\r\n    [%Bytes]        = (100 * (BytesRead + BytesWritten) \/ @TotalBytes),\r\n    [%Stall]        = (100 * IoStallMS \/ @TotalStall),\r\n    [NumberReads],\r\n    [NumberWrites],\r\n    [TotalIO]       = CAST((NumberReads + NumberWrites) AS BIGINT),\r\n    [MBsRead]       = [BytesRead] \/ (1024*1024),\r\n    [MBsWritten]        = [BytesWritten] \/ (1024*1024),\r\n    [TotalMBs]      = (BytesRead + BytesWritten) \/ (1024*1024),\r\n    [IoStallMS],\r\n    IoStallReadMS,\r\n    IoStallWriteMS,\r\n    [AvgStallPerIO]     = ([IoStallMS] \/ ([NumberReads] + [NumberWrites] + 1)),\r\n    [AvgStallPerReadIO] = (IoStallReadMS \/ ([NumberReads] + 1)),\r\n    [AvgStallPerWriteIO]= (IoStallWriteMS \/ ( [NumberWrites] + 1)),\r\n\r\n    [AvgBytesPerRead]  = ((BytesRead) \/ (NumberReads + 1)),\r\n    [AvgBytesPerWrite] = ((BytesWritten) \/ (NumberWrites + 1))\r\nFROM ::FN_VIRTUALFILESTATS(NULL, NULL)\r\nORDER BY dbname\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here is the script which can give you SQL Server file IO Statistics for each file and file group. Using this data you can find out sql server read\/write performance of your disks. DECLARE @TotalIO BIGINT, @TotalBytes BIGINT, @TotalStall BIGINT &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/\"> <span class=\"screen-reader-text\">Measure the I\/O load on database files and file group using fn_virtualfilestats<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":606,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[115,158],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>Measure the I\/O load on database files and file group using fn_virtualfilestats  - BinaryWorld Blog<\/title>\r\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_US\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"Measure the I\/O load on database files and file group using fn_virtualfilestats  - BinaryWorld Blog\" \/>\r\n<meta property=\"og:description\" content=\"Here is the script which can give you SQL Server file IO Statistics for each file and file group. Using this data you can find out sql server read\/write performance of your disks. DECLARE @TotalIO BIGINT, @TotalBytes BIGINT, @TotalStall BIGINT &hellip; Measure the I\/O load on database files and file group using fn_virtualfilestats Read More &raquo;\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/\" \/>\r\n<meta property=\"og:site_name\" content=\"BinaryWorld Blog\" \/>\r\n<meta property=\"article:published_time\" content=\"2014-03-25T17:28:54+00:00\" \/>\r\n<meta property=\"og:image\" content=\"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg\" \/>\r\n\t<meta property=\"og:image:width\" content=\"150\" \/>\r\n\t<meta property=\"og:image:height\" content=\"150\" \/>\r\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\r\n<meta name=\"author\" content=\"Binary World\" \/>\r\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Binary World\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/\",\"url\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/\",\"name\":\"Measure the I\/O load on database files and file group using fn_virtualfilestats - BinaryWorld Blog\",\"isPartOf\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg\",\"datePublished\":\"2014-03-25T17:28:54+00:00\",\"dateModified\":\"2014-03-25T17:28:54+00:00\",\"author\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0\"},\"breadcrumb\":{\"@id\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#primaryimage\",\"url\":\"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg\",\"contentUrl\":\"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg\",\"width\":150,\"height\":150,\"caption\":\"T SQL Date format convert function\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/binaryworld.net\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Measure the I\/O load on database files and file group using fn_virtualfilestats\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/#website\",\"url\":\"https:\/\/binaryworld.net\/blogs\/\",\"name\":\"BinaryWorld Blog\",\"description\":\"Tips and Tutorials for Microsoft SQL Server, SSIS, SSAS, Business Intelligence, C#, .net\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/binaryworld.net\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0\",\"name\":\"Binary World\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g\",\"caption\":\"Binary World\"},\"description\":\"Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.\",\"url\":\"https:\/\/binaryworld.net\/blogs\/author\/admin\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Measure the I\/O load on database files and file group using fn_virtualfilestats  - BinaryWorld Blog","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:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/","og_locale":"en_US","og_type":"article","og_title":"Measure the I\/O load on database files and file group using fn_virtualfilestats  - BinaryWorld Blog","og_description":"Here is the script which can give you SQL Server file IO Statistics for each file and file group. Using this data you can find out sql server read\/write performance of your disks. DECLARE @TotalIO BIGINT, @TotalBytes BIGINT, @TotalStall BIGINT &hellip; Measure the I\/O load on database files and file group using fn_virtualfilestats Read More &raquo;","og_url":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/","og_site_name":"BinaryWorld Blog","article_published_time":"2014-03-25T17:28:54+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg","type":"image\/jpeg"}],"author":"Binary World","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Binary World","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/","url":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/","name":"Measure the I\/O load on database files and file group using fn_virtualfilestats - BinaryWorld Blog","isPartOf":{"@id":"https:\/\/binaryworld.net\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#primaryimage"},"image":{"@id":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#primaryimage"},"thumbnailUrl":"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg","datePublished":"2014-03-25T17:28:54+00:00","dateModified":"2014-03-25T17:28:54+00:00","author":{"@id":"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0"},"breadcrumb":{"@id":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#primaryimage","url":"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg","contentUrl":"https:\/\/binaryworld.net\/blogs\/wp-content\/uploads\/2014\/02\/sql-server-logo-e1397590261883.jpg","width":150,"height":150,"caption":"T SQL Date format convert function"},{"@type":"BreadcrumbList","@id":"https:\/\/binaryworld.net\/blogs\/measure-io-database-files-filegroup-fn_virtualfilestats\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/binaryworld.net\/blogs\/"},{"@type":"ListItem","position":2,"name":"Measure the I\/O load on database files and file group using fn_virtualfilestats"}]},{"@type":"WebSite","@id":"https:\/\/binaryworld.net\/blogs\/#website","url":"https:\/\/binaryworld.net\/blogs\/","name":"BinaryWorld Blog","description":"Tips and Tutorials for Microsoft SQL Server, SSIS, SSAS, Business Intelligence, C#, .net","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/binaryworld.net\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/77cf0a9a512dd22bff93c6a1b6374fe0","name":"Binary World","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/binaryworld.net\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eaea47799daa577835eb53e64dfd3e13?s=96&d=mm&r=g","caption":"Binary World"},"description":"Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.","url":"https:\/\/binaryworld.net\/blogs\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/posts\/704"}],"collection":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/comments?post=704"}],"version-history":[{"count":0,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/posts\/704\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/media\/606"}],"wp:attachment":[{"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/media?parent=704"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/categories?post=704"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/binaryworld.net\/blogs\/wp-json\/wp\/v2\/tags?post=704"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}