Upload
miroslav-dimitrov
View
227
Download
0
Tags:
Embed Size (px)
Citation preview
©2011 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice
Miroslav DimitrovBoris Hristov
INSIDE TEMPDB(ALMOST LEVEL 500)
2
Our agenda = answer the WWW questions…
1. Tempdb creation
2. Logging
3. Allocations
Tempdb creation
4
Right after master, we create tempdbOpen model firstCreate tempdb based on model and propertiesNotify tempdb is readyIf we fail – server goes down!
5
How?
Lock model and tempdb! Copy extents from model to tempdb (including objects)Fixup the tempdb data fileThen tlog fileCreate attach the other files
-f option1 primary data file the size of model (unlimited fixed auto grow)Build one primary log 516096 – 2vlfs + header = 516096 bytes (unlimited 10% autogrowth)DATA FolderOrginal sizes are retained
Demo
7
How?
Lock model and tempdb! Copy extents from model to tempdb (including objects)Fixup the tempdb data fileThen tlog fileCreate attach the other files
-f option1 primary data file the size of model (unlimited fixed auto grow)Build one primary log 516096 – 2vlfs + header = 516096 bytes (unlimited 10% autogrowth)DATA FolderOrginal sizes are retained
8
Before tempdb is ready – no one will use it
9
Tempdb log
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 loginternal objects – mostly allocation logging
Tempdb logging
Demo
12
After image logging
Table with value of 1
Tempdb allocations
14
What is there in tempdb exactly?
User Objects
• Temp tables• Table variables• UDFs• Online index space• …
Internal Objects
• Sort tables• Worktables• Workfiles• Version Store
15
Temporary table caching
We cache…• Stored procs• Triggers • Functions
Why?
16
Internal objects
Internal
Objects
• Sort tables• Worktables• Workfiles• Version Store
17
TempDB allocations
PFS / GAM / SGAM pages
The only place MS do non-logged allocations!
What about contention?
18
How is a table created inside tempdb?
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
Tempdb Algorithm – how to choose a file?
Round robin/proportio
nal 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
Allocation of user and tempdb
And why is SQL Server 2005 SP2 CU KB9836185 that important?
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
TempDB Files - benchmark
Demo
THANK YOU