One of the focal points in SQL Server Tuning for SharePoint is around the TEMPDB. A lot of performance issues are caused by the performance of the TEMPDB. TEMPDB is one of the four system databases.
TEMPDB is important to SharePoint and I'll try to explain how to detect TEMPDB issues on SQL instances that contain SharePoint DB’s. TEMPDB is one of the important systems DB regarding the health of the SharePoint. In SharePoint almost every action/request is generating work in the TEMPDB.
Recommendation for TEMPDB performance:
There are 2 trace flag [TF] that can help us improve performance around TEMPDB issues.
Note that both trace flags have instance level affect; in other words all databases in SQL Server instance will be affected and not only the tempdb.
-- Script for monitoringTempDBfile growth: SELECT name FileName, size*1.0/128 FileSizeinMB, CASE max_size WHEN 0 THEN'Autogrowth is off.' WHEN-1 THEN'Autogrowth is on.' ELSE'Log file will grow to a maximum size of 2 TB.' END, growth 'GrowthValue','GrowthIncrement'= CASE WHEN growth=0 THEN 'Size is fixed and will not grow.' WHEN growth> 0 AND is_percent_growth= 0 THEN'Growth value is in 8-KB pages.' ELSE'Growth value is a percentage.' END FROM tempdb.sys.database_files; GO -- Script for monitoring TempDB objects size: SELECT SUM(user_object_reserved_page_count)*8 User_Object_In_KB, SUM(internal_object_reserved_page_count)*8 asSys_bj_In_KB, SUM(version_store_reserved_page_count)*8 asVer_Stor_In_KB FROM sys.dm_db_file_space_usage -- Script for monitoring TempDb contention: Select session_id,wait_type,wait_duration_ms,blocking_session_id,resource_description, ResourceType=Case When Cast(Right(resource_description,Len(resource_description)-Charindex(':',resource_description, 3))As Int)- 1 % 8088 = 0 Then'Is PFS Page' When Cast(Right(resource_description,Len(resource_description)-Charindex(':',resource_description, 3))As Int)- 2 % 511232 = 0 Then'Is GAM Page' When Cast(Right(resource_description,Len(resource_description)-Charindex(':',resource_description, 3))As Int)- 3 % 511232 = 0 Then'Is SGAM Page' Else'Is Not PFS, GAM, or SGAM page' End From sys.dm_os_waiting_tasks Where wait_type Like'PAGE%LATCH_%' And resource_description Like'2:%'
-- Script for monitoringTempDBfile growth:
SELECT name FileName, size*1.0/128 FileSizeinMB,
CASE max_size
WHEN 0 THEN'Autogrowth is off.'
WHEN-1 THEN'Autogrowth is on.'
ELSE'Log file will grow to a maximum size of 2 TB.'
END, growth 'GrowthValue','GrowthIncrement'=
CASE
WHEN growth=0 THEN 'Size is fixed and will not grow.'
WHEN growth> 0 AND is_percent_growth= 0 THEN'Growth value is in 8-KB pages.'
ELSE'Growth value is a percentage.'
END
FROM tempdb.sys.database_files;
GO
-- Script for monitoring TempDB objects size:
SELECT SUM(user_object_reserved_page_count)*8 User_Object_In_KB,
SUM(internal_object_reserved_page_count)*8 asSys_bj_In_KB,
SUM(version_store_reserved_page_count)*8 asVer_Stor_In_KB
FROM sys.dm_db_file_space_usage
-- Script for monitoring TempDb contention:
Select session_id,wait_type,wait_duration_ms,blocking_session_id,resource_description,
ResourceType=Case
When Cast(Right(resource_description,Len(resource_description)-Charindex(':',resource_description, 3))As Int)- 1 % 8088 = 0 Then'Is PFS Page'
When Cast(Right(resource_description,Len(resource_description)-Charindex(':',resource_description, 3))As Int)- 2 % 511232 = 0 Then'Is GAM Page'
When Cast(Right(resource_description,Len(resource_description)-Charindex(':',resource_description, 3))As Int)- 3 % 511232 = 0 Then'Is SGAM Page'
Else'Is Not PFS, GAM, or SGAM page'
End
From sys.dm_os_waiting_tasks
Where wait_type Like'PAGE%LATCH_%' And resource_description Like'2:%'