Article ID: 2154845 - Last Review: April 2, 2012 - Revision: 6.0

Recommendations to reduce allocation contention in SQL Server tempdb database

System TipThis article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
Expand all | Collapse all

SYMPTOMS

You observe severe blocking when the SQL Server is experiencing heavy load. When you examine the Dynamic Management Views [sys.dm_exec_request or sys.dm_os_waiting_tasks], you observe that these requests or tasks are waiting for tempdb resources. You will notice that the wait type and wait resource point to LATCH waits on pages in tempdb. These pages might be of the format 2:1:1, 2:1:3, etc.

CAUSE

When the tempdb database is heavily used, SQL Server may experience contention when it tries to allocate pages. Depending on the degree of contention, this may cause queries and requests that involve tempdb to be unresponsive for short periods of time.

RESOLUTION

There are several steps you can take to improve the concurrency of tempdb:

Increase the number of data files in tempdb to maximize disk bandwidth and to reduce contention in allocation structures. As a general guideline, create one data file per CPU or core. Each file should be set to the same size. This enables the proportional fill algorithm to distribute the allocation load uniformly with minimal contention.

Consider implementing the best practice recommendations in the Technet article titled Working with tempdb in SQL Server 2005 (http://technet.microsoft.com/en-us/library/cc966545.aspx) .

If the previous steps do not significantly reduce the allocation contention and the contention is on SGAM pages, implement trace flag -T1118. Under this trace flag, SQL Server allocates full extents to each database object, thereby eliminating the contention on SGAM pages. Note that this trace flag affects every database on the instance of SQL Server. For information about how to determine whether the allocation contention is on SGAM pages, see Monitoring contention caused by DML operations subtopic under Working with tempdb in SQL Server 2005 (http://technet.microsoft.com/en-us/library/cc966545.aspx) page on Technet. 

MORE INFORMATION

For more information about the products or tools that automatically check for this condition on your instance of SQL Server and on the versions of the SQL Server product, see the following table:
Collapse this tableExpand this table
Rule software



Rule title



Rule description



Product versions against which the rule is evaluated
SQL Server 2008 R2 Best Practice Analyzer (SQL Server 2008 R2 BPA)












SQL tempdb database not configured optimally













The SQL Server 2008 R2 Best Practice Analyzer (SQL Server 2008 R2 BPA) provides a rule to detect situations where the tempdb database is configured with only one data file and the SQL Server instance is using multiple processors. The SQL Server 2008 R2 BPA supports both SQL Server 2008 and SQL Server 2008 R2. 

If you run the BPA tool and encounter an Error with the title of Engine - SQL tempdb database not configured optimally, and then you need to follow the recommendations from the resolution section of this article. You have to find out how many SQL OS schedulers are currently online and then configure multiple tempdb files that can support the concurrent activity on these schedulers. You can use the following query to find the number of schedulers:

SELECT COUNT(*) AS processor_count

FROM sys.dm_os_schedulers WHERE status = 'VISIBLE ONLINE'
SQL Server 2008
SQL Server 2008 R2













SQL Server 2012 Best Practice Analyzer (SQL Server 2012 BPA)










SQL tempdb database not configured optimally











The SQL Server 2012 Best Practice Analyzer (SQL Server 2012 BPA) provides a rule to detect situations where the tempdb database is configured with only one data file and the SQL Server instance is using multiple processors.

If you run the BPA tool and encounter an Error with the title of Engine - SQL tempdb database not configured optimally, and then you need to follow the recommendations from the resolution section of this article. You have to find out how many SQL OS schedulers are currently online and then configure multiple tempdb files that can support the concurrent activity on these schedulers. You can use the following query to find the number of schedulers:

SELECT COUNT(*) AS processor_count

FROM sys.dm_os_schedulers WHERE status = 'VISIBLE ONLINE'
SQL Server 2012
















APPLIES TO
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 Enterprise Evaluation
  • Microsoft SQL Server 2008 Express
  • Microsoft SQL Server 2008 Express with Advanced Services
  • Microsoft SQL Server 2008 R2 Datacenter
  • Microsoft SQL Server 2008 R2 Developer
  • Microsoft SQL Server 2008 R2 Enterprise
  • Microsoft SQL Server 2008 R2 Express
  • Microsoft SQL Server 2008 R2 Express with Advanced Services
  • Microsoft SQL Server 2008 R2 Standard
  • Microsoft SQL Server 2008 R2 Standard Edition for Small Business
  • Microsoft SQL Server 2008 R2 Web
  • Microsoft SQL Server 2008 R2 Workgroup
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 Standard Edition for Small Business
  • Microsoft SQL Server 2008 Web
  • Microsoft SQL Server 2008 Workgroup
Keywords: 
KB2154845