{"id":6340,"date":"2019-03-08T14:36:16","date_gmt":"2019-03-08T14:36:16","guid":{"rendered":"https:\/\/ittutorial.org\/?p=6340"},"modified":"2019-11-28T07:04:53","modified_gmt":"2019-11-28T07:04:53","slug":"sql-server-database-size-growth-using-backup-history","status":"publish","type":"post","link":"https:\/\/ittutorial.org\/sql-server-database-size-growth-using-backup-history\/","title":{"rendered":"SQL Server Database Size Growth using Backup history"},"content":{"rendered":"<p>Hi,<\/p>\n<p>Managers and customers are asking frequently what is the database size growth.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-6341\" src=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/database-growth.png\" alt=\"\" width=\"625\" height=\"346\" srcset=\"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/database-growth.png 625w, https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/database-growth-300x166.png 300w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/p>\n<p><!--more--><\/p>\n\n<p>&nbsp;<\/p>\n<p>Database size growth grafic is very important for the new storage order. Because Enterprise companies want to purchase new storage in one or two years not every 2-3 month.<\/p>\n<p>&nbsp;<\/p>\n<p>You can\u00a0analyse the database size growth using backup history with following script.<\/p>\n<pre>DECLARE @startDate datetime;\r\nSET @startDate = GetDate();\r\n\r\nSELECT PVT.DatabaseName\r\n, PVT.[0], PVT.[-1], PVT.[-2], PVT.[-3], PVT.[-4], PVT.[-5], PVT.[-6]\r\n, PVT.[-7], PVT.[-8], PVT.[-9], PVT.[-10], PVT.[-11], PVT.[-12]\r\nFROM\r\n(SELECT BS.database_name AS DatabaseName\r\n,DATEDIFF(mm, @startDate, BS.backup_start_date) AS MonthsAgo\r\n,CONVERT(numeric(10, 1), AVG(BF.file_size \/ 1048576.0)) AS AvgSizeMB\r\nFROM msdb.dbo.backupset as BS\r\nINNER JOIN\r\nmsdb.dbo.backupfile AS BF\r\nON BS.backup_set_id = BF.backup_set_id\r\nWHERE NOT BS.database_name IN\r\n('master', 'msdb', 'model', 'tempdb')\r\nAND BF.[file_type] = 'D'\r\nAND BS.backup_start_date BETWEEN DATEADD(yy, -1, @startDate) AND @startDate\r\nGROUP BY BS.database_name\r\n,DATEDIFF(mm, @startDate, BS.backup_start_date)\r\n) AS BCKSTAT\r\nPIVOT (SUM(BCKSTAT.AvgSizeMB)\r\nFOR BCKSTAT.MonthsAgo IN ([0], [-1], [-2], [-3], [-4], [-5], [-6], [-7], [-8], [-9], [-10], [-11], [-12])\r\n) AS PVT\r\nORDER BY PVT.DatabaseName;\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<h4><span style=\"color: #ff0000;\">Do you want to learn Microsoft SQL Server DBA Tutorials for Beginners, then read the following articles.<\/span><\/h4>\n<p><a href=\"https:\/\/ittutorial.org\/sql-server-tutorials-microsoft-database-for-beginners\/\">https:\/\/ittutorial.org\/sql-server-tutorials-microsoft-database-for-beginners\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, Managers and customers are asking frequently what is the database size growth.<\/p>\n","protected":false},"author":1,"featured_media":6341,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3828,2227,3827],"tags":[2347,2348,2344,1028,1031,1600,1610,2231,2228,2345,2346,2343,2230,2229],"class_list":["post-6340","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-sql-scripts","category-sql-server-2","category-sql-server-dba-scripts","tag-database-size-growth-grafic","tag-database-size-growth-script-sql-server","tag-how-to-analyse-the-database-size-growth-using-backup-history","tag-mehmet-deveci","tag-mehmet-salih-deveci","tag-sql-server-2012","tag-sql-server-2014","tag-sql-server-2019","tag-sql-server-collection-inventory-script","tag-sql-server-database-size-growth","tag-sql-server-database-size-growth-grafic","tag-sql-server-database-size-growth-using-backup-history","tag-sql-server-useful-query","tag-sql-server-useful-script"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/ittutorial.org\/wp-content\/uploads\/2019\/03\/database-growth.png","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/comments?post=6340"}],"version-history":[{"count":2,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6340\/revisions"}],"predecessor-version":[{"id":12966,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/posts\/6340\/revisions\/12966"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media\/6341"}],"wp:attachment":[{"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/media?parent=6340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/categories?post=6340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ittutorial.org\/wp-json\/wp\/v2\/tags?post=6340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}