introduction to sql server memory management - for the dba
TRANSCRIPT
![Page 1: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/1.jpg)
MemoryManagementSQLServerExploration
byiKosmikGurukulam
www.sqlserverapp.com
![Page 2: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/2.jpg)
• SQL Server dynamically allocates &frees memory
• No need to explicitly configure it
www.sqlserverapp.com
![Page 3: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/3.jpg)
Then, why worryabout memorymanagement?
www.sqlserverapp.com
![Page 4: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/4.jpg)
Becausethere is aVILLAIN!
Yes, Disk I/O!
I/O reads/writes arethe one of most
resource intensive!
www.sqlserverapp.com
![Page 5: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/5.jpg)
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
![Page 6: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/6.jpg)
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
![Page 7: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/7.jpg)
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
![Page 8: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/8.jpg)
BUFFERMANAGEMENT
Key to achieving I/Oefficiency
www.sqlserverapp.com
![Page 9: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/9.jpg)
BUFFER
8KB page inmemory
www.sqlserverapp.com
![Page 10: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/10.jpg)
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
![Page 11: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/11.jpg)
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
![Page 12: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/12.jpg)
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
![Page 13: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/13.jpg)
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
![Page 14: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/14.jpg)
It makes sense to understand SQLServer's memory usage first
www.sqlserverapp.com
![Page 15: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/15.jpg)
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
![Page 16: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/16.jpg)
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
![Page 17: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/17.jpg)
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
![Page 18: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/18.jpg)
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
![Page 19: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/19.jpg)
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
![Page 20: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/20.jpg)
Information about the pages in theBuffer Pool
sys.dm_os_buffer_descriptors
www.sqlserverapp.com
![Page 21: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/21.jpg)
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
![Page 22: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/22.jpg)
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
![Page 23: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/23.jpg)
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
![Page 24: Introduction to SQL Server Memory Management - for the DBA](https://reader034.vdocuments.net/reader034/viewer/2022042615/55a687901a28ab341e8b45fd/html5/thumbnails/24.jpg)
Hope you enjoyed the slides!
Write your queries, suggestions or if youneed tutorial on any specific topic
www.sqlserverapp.com