Skip to main content

TempDB – Relocate the TempDB Database Files

I took control of a new server recently and noticed that Tempdb was not configured to best practice. It was not on its own drive and it consisted of one data file and one log file…The server had a couple of cores, I’m not sure how relevant this is anymore but SQL server 2000 it was recommended you create a TEMPDB data file for CPU…I’m not sure that you need a file for each CPU/core in later versions but as Brad McGehee says in his TEMPDB optimisation chapter in MVP deep dives (This is my review of the book) it does give you a place to start.

My first script here moves both the current log and data file to its new home.

USE master;
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = tempdev, FILENAME = 'S:\SQLTEMP\tempdb.mdf');
GO
ALTER DATABASE tempdb
MODIFY FILE (NAME = templog, FILENAME = 'S:\SQLTEMP\templog.ldf');
GO


Once you have run this you will need to restart SQL Server for the changes to take affect. Also you will have two copies of the old TEMPDB files in the in the old location, I like to delete these after the restart  to avoid confusion later.



The next script below adds an additional data file to my tempdb database, this ensures the number of data files in tempdb matches the number of cores on my machine. The reason for multi-data files is a reduction in contention on each file as IO requests are spread across the multiple files. This can be beneficial, even if the files reside on the same volume as is the case here, if you put each file on a volume of their own the performance gain is even greater…With a greater cost attached of course.



Anyhow, the following script adds an additional data file to the tempdb database. Its important to keep the size of each data file identical preferably sized according to TEMPDB usage. Also ensure that the same auto grow settings are set for each file. The algorithm SQL Server uses for filling pages will distribute the load equally if the files are the same size.



 
USE [master]
GO
ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'tempdev', SIZE = 153600KB )
GO
ALTER DATABASE [tempdb] ADD FILE ( NAME = N'TempDev2', FILENAME = N'S:\SQLTEMP\TempDev2.ndf' , SIZE = 153600KB , FILEGROWTH = 10%)
GO
ALTER DATABASE [tempdb] MODIFY FILE ( NAME = N'templog', SIZE = 51200KB )
GO



As with all things please take the time to test the optimal configuration in your environment, as multiple files may or may not benefit you.

Comments

Popular posts from this blog

SQL Server 2012 and Virtual Service Accounts

This post is written by David Postlethwaite
If you are using SQL Server 2012 you will probably have noticed that the default account for the SQL services has changed from that used in previous versions. With SQL 2005 and 2008 the default account for SQL service and SQL Agent service was “NT Authority\System”. This is one the built in accounts on a Windows machine, managed by the machine and selectable from a dedicated dropdown list

The Network Service account was introduced in Windows 2003 as an alternative to using the LocalSystem account, which has full local system privileges on the local machine, a major security concern.
The Network Service has limited local privileges easing these security concerns but when many services on a machine use the Network Service account it becomes harder to track which service is actually accessing resources and performing actions, because all the services are using the one Network Service account.
Also, this account, by default, has sysadmin per…

Always Encrypted

By David Postlethwaite

Always Encrypted is new features in SQL Server 2016 and it is also available in Azure SQL Database. Here you can encrypt columns in a table with a master key and a certificate so that they will appear as encrypted strings to those who don’t have the required certificate installed on their pc.
Once the certificate is installed on the computer then the unencrypted data can then be seen as normal.

The data passes from database to your application as the encrypted value, only the application with the correct certificate can unencrypt the data so it is secure across the wire. This will go some way to resolving the concern of people worried about putting their sensitive data on a shared server in the cloud such as Microsoft Azure and accessing the data across the Internet.

At the time of writing Always Encrypted is only supported with ADO.NET 4.6, JDBC 6.0 and ODBC 13.1 but expect other driver to become available.

The calling application (including SSMS) must also hav…

New in SQL Server 2017: Graph Databases

David has recorded and published a video of his presentation on SQL Server Graph Database. In his video which you can watch below, David provides an excellent introduction into SQL Server 2017 Graph Databases. In his presentation he looks at Tennis results at tournaments for  his favourite player "The Fed"  Rodger Federer.

David  shows how to set up graph database and work with them in SQL Server 2017.

Graph Database is not new. Other vendors have had graph database capabilities for some time so Microsoft are quite late to the market. In David presentation it appears that Microsoft have done a reasonable job of implementing some of the graph database features but he does point some of the limitations of the Microsoft product too and suggests that it is not ready for production yet but Microsoft seem serious about this feature.

Please watch the video and feel free to leave a comment or feedback - David is delivering a version of this talk on Graph databases in SQL Saturday Ka…