{"id":2951,"date":"2014-08-04T19:06:11","date_gmt":"2014-08-04T19:06:11","guid":{"rendered":"http:\/\/www.tsls.co.uk\/?p=2951"},"modified":"2024-04-22T08:58:11","modified_gmt":"2024-04-22T08:58:11","slug":"how-to-split-temp-db","status":"publish","type":"post","link":"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/","title":{"rendered":"How to split temp DB"},"content":{"rendered":"<p>To improve your SQL Server performance or relive TempDB page (wirte) blocking consider splitting\u00a0the TempDB Data file into the amount of logical processors in the server.<\/p>\n<p>As a <b>general<\/b>\u00a0rule, if the number of logical processors is less than or equal to 8, use the same number of data files as logical processors. If the number of logical processors is greater than 8, use 8 data files and then if contention continues, increase the number of data files by multiples of 4 (up to the number of logical processors) until the contention is reduced to acceptable levels or make changes to the workload\/code.<\/p>\n<p>http:\/\/support.microsoft.com\/kb\/2154845<\/p>\n<p>Use the following script to split out TempDB<\/p>\n<p><!--more--><\/p>\n<p><code><br \/>\nUSE master<br \/>\nGO<br \/>\nCREATE TABLE #numprocs<br \/>\n(<br \/>\n[Index] INT,<br \/>\n[Name] VARCHAR(200),<br \/>\nInternal_Value VARCHAR(50),<br \/>\nCharacter_Value VARCHAR(200)<br \/>\n)<br \/>\nDECLARE @BASEPATH VARCHAR(200)<br \/>\nDECLARE @PATH VARCHAR(200)<br \/>\nDECLARE @SQL_SCRIPT VARCHAR(500)<br \/>\nDECLARE @CORES INT<br \/>\nDECLARE @FILECOUNT INT<br \/>\nDECLARE @SIZE INT<br \/>\nDECLARE @GROWTH INT<br \/>\nDECLARE @ISPERCENT INT<br \/>\nINSERT INTO #numprocs<br \/>\nEXEC xp_msver<br \/>\nSELECT @CORES = Internal_Value FROM #numprocs WHERE [Index] = 16<br \/>\nPRINT @CORES<br \/>\nSET @BASEPATH = (select SUBSTRING(physical_name, 1, CHARINDEX(N'tempdb.mdf', LOWER(physical_name)) - 1) DataFileLocation<br \/>\nFROM master.sys.master_files<br \/>\nWHERE database_id = 2 and FILE_ID = 1)<br \/>\nPRINT @BASEPATH<br \/>\nSET @FILECOUNT = (SELECT COUNT(*)<br \/>\nFROM master.sys.master_files<br \/>\nWHERE database_id = 2 AND TYPE_DESC = 'ROWS')<br \/>\nSELECT @SIZE = size FROM master.sys.master_files WHERE database_id = 2 AND FILE_ID = 1<br \/>\nSET @SIZE = @SIZE \/ 128<br \/>\nSELECT @GROWTH = growth FROM master.sys.master_files WHERE database_id = 2 AND FILE_ID = 1<br \/>\nSELECT @ISPERCENT = is_percent_growth FROM master.sys.master_files WHERE database_id = 2 AND FILE_ID = 1<br \/>\nWHILE @CORES &gt; @FILECOUNT<br \/>\nBEGIN<br \/>\nSET @SQL_SCRIPT = 'ALTER DATABASE tempdb<br \/>\nADD FILE<br \/>\n(<br \/>\nFILENAME = ''' + @BASEPATH + 'tempdb' + RTRIM(CAST(@CORES as CHAR)) + '.ndf'',<br \/>\nNAME = tempdev' + RTRIM(CAST(@CORES as CHAR)) + ',<br \/>\nSIZE = ' + RTRIM(CAST(@SIZE as CHAR)) + 'MB,<br \/>\nFILEGROWTH = ' + RTRIM(CAST(@GROWTH as CHAR))<br \/>\nIF @ISPERCENT &gt; 0<br \/>\nSET @SQL_SCRIPT = @SQL_SCRIPT + '%'<br \/>\nSET @SQL_SCRIPT = @SQL_SCRIPT + ')'<br \/>\nEXEC(@SQL_SCRIPT)<br \/>\nSET @CORES = @CORES - 1<br \/>\nEND<br \/>\nGO<br \/>\nDROP TABLE #numprocs<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>To improve your SQL Server performance or relive TempDB page (wirte) blocking consider splitting\u00a0the TempDB Data file into the amount of logical processors in the server. As a general\u00a0rule, if the number of logical processors<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[21],"tags":[2081],"class_list":["post-2951","post","type-post","status-publish","format-standard","hentry","category-microsoft","tag-sql"],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\r\n<title>How to split temp DB - TSLS - Luke Smith<\/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:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/\" \/>\r\n<meta property=\"og:locale\" content=\"en_GB\" \/>\r\n<meta property=\"og:type\" content=\"article\" \/>\r\n<meta property=\"og:title\" content=\"How to split temp DB - TSLS - Luke Smith\" \/>\r\n<meta property=\"og:description\" content=\"To improve your SQL Server performance or relive TempDB page (wirte) blocking consider splitting\u00a0the TempDB Data file into the amount of logical processors in the server. As a general\u00a0rule, if the number of logical processors\" \/>\r\n<meta property=\"og:url\" content=\"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/\" \/>\r\n<meta property=\"og:site_name\" content=\"TSLS - Luke Smith\" \/>\r\n<meta property=\"article:published_time\" content=\"2014-08-04T19:06:11+00:00\" \/>\r\n<meta property=\"article:modified_time\" content=\"2024-04-22T08:58:11+00:00\" \/>\r\n<meta name=\"author\" content=\"Luke Smith\" \/>\r\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Luke Smith\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\r\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/\",\"url\":\"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/\",\"name\":\"How to split temp DB - TSLS - Luke Smith\",\"isPartOf\":{\"@id\":\"https:\/\/www.tsls.co.uk\/#website\"},\"datePublished\":\"2014-08-04T19:06:11+00:00\",\"dateModified\":\"2024-04-22T08:58:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.tsls.co.uk\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to split temp DB\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tsls.co.uk\/#website\",\"url\":\"https:\/\/www.tsls.co.uk\/\",\"name\":\"TSLS - Luke Smith\",\"description\":\"- Knowledge - Thoughts - Microsoft -\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tsls.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7\",\"name\":\"Luke Smith\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/www.tsls.co.uk\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g\",\"caption\":\"Luke Smith\"},\"description\":\"I\u2019ve been working with Microsoft Technologies for over 20 years, my main focus now being Microsoft Online Services. I manage the Cloud Services at ElysianIT Limited and as a P-SELLER at Microsoft. I have worked with many organisations from SMC to Enterprise. I\u2019ve been working with Microsoft Technologies since DOS 5.0, to date I have been working on Microsoft\u2019s latest cloud technology Windows Azure, Windows 10 Office 365 and Microsoft SharePoint\",\"sameAs\":[\"http:\/\/www.tsls.co.uk\"],\"url\":\"https:\/\/www.tsls.co.uk\/index.php\/author\/luke\/\"}]}<\/script>\r\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to split temp DB - TSLS - Luke Smith","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.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/","og_locale":"en_GB","og_type":"article","og_title":"How to split temp DB - TSLS - Luke Smith","og_description":"To improve your SQL Server performance or relive TempDB page (wirte) blocking consider splitting\u00a0the TempDB Data file into the amount of logical processors in the server. As a general\u00a0rule, if the number of logical processors","og_url":"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/","og_site_name":"TSLS - Luke Smith","article_published_time":"2014-08-04T19:06:11+00:00","article_modified_time":"2024-04-22T08:58:11+00:00","author":"Luke Smith","twitter_misc":{"Written by":"Luke Smith","Estimated reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/","url":"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/","name":"How to split temp DB - TSLS - Luke Smith","isPartOf":{"@id":"https:\/\/www.tsls.co.uk\/#website"},"datePublished":"2014-08-04T19:06:11+00:00","dateModified":"2024-04-22T08:58:11+00:00","author":{"@id":"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7"},"breadcrumb":{"@id":"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.tsls.co.uk\/index.php\/2014\/08\/04\/how-to-split-temp-db\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.tsls.co.uk\/"},{"@type":"ListItem","position":2,"name":"How to split temp DB"}]},{"@type":"WebSite","@id":"https:\/\/www.tsls.co.uk\/#website","url":"https:\/\/www.tsls.co.uk\/","name":"TSLS - Luke Smith","description":"- Knowledge - Thoughts - Microsoft -","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tsls.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.tsls.co.uk\/#\/schema\/person\/e4d7dac4fe1b3f8df31f3857bb3ebda7","name":"Luke Smith","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/www.tsls.co.uk\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/29abc50f07a4ebe68cb4f31981884f89b2157d7e4ed63b09631d40c0717faa94?s=96&d=mm&r=g","caption":"Luke Smith"},"description":"I\u2019ve been working with Microsoft Technologies for over 20 years, my main focus now being Microsoft Online Services. I manage the Cloud Services at ElysianIT Limited and as a P-SELLER at Microsoft. I have worked with many organisations from SMC to Enterprise. I\u2019ve been working with Microsoft Technologies since DOS 5.0, to date I have been working on Microsoft\u2019s latest cloud technology Windows Azure, Windows 10 Office 365 and Microsoft SharePoint","sameAs":["http:\/\/www.tsls.co.uk"],"url":"https:\/\/www.tsls.co.uk\/index.php\/author\/luke\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2gf1k-LB","_links":{"self":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/2951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=2951"}],"version-history":[{"count":3,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/2951\/revisions"}],"predecessor-version":[{"id":2981,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/2951\/revisions\/2981"}],"wp:attachment":[{"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=2951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=2951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tsls.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=2951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}