Managing Your TempDb

1,394 views

Published on

By Choirul Amri.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,394
On SlideShare
0
From Embeds
0
Number of Embeds
738
Actions
Shares
0
Downloads
22
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Managing Your TempDb

  1. 1. Managing Your Tempdb Choirul Amri Senior Consultant, MCS http://www.choirulamri.org @mchoirul SQL Server User Group Indonesia Jakarta, February 28, 2013
  2. 2. Session Takeaway • What is tempdb, by the way? • What objects are stored • How tempdb works • How to monitor tempdb • Tempdb best practices
  3. 3. Are you familiar with this? • Slow query performance • Runs out of disk space for system database (tempdb)
  4. 4. What is tempdb? • System database  • Used to store temporary data in SQL Server • What’s in it: – User objects – Internal objects – Version store Tempdb is often overlooked performance bottleneck
  5. 5. What objects are stored? • User objects – Your #temp table and table variable – Internal Objects • Internal Objects – Work files and work tables such as cursor, GROUP BY, and sorting operation – Maintenance operation such as index rebuild and DBCC CHECKDB • Version Stores – Snapshot isolation or read-committed snapshot isolation – Online index rebuild • Complete list: – http://technet.microsoft.com/en- US/library/ms345368(v=SQL.90).aspx – http://technet.microsoft.com/en-us/library/cc966545.aspx DBA has limited control over tempdb size, developer has!
  6. 6. How tempdb works • It’s cleared every time the server restarted • Default: 8MB with 10% autogrowth • 1 SQL instance = 1 tempdb • Simple recovery model • It can be multiple files (MDF) • Balancing between MDF: SQL Sever will choose the biggest file or the one with more free space • May not be backed-up, restored, attached, detached
  7. 7. Monitoring tempdb • Allocation bottleneck – Balancing between files • IO bottleneck – Disk contention problem • Space utilization – Internal, user object, version store
  8. 8. Allocation bottleneck • Check for PAGELATCH and PAGEIOLACTH wait • Check for this type of page: – PFS: 1 – GAM: 2 – SGAM: 3
  9. 9. Checking allocation bottleneck demo
  10. 10. IO Bottleneck • Use DMV query to get top expensive IO • Check perfmon to see if tempdb disks are bottleneck • check sys.dm_io_virtual_file_stats and sys.dm_io_pending_io_requests
  11. 11. Checking IO bottleneck demo
  12. 12. Tempdb capacity planning • There is no exact formula to forecast tempdb • Monitor tempdb size regularly to forecast the trend, and use it as baseline
  13. 13. Tempdb capacity planning • There is no exact formula to forecast tempdb • Monitor tempdb size regularly to forecast the trend, and use it as baseline • Create SQL job to monitor tempdb size at peak time and non peak time • Put the size in production, and monitor it! • Example: • Starting point: 10% of your biggest database size • Revise the size regularly
  14. 14. Monitoring tempdb size Checking query with tempdb usage demo
  15. 15. Tempdb tuning • Pre-size the tempdb files, don’t relay on auto growth • Split to MDF several files – Starting point: ¼ of CPU cores – Increase the number by 2 o 4, until allocation bottleneck disappear • All data files should be at the same size • You need to restart SQL Server after adding new data file • Put tempdb on faster disk • Adding more RAM 
  16. 16. Random tempdb myth • Tempdb files has to be = #CPU cores – Not really, you may lead to allocation bottleneck! • You can shrink tempdb to improve performance – Don’t do it if you have enough space – Tempdb will grow again, you got IO and allocation problem! • Placing tempdb files to different disk will improve performance – Only apply to IO issues, it does not solve allocation bottleneck
  17. 17. More reference • Sunil Agawal blog (MSFT) – http://blogs.msdn.com/b/sqlserverstorageengin e/archive/tags/tempdb/ • Working with tempdb in SQL Server 2005 – http://technet.microsoft.com/en- us/library/cc966545.aspx • Optimizing tempdb Perfomance – http://technet.microsoft.com/en- US/library/ms175527(v=sql.90).aspx
  18. 18. Thank You  • Discussion… • Download PPT and Code from my blog: – http://www.choirulamri.org – Twitter: mchoirul

×