SQL SERVER TIPS n°5 : TempDB Best practices

In this tip we will talk about some of the best practises for configuring TempDB database and its placement:

The size and physical placement of the tempdb database can affect the performance of a system. For example, if the size that is defined for tempdb is too small, part of the system-processing load may be taken up with autogrowing tempdb to the size required to support the workload every time you restart the instance of SQL Server. You can avoid this overhead by increasing the sizes of the tempdb data and log file.

For information about determining the appropriate amount of disk space required for tempdb, see Capacity Planning for tempdb.

TempDB Size and Placement Recommendations:

To achieve optimal tempdb performance, we recommend the following configuration for tempdb in a production environment:

1) Set the recovery model of tempdb to SIMPLE. (This model automatically reclaims log space to keep space requirements small)

2) Allow TempDB files to automatically grow as required. (This allows the file to grow until the disk is full) *If the production environment cannot tolerate the potential for application time-outs that may occur during autogrow operations, preallocate space to allow for the expected workload.

3) Set the file growth increment to a reasonable size to avoid the tempdb database files from growing by too small a value. If the file growth is too small, compared to the amount of data that is being written to tempdb, tempdb may have to constantly expand. This will affect performance. We recommend the following general guidelines for setting the FILEGROWTH increment for tempdb files.

If TempDB file size > 0 and < 100 MB then the recommended Filegroup increment can be 10 MB

If TempDB file size > 100 and < 200 MB then the recommended filegroup increment can be 20 MB

If TempDB file size >= 200 MB then the recommended filegroup increment can be 10%

Note: You may have to adjust this percentage based on the speed of the I/O subsystem on which the tempdb files are located. To avoid potential latch time-outs, we recommend limiting the autogrow operation to approximately two minutes. For example, if the I/O subsystem can initialize a file at 50 MB per second, the FILEGROWTH increment should be set to a maximum of 6 GB, regardless of the tempdb file size. If possible, use instant database file initialization to improve the performance of autogrow operations.

4) Preallocate space for all tempdb files by setting the file size to a value large enough to accommodate the typical workload in the environment. This prevents tempdb from expanding too frequently, which can affect performance. The tempdb database should be set to autogrow, but this should be used to increase disk space for unplanned exceptions.

5) VERY IMPORTANT: Create as many files as needed to maximize disk bandwidth. Using multiple files reduces tempdb storage contention and yields significantly better scalability. However, do not create too many files because this can reduce performance and increase management overhead. As a general guideline, create one data file for each CPU on the server (accounting for any affinity mask settings) and then adjust the number of files up or down as necessary. Note that a dual-core CPU is considered to be two CPUs.

6) Make each data file the same size; this allows for optimal proportional-fill performance.

7) Put the tempdb database on a fast I/O subsystem. Use disk striping if there are many directly attached disks.

8) Put the tempdb database on disks that differ from those that are used by user databases.

Note: The values for the file size and filegrowth parameters are used whenever tempdb is created. For example, if you increase the size of the tempdb data file to 20 MB and increase the file growth increment to 15 percent, the new values immediately take affect. If subsequent transactional activities cause tempdb to grow in size, the data file will return to the size of 20 MB every time you restart the instance of SQL Server.