Introduction to SQL Server Memory Management - for the DBA
-
Upload
ikosmik -
Category
Technology
-
view
275 -
download
2
Transcript of Introduction to SQL Server Memory Management - for the DBA
MemoryManagementSQLServerExploration
byiKosmikGurukulam
www.sqlserverapp.com
• SQL Server dynamically allocates &frees memory
• No need to explicitly configure it
www.sqlserverapp.com
Then, why worryabout memorymanagement?
www.sqlserverapp.com
Becausethere is aVILLAIN!
Yes, Disk I/O!
I/O reads/writes arethe one of most
resource intensive!
www.sqlserverapp.com
M E M OR YM E M OR YU S A G EU S A G E
I / OI / OC OU N TC OU N T
SQL Server needs to balance these twofactors
www.sqlserverapp.com
M E M OR YM E M OR YU S A G EU S A G E
I / OI / OC OU N TC OU N T
Storing too much in memory also bloatsup SQL Server's memory usage
www.sqlserverapp.com
M E M OR YM E M OR YU S A G EU S A G E I / OI / O
C OU N TC OU N T
Reducing memory use willrequire more frequent disk
I/O! www.sqlserverapp.com
BUFFERMANAGEMENT
Key to achieving I/Oefficiency
www.sqlserverapp.com
BUFFER
8KB page inmemory
www.sqlserverapp.com
C O M P O N E N T SC O M P O N E N T S I NI NB U F F E RB U F F E R M A N A G E M E N TM A N A G E M E N T
BUFFER CACHE /POOL
BUFFERMANAGER
www.sqlserverapp.com
C O M P O N E N T SC O M P O N E N T S I NI NB U F F E RB U F F E R M A N A G E M E N TM A N A G E M E N T
BUFFER CACHE /POOL
Consists of 8 KB pageswww.sqlserverapp.com
H O WH O W D O E SD O E S I TI T O P E R A T E ?O P E R A T E ?
BUFFER CACHE /POOL DISK
Page is read into pool when needed
?
www.sqlserverapp.com
H O WH O W M U C HM U C H M E M O R YM E M O R Y I SI SU S E DU S E D B YB Y T H ET H E B U F F E RB U F F E R
C A C H E ?C A C H E ?
www.sqlserverapp.com
It makes sense to understand SQLServer's memory usage first
www.sqlserverapp.com
HOW DOES SQL SERVER USESYSTEM MEMORY?
SQL Serverreserves some
memory from thesystem for itspotential usage
TARGET MEMORY
SQL Server usesonly what it
actually needs atthat point in time
COMMITTED MEMORY
www.sqlserverapp.com
Q U E R Y I N GQ U E R Y I N G F O RF O R I T !I T !
SELECTcounter_name AS "STATISTIC NAME",(cntr_value/ (1024)) AS "MEMORY VALUE (MB)"FROMsys.dm_os_performance_countersWHEREcounter_nameIN ('Total Server Memory (KB)', 'Target Server Memory (KB)')
www.sqlserverapp.com
o ro r y o uy o u c o u l dc o u l d a l s oa l s o t r yt r y t h i st h i sq u e r y !q u e r y !
SELECTcommitted_kb / (1024),committed_target_kb / (1024*1024)FROMsys.dm_os_sys_info
www.sqlserverapp.com
H O WH O W D O E SD O E S S Q LS Q L S E R V E RS E R V E R U S EU S ES Y S T E MS Y S T E M M E M O R Y ?M E M O R Y ?
TARGETMEMORY
COMMITTEDMEMORY
Ramp Up
www.sqlserverapp.com
Interaction of Buffer Manager
BU F F E RBU F F E RM A N A G E RM A N A G E R
R E S OU R C ER E S OU R C EM A N A G E RM A N A G E R
DA T A BA S EDA T A BA S EM A N A G E RM A N A G E R
L OGL OGM A N A G E RM A N A G E R
Memoryusage
low-levelfile I/O
Write-aheadlogging
www.sqlserverapp.com
Information about the pages in theBuffer Pool
sys.dm_os_buffer_descriptors
www.sqlserverapp.com
ALLOCATION UNIT
Some concepts related tosys.dm_os_buffer_descriptors explained
Types/Categories of data stored in pages
3 TYPES
IN_ROW_DATA
ROW_OVERFLOW_DATA
LOB_DATA
Data in the row
When data exceeds8060 bytes
To store LOB datatype
www.sqlserverapp.com
SELECTCOUNT(*) AS number_of_pages_cached,((COUNT(*) * 8.0) / 1024) AScache_usage_in_mb,CASE
database_idWHEN 32767
THEN 'ResourceDb'ELSE DB_NAME(database_id)
END AS Database_nameFROM sys.dm_os_buffer_descriptorsGROUP BY DB_NAME(database_id) , database_idORDER BY cached_pages_count DESC;
Keeping track of pages in the Buffer Pool
www.sqlserverapp.com
TORN PAGEPROTECTION
Data Integrity Protection Mechanisms
CHECKSUMPROTECTION
2 bits to validate dataintegrity
If power failure duringdisk write corrupts data,this may not protect the
integrity always.
But this method is lessresource-intensive
Calculates checksum basedon whole data
Costlier, i.e. more resourceintensive
Is a more reliable way tocatch data integrity issues
www.sqlserverapp.com
Hope you enjoyed the slides!
Write your queries, suggestions or if youneed tutorial on any specific topic
www.sqlserverapp.com