Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to spread tempdb over multiple files?

Tags:

This blog http://blogs.msdn.com/sqlserverstorageengine/archive/2009/01/04/managing-tempdb-in-sql-server-tempdb-configuration.aspx states that it is a good idea to "Spread TempDB across at least as many equal sized files as there are COREs or CPUs."

So my basic question is how do i actually configure my SQL server to do that. So I right click the tempdb, choose properties, files and then add a file for each CPU? How does it know that it should spread the tempdb across these files? is there a flag I should set?

Have I misunderstood the article?

like image 280
Jimmymcnulty Avatar asked Apr 05 '09 23:04

Jimmymcnulty


People also ask

Why should you have multiple files for tempdb?

Microsoft recommends that you create multiple files to reduce contention issues within the TempDB. It is recommended that you create one file per CPU core- a server with (2) 4 core processors would need 8 data files. There is no need to create multiple Log files, one is sufficient.

How many tempdb files should you have?

According to Microsoft Support, the best approach is to create one tempdb data file per logical processor up to 8 data files. If your system has more than 8 logical processors, start with 8 data files and monitor your server's workload to determine if more data files would be beneficial.

How do I reduce the number of tempdb files?

All tempdb files are re-created during startup. However, they are empty and can be removed. To remove additional files in tempdb, use the ALTER DATABASE command by using the REMOVE FILE option. Use the DBCC SHRINKDATABASE command to shrink the tempdb database.


1 Answers

This tip is best as long as you can spread the additional TempDB files across different hard disks. Otherwise, the different threads which create different temp tables will be in contention for the same physical disk.

You can indeed do exactly what you say to do and the work will be automatically spread across the TempDB data files. This can also be scripted as such:

ALTER DATABASE tempdb ADD FILE (NAME = tempdev2, FILENAME = 'W:\tempdb2.mdf', SIZE = 256); ALTER DATABASE tempdb ADD FILE (NAME = tempdev3, FILENAME = 'X:\tempdb3.mdf', SIZE = 256); ALTER DATABASE tempdb ADD FILE (NAME = tempdev4, FILENAME = 'Y:\tempdb4.mdf', SIZE = 256); GO 

to get you three additional files (i.e. 4 CPU cores and 4 physical disks).

like image 137
Jesse C. Slicer Avatar answered Nov 03 '22 02:11

Jesse C. Slicer