Inside tempdb

452 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
452
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Inside tempdb

  1. 1. ©2011 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice Miroslav Dimitrov Boris Hristov INSIDE TEMPDB (ALMOST LEVEL 500)
  2. 2. 2 Our agenda = answer the WWW questions… 1. Tempdb creation 2. Logging 3. Allocations
  3. 3. Tempdb creation
  4. 4. 4 Right after master, we create tempdb Open model first Create tempdb based on model and properties Notify tempdb is ready If we fail – server goes down!
  5. 5. 5 How? Lock model and tempdb! Copy extents from model to tempdb (including objects) Fixup the tempdb data file Then tlog file Create attach the other files -f option 1 primary data file the size of model (unlimited fixed auto grow) Build one primary log 516096 – 2vlfs + header = 516096 bytes (unlimited 10% autogrowth) DATA Folder Orginal sizes are retained
  6. 6. Demo
  7. 7. 7 How? Lock model and tempdb! Copy extents from model to tempdb (including objects) Fixup the tempdb data file Then tlog file Create attach the other files -f option 1 primary data file the size of model (unlimited fixed auto grow) Build one primary log 516096 – 2vlfs + header = 516096 bytes (unlimited 10% autogrowth) DATA Folder Orginal sizes are retained
  8. 8. 8 Before tempdb is ready – no one will use it
  9. 9. Tempdb log 9 Minimize logging – after images for inserts and updates (only to heaps – temp tables) No need for crash recovery – who cares? Then why a tlog? ONLY FOR ROLLBACK Log is faster than you think (lazy commits – one note) No normal checkpoint of pages – skips tempdb (hard Is supported) truncates the log internal objects – mostly allocation logging
  10. 10. Tempdb logging
  11. 11. Demo
  12. 12. After image logging 12 Table with value of 1
  13. 13. Tempdb allocations
  14. 14. What is there in tempdb exactly? 14 User Objects • Temp tables • Table variables • UDFs • Online index space • … Internal Objects • Sort tables • Worktables • Workfiles • Version Store
  15. 15. Temporary table caching 15 We cache… • Stored procs • Triggers • Functions Why?
  16. 16. Internal objects 16 Internal Objects • Sort tables • Worktables • Workfiles • Version Store
  17. 17. TempDB allocations 17 PFS / GAM / SGAM pages The only place MS do non-logged allocations! What about contention?
  18. 18. How is a table created inside tempdb? 18 Build system catalog enries Why? Why? Allocate IAM – fina a mixed extent and mark in PFS Allocate 1 page Record allocation in system tables
  19. 19. Tempdb Algorithm – how to choose a file? 19 Round robin/proportional fill approach For each “allocation” we switch to next file with “equal free space” Skip files that are not so free We calculate the “proportion” - After recovery - When adding or removing files - Every 8192 extent allocations Trace flag 1165 – dump numbers
  20. 20. Allocation of user and tempdb 20 And why is SQL Server 2005 SP2 CU KB9836185 that important?
  21. 21. The pressure • PFS, GAM and SGAM • Frequent create/drop of tables • Internal objects allocation/deallocation The symptoms • PAGELATCH waits • NOT PAGELATCHIO waits The solution • Temp table caching • Trace flag 1118 • Multiple data files (always restart after adding!) The collision
  22. 22. TempDB Files - benchmark
  23. 23. Demo
  24. 24. THANK YOU

×