Your SlideShare is downloading. ×
Managing Your TempDb
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Managing Your TempDb

935
views

Published on

By Choirul Amri.

By Choirul Amri.

Published in: Technology

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
935
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
15
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Managing Your Tempdb Choirul Amri Senior Consultant, MCS http://www.choirulamri.org @mchoirul SQL Server User Group Indonesia Jakarta, February 28, 2013
  • 2. Session Takeaway • What is tempdb, by the way? • What objects are stored • How tempdb works • How to monitor tempdb • Tempdb best practices
  • 3. Are you familiar with this? • Slow query performance • Runs out of disk space for system database (tempdb)
  • 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. 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. 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. Monitoring tempdb • Allocation bottleneck – Balancing between files • IO bottleneck – Disk contention problem • Space utilization – Internal, user object, version store
  • 8. Allocation bottleneck • Check for PAGELATCH and PAGEIOLACTH wait • Check for this type of page: – PFS: 1 – GAM: 2 – SGAM: 3
  • 9. Checking allocation bottleneck demo
  • 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. Checking IO bottleneck demo
  • 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. 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. Monitoring tempdb size Checking query with tempdb usage demo
  • 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. 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. 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. Thank You  • Discussion… • Download PPT and Code from my blog: – http://www.choirulamri.org – Twitter: mchoirul