Warning: Constant WP_TEMP_DIR already defined in /var/www/html/blogs/glenn/wp-config.php on line 94

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902

Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/blogs/glenn/wp-config.php:94) in /var/www/html/blogs/glenn/wp-includes/rest-api/class-wp-rest-server.php on line 1902
{"id":1047,"date":"2016-01-19T17:06:37","date_gmt":"2016-01-20T01:06:37","guid":{"rendered":"http:\/\/3.209.169.194\/blogs\/glenn\/?p=1047"},"modified":"2017-04-13T12:28:50","modified_gmt":"2017-04-13T19:28:50","slug":"sql-server-diagnostic-information-queries-detailed-day-19","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/","title":{"rendered":"SQL Server Diagnostic Information Queries Detailed, Day 19"},"content":{"rendered":"

After eighteen days of queries, we have made it through all of the instance-level queries in this set. Now, we move on to the database-specific queries in the set. For these queries, you need to be connected to a particular database that you are concerned with, rather than the master system database.<\/p>\n

For Day 19 of this series, we start out with Query #44<\/strong>, which is File Sizes and Space. This query retrieves information from the sys.database_files<\/a> system catalog view and the sys.data_spaces<\/a> system catalog view about The sizes and available space for all of your database files. Query #44 is shown in Figure 1.<\/p>\n

\n
\n
   1:<\/span> -- Individual File Sizes and space available for current database  (Query 44) (File Sizes and Space)<\/span><\/pre>\n

<\/p>\n

   2:<\/span> SELECT<\/span> f.name AS<\/span> [File<\/span> Name] , f.physical_name AS<\/span> [Physical Name], <\/pre>\n

<\/p>\n

   3:<\/span> CAST<\/span>((f.size<\/span>\/128.0) AS<\/span> DECIMAL<\/span>(15,2)) AS<\/span> [Total Size<\/span> in<\/span> MB],<\/pre>\n

<\/p>\n

   4:<\/span> CAST<\/span>(f.size<\/span>\/128.0 - CAST<\/span>(FILEPROPERTY(f.name, 'SpaceUsed'<\/span>) AS<\/span> int<\/span>)\/128.0 AS<\/span> DECIMAL<\/span>(15,2)) <\/pre>\n

<\/p>\n

   5:<\/span> AS<\/span> [Available Space<\/span> In<\/span> MB], [file_id], fg.name AS<\/span> [Filegroup Name],<\/pre>\n

<\/p>\n

   6:<\/span> f.is_percent_growth, f.growth<\/pre>\n

<\/p>\n

   7:<\/span> FROM<\/span> sys.database_files AS<\/span> f WITH<\/span> (NOLOCK) <\/pre>\n

<\/p>\n

   8:<\/span> LEFT<\/span> OUTER<\/span> JOIN<\/span> sys.data_spaces AS<\/span> fg WITH<\/span> (NOLOCK) <\/pre>\n

<\/p>\n

   9:<\/span> ON<\/span> f.data_space_id = fg.data_space_id OPTION<\/span> (RECOMPILE);<\/pre>\n

<\/p>\n

  10:<\/span>  <\/pre>\n

<\/p>\n

  11:<\/span> -- Look at how large and how full the files are and where they are located<\/span><\/pre>\n

<\/p>\n

  12:<\/span> -- Make sure the transaction<\/span> log is<\/span> not<\/span> full<\/span>!!<\/pre>\n

<\/div>\n<\/div>\n

Figure 1: Query #44 File Sizes and Space<\/strong><\/p>\n

This query lets you see how large each of your database files are, plus how much space is available in each of your database files. For data files, you can also see what file group each file is in. You can also see exactly where each file is located in the file system. This is all extremely useful information.<\/p>\n

 <\/p>\n

Query #45<\/strong> is IO Stats By File. This query retrieves information from the sys.dm_io_virtual_file_stats<\/a> dynamic management function and the sys.database_files<\/a> system catalog view about the cumulative I\/O usage by database file. Query #45 is shown in Figure 2.<\/p>\n

\n
\n
   1:<\/span> -- I\/O Statistics by file for the current database  (Query 45) (IO Stats By File)<\/span><\/pre>\n

<\/p>\n

   2:<\/span> SELECT<\/span> DB_NAME(DB_ID()) AS<\/span> [Database<\/span> Name], df.name AS<\/span> [Logical Name], vfs.[file_id], df.type_desc,<\/pre>\n

<\/p>\n

   3:<\/span> df.physical_name AS<\/span> [Physical Name], CAST<\/span>(vfs.size_on_disk_bytes\/1048576.0 AS<\/span> DECIMAL<\/span>(10, 2)) AS<\/span> [Size<\/span> on<\/span> Disk<\/span> (MB)],<\/pre>\n

<\/p>\n

   4:<\/span> vfs.num_of_reads, vfs.num_of_writes, vfs.io_stall_read_ms, vfs.io_stall_write_ms,<\/pre>\n

<\/p>\n

   5:<\/span> CAST<\/span>(100. * vfs.io_stall_read_ms\/(vfs.io_stall_read_ms + vfs.io_stall_write_ms) AS<\/span> DECIMAL<\/span>(10,1)) AS<\/span> [IO Stall Reads<\/span> Pct],<\/pre>\n

<\/p>\n

   6:<\/span> CAST<\/span>(100. * vfs.io_stall_write_ms\/(vfs.io_stall_write_ms + vfs.io_stall_read_ms) AS<\/span> DECIMAL<\/span>(10,1)) AS<\/span> [IO Stall Writes Pct],<\/pre>\n

<\/p>\n

   7:<\/span> (vfs.num_of_reads + vfs.num_of_writes) AS<\/span> [Writes + Reads<\/span>], <\/pre>\n

<\/p>\n

   8:<\/span> CAST<\/span>(vfs.num_of_bytes_read\/1048576.0 AS<\/span> DECIMAL<\/span>(10, 2)) AS<\/span> [MB Read<\/span>], <\/pre>\n

<\/p>\n

   9:<\/span> CAST<\/span>(vfs.num_of_bytes_written\/1048576.0 AS<\/span> DECIMAL<\/span>(10, 2)) AS<\/span> [MB Written],<\/pre>\n

<\/p>\n

  10:<\/span> CAST<\/span>(100. * vfs.num_of_reads\/(vfs.num_of_reads + vfs.num_of_writes) AS<\/span> DECIMAL<\/span>(10,1)) AS<\/span> [# Reads<\/span> Pct],<\/pre>\n

<\/p>\n

  11:<\/span> CAST<\/span>(100. * vfs.num_of_writes\/(vfs.num_of_reads + vfs.num_of_writes) AS<\/span> DECIMAL<\/span>(10,1)) AS<\/span> [# Write<\/span> Pct],<\/pre>\n

<\/p>\n

  12:<\/span> CAST<\/span>(100. * vfs.num_of_bytes_read\/(vfs.num_of_bytes_read + vfs.num_of_bytes_written) AS<\/span> DECIMAL<\/span>(10,1)) AS<\/span> [Read<\/span> Bytes Pct],<\/pre>\n

<\/p>\n

  13:<\/span> CAST<\/span>(100. * vfs.num_of_bytes_written\/(vfs.num_of_bytes_read + vfs.num_of_bytes_written) AS<\/span> DECIMAL<\/span>(10,1)) AS<\/span> [Written Bytes Pct]<\/pre>\n

<\/p>\n

  14:<\/span> FROM<\/span> sys.dm_io_virtual_file_stats(DB_ID(), NULL<\/span>) AS<\/span> vfs<\/pre>\n

<\/p>\n

  15:<\/span> INNER<\/span> JOIN<\/span> sys.database_files AS<\/span> df WITH<\/span> (NOLOCK)<\/pre>\n

<\/p>\n

  16:<\/span> ON<\/span> vfs.[file_id]= df.[file_id] OPTION<\/span> (RECOMPILE);<\/pre>\n

<\/p>\n

  17:<\/span>  <\/pre>\n

<\/p>\n

  18:<\/span> -- This helps you characterize your workload better from an I\/O perspective for this database<\/span><\/pre>\n

<\/p>\n

  19:<\/span> -- It helps you determine whether you has an OLTP or<\/span> DW\/DSS type of<\/span> workload<\/pre>\n

<\/div>\n<\/div>\n

Figure 2: Query #45 IO Stats By File<\/strong><\/p>\n

This query lets you see all of the cumulative file activity for each of the files in the current database, since SQL Server was last started. This includes your normal workload activity, plus any other activity that touches your data and log files. This would include things like database backups, index maintenance, DBCC CHECKDB activity, and HA-related activity from things like transactional replication, database mirroring, and AlwaysOn AG-related activity.<\/p>\n

Looking at the results of this query helps you understand what kind of I\/O workload activity you are seeing on each of your database files. This helps you do a better job when it comes to designing and configuring your storage subsystem.<\/p>\n","protected":false},"excerpt":{"rendered":"

After eighteen days of queries, we have made it through all of the instance-level queries in this set. Now, we move on to the database-specific queries in the set. For these queries, you need to be connected to a particular database that you are concerned with, rather than the master system database. For Day 19 […]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[273],"tags":[272],"class_list":["post-1047","post","type-post","status-publish","format-standard","hentry","category-dmv-diagnostic-queries-detailed","tag-dmv-diagnostic-queries-detailed"],"yoast_head":"\nSQL Server Diagnostic Information Queries Detailed, Day 19 - Glenn Berry<\/title>\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\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Server Diagnostic Information Queries Detailed, Day 19 - Glenn Berry\" \/>\n<meta property=\"og:description\" content=\"After eighteen days of queries, we have made it through all of the instance-level queries in this set. Now, we move on to the database-specific queries in the set. For these queries, you need to be connected to a particular database that you are concerned with, rather than the master system database. For Day 19 […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/\" \/>\n<meta property=\"og:site_name\" content=\"Glenn Berry\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-20T01:06:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-13T19:28:50+00:00\" \/>\n<meta name=\"author\" content=\"Glenn Berry\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Glenn Berry\" \/>\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\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/\",\"name\":\"SQL Server Diagnostic Information Queries Detailed, Day 19 - Glenn Berry\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/#website\"},\"datePublished\":\"2016-01-20T01:06:37+00:00\",\"dateModified\":\"2017-04-13T19:28:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/#\/schema\/person\/57a8972435106bac7970692fcf5edfa7\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Server Diagnostic Information Queries Detailed, Day 19\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/\",\"name\":\"Glenn Berry\",\"description\":\"Semi-random musings about SQL Server performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/#\/schema\/person\/57a8972435106bac7970692fcf5edfa7\",\"name\":\"Glenn Berry\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/64bdac8830f25f2f8cc780f8a1286c66ff1182218009271e7a953639596f7e25?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/64bdac8830f25f2f8cc780f8a1286c66ff1182218009271e7a953639596f7e25?s=96&d=mm&r=g\",\"caption\":\"Glenn Berry\"},\"sameAs\":[\"https:\/\/www.sqlskills.com\/blogs\/glenn\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/glenn\/author\/glenn\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Server Diagnostic Information Queries Detailed, Day 19 - Glenn Berry","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\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/","og_locale":"en_US","og_type":"article","og_title":"SQL Server Diagnostic Information Queries Detailed, Day 19 - Glenn Berry","og_description":"After eighteen days of queries, we have made it through all of the instance-level queries in this set. Now, we move on to the database-specific queries in the set. For these queries, you need to be connected to a particular database that you are concerned with, rather than the master system database. For Day 19 […]","og_url":"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/","og_site_name":"Glenn Berry","article_published_time":"2016-01-20T01:06:37+00:00","article_modified_time":"2017-04-13T19:28:50+00:00","author":"Glenn Berry","twitter_misc":{"Written by":"Glenn Berry","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/","url":"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/","name":"SQL Server Diagnostic Information Queries Detailed, Day 19 - Glenn Berry","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/#website"},"datePublished":"2016-01-20T01:06:37+00:00","dateModified":"2017-04-13T19:28:50+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/#\/schema\/person\/57a8972435106bac7970692fcf5edfa7"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/sql-server-diagnostic-information-queries-detailed-day-19\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/glenn\/"},{"@type":"ListItem","position":2,"name":"SQL Server Diagnostic Information Queries Detailed, Day 19"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/glenn\/","name":"Glenn Berry","description":"Semi-random musings about SQL Server performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/glenn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/#\/schema\/person\/57a8972435106bac7970692fcf5edfa7","name":"Glenn Berry","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/glenn\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/64bdac8830f25f2f8cc780f8a1286c66ff1182218009271e7a953639596f7e25?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/64bdac8830f25f2f8cc780f8a1286c66ff1182218009271e7a953639596f7e25?s=96&d=mm&r=g","caption":"Glenn Berry"},"sameAs":["https:\/\/www.sqlskills.com\/blogs\/glenn\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/glenn\/author\/glenn\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/posts\/1047","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/comments?post=1047"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/posts\/1047\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/media?parent=1047"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/categories?post=1047"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/glenn\/wp-json\/wp\/v2\/tags?post=1047"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}