You can watch the replay for this Geek Sync webcast in the IDERA Resource Center: http://ow.ly/7OmW50A5qNs
Every SQL Server system you work with has a tempdb database. In this Geek Sync, you’ll learn how tempdb is structured, what it’s used for and the common performance problems that are tied to this shared resource.
2. About Me – Vicky Harp
• Product Manager with Idera
• Working with SQL Server
since 2001
• Working at Idera since 2004
• Twitter: @vickyharp
• Email: vicky.harp@idera.com
4. How temporary is it?
• Recreated on server restart
– Reverts to last configured size
– Populated with contents of model database
• Does not run recovery
– Everything in tempdb is, well, temporary!
5. Why monitor tempdb?
Temp tables
Table
variables
Cursors
Worktables
DBCC
CHECKDB
Version Store
Online Index
Rebuilds
After Triggers
7. File Space and Topology
• Defaults
– One 8 MB data file on the C: drive
– One 1 MB log file on the C: drive
– 10% autogrow
8. File Space and Topology
• Best practices
– One 8 MB data file on the C: drive
– One 1 MB log file on the C: drive
– 10% autogrow
9. File Space and Topology
• Best practices
– Multiple pre-sized data files on a non-system
drive
– One pre-sized log file on a non-system drive
– Fixed size autogrow as a last resort
10. What Size Files?
• DBCC CHECKDB with ESTIMATEONLY
• Index size of largest index being rebuilt
• Monitor, monitor, monitor!
11. File Space and Topology
• What to check
– File location
– File count
– Available space
• How often
– Every 5 seconds forever
12. File Space and Topology
• What to check
– File location
– File count
– Available space
• How often
– After server restart
– Up to hourly for space available
19. Mixed and Dedicated Extents
Tab A
Tab A
Tab A
Tab B
Tab B
Tab B
Tab C
Tab C
Tab A
Tab C
Tab B
8 KB
8 KB
8 KB
8 KB
8 KB
8 KB
8 KB
8 KB
64 KB 64 KB
64 KB
20. GAM Intervals
GAM Interval (4 GB)
1 2 63998 63999…
GAM
Page Allocation state of each extent (1-63999)
SGAM
Page Free pages in mixed extents (1-63999)
27. File Configuration
• Multiple tempdb data files
• All files the same size
• Presize files to prevent autogrow
• Log size 2x size of largest file
• Autogrow set to fixed size
28. Number of Files
• Create 1 file for every 2 or 4 logical
CPUs, to a maximum of 8
• Monitor for contention
• If contention exists, add 4 more files
• Repeat until a max of 1 file per
logical CPU
29. Trace Flags and SQL 2016
• TF1117
– Grow all files in a filegroup equally
• TF1118
– Do not use mixed extents
• Default behavior for SQL 2016
30. Contention
• What to check
– Waits on allocation objects in tempdb
• How often
– Continuously while configuring tempdb
– Weekly spot checks thereafter
31. Monitoring Contention
• sys.dm_os_waiting_tasks
• wait_type like 'PAGE%LATCH_%'
• PageID
– PFS – 1 or multiple of 8088
– GAM – 2 or multiple of 511232
– SGAM – 3 or (PageID – 1) is multiple of 511232
36. Version Store
• What to check
– Version store size
– Long running version store transactions
– Version generation and cleanup rate
• How often
– Continuously with snapshot isolation workload
– Otherwise, check with space available check
37. Monitoring Version Store
• sys.dm_db_file_space_usage
– version_store_reserved_page_count
• sys.dm_tran_active_snapshot_database_transactions
• sys.dm_os_performance_counters
– Version Generation rate (KB/s)
– Version Cleanup rate (KB/s)
41. Session Space Usage
• What to check
– Heavy use of tempdb by user sessions
• How often
– Continuously if tuning workload
– Otherwise, daily spot checks
42. Monitor Session Space Used
• tempdb.sys.dm_db_session_space_usage
• tempdb.sys.dm_db_task_space_usage