SlideShare a Scribd company logo
SQL Server
Database
Structures
PRESENTERINFO
1982 I started working with computers
1988 I started my professional career in computers industry
1996 I started working with SQL Server 6.0
1998 I earned my first certification at Microsoft as
Microsoft Certified Solution Developer (3rd in Greece)
1999 I started my career as Microsoft Certified Trainer (MCT) with more than
30.000 hours of training until now!
2010 I became for first time Microsoft MVP on Data Platform
I created the SQL School Greece www.sqlschool.gr
2012 I became MCT Regional Lead by Microsoft Learning Program.
2013 I was certified as MCSE : Data Platform
I was certified as MCSE : Business Intelligence
2016 I was certified as MCSE: Data Management & Analytics
2017 Certified as MCSA : Machine Learning
Recertified as MCSE: Data Management & Analytics
Antonios
Chatzipavlis
Data Solutions
Consultant & Trainer
MVP on Data Platform
MCT, MCSE, MCITP, MCPD, MCSD, MCDBA,
MCSA, MCTS, MCAD, MCP, OCA, ITIL-F
Μια πηγή ενημέρωσης για την Microsoft Data Platform
προς τους Έλληνες IT Professionals, DBAs, Developers,
Information Workers αλλά και απλούς χομπίστες που
απλά τους αρέσει ο SQL Server.
Help line : help@sqlschool.gr
• Articles about SQL Server
• SQL Server News
• SQL Nights
• Webcasts
• Downloads
• Resources
What we are doing here Follow us in socials
fb/sqlschoolgr
fb/groups/sqlschool
@antoniosch
@sqlschool
yt/c/SqlschoolGr
SQL School Greece group
SELECT KNOWLEDGE
FROM SQL SERVER
Connect with PASS
Sign up for a free membership today at:
pass.org
is the PASS Local Group in Greece
PASS VIRTUAL CHAPTERS
SPONSORS
PRESENTATIONCONTENT
• Database Structure Internals
• Data File Internals
• tempdb Internals
DATABASE
STRUCTURE
INTERNALS
• 32,767 Databases per instance
• 524,767 TB is the max size per
database
• 16 TB is the max size for each data file
• 2 TB is the max size for each log file
• 32,767 files per database
• 32,767 filegroups per database
• 64 KB is the size of each Extent
- 8 pages X 8 KB per page
• 8 KB is the size of each Page
DATABASE COMPONENTS
Database
File Group
(one or more)
Data File
(one or more)
Extent
(mixed or uniform)
Pages
(8 KB each)
File groups
• Logical grouping of data files
• Can bring administration and
performance benefits
• FILESTREAM has its own file group
FILEGROUPS AND DATABASE FILES
Database Files
• Data Files
- At least one per database
- Multiple files can:
- improve performance,
- aid maintainability
- circumvent operating system file size
limitations
• Transaction Log Files
- Usually only one per database
- No performance advantage from
multiple files
EXTENTS
Comprises eight physically continuous pages
Mixed
shared between
different
database objects
Uniform
owned by a
single
database object
PAGE STRUCTURE AND PAGE TYPES
Page Types
• Data (1)
• Index (2)
• Text (3 and 4)
• Boot (13)
• File Header (15)
• PFS (11)
• GAM (8)
• SGAM (9)
• IAM (10)
• DIFF_MAP (16)
• ML_MAP (17)
PAGE HEADER
pageID The file number and page number of this page in the database Metadata: ObjectId The ID of the object to which this page belongs
slotCnt The total number of slots (rows) used on this page Metadata: PartitionId The ID of the partition that this page is part of
Type Page Type Metadata: AllocUnitId The ID of the allocation unit that contains this page
LSN The LSN corresponding to the last log entry that changed this page freeData The byte offset of the first free space on this page
nextPage The file number and page number of the next page if this page is in
a page chain
Pminlen The number of bytes in fixed-length portion of rows
prevPage The file number and page number of the previous page if this page
is in a page chain
freeCnt The number of free bytes on the page
Level The level of this page in an index (always 0 for leaf pages) indexId The index ID of this page (always 0 for data pages)
• Data rows for in-row data
- The maximum size of a single data row is 8,060 bytes of in-row data.
- Rows can also have row-overflow and LOB data stored on separate pages.
- The number of rows stored on a given page varies depending on the table
structure and on the data being stored.
- A table with all fixed-length columns always can store the same number of
rows per page
- Variable-length rows can store as many rows as will fit based on the actual
length of the data entered.
- Keeping the row length shorter allows more rows to fit on a page, thus
reducing I/O and increasing the likelihood that needed data can stay in cache.
• Row offset array
- The row offset array is a block of 2-byte entries
- Each indicating the offset on the page at which the corresponding data row
begins.
- The row offset array indicates the logical order of rows on a page.
- For example, if a table has a clustered index, SQL Server stores the rows in the order of the
clustered index key.
- This doesn’t mean the rows are physically stored on the page in the order of
the clustered index key.
- Rather, slot 0 in the offset array refers to the first row in the clustered index key order, slot 1
refers to the second row, and so forth
DATA ROWS AND ROW OFFSET ARRAY
• Status Bits A
- Bit 0. This indicates special versioning information. In SQL Server 2012, this is always 0.
- Bits 1 through 3. Taken as a 3-bit value,
- 0(000) indicates a primary record,
- 1 (001) indicates a forwarded record,
- 2 (010) indicates a forwarding stub,
- 3 (011) indicates an index record,
- 4 (100) indicates a BLOB fragment or row-overflow data
- 5(101) indicates a ghost index record
- 6(110) indicates a ghost data record,
- 7(111) indicates a ghost version record.
- Bit 4. This indicates that a NULL bitmap exists. In SQL Server 2012, a NULL bitmap is always
present, even if no NULLs are allowed in any column.
- Bit 5. This indicates that variable-length columns exist in the row.
- Bit 6. This indicates that the row contains versioning information.
- Bit 7. This isn’t used in SQL Server 2012.
• Status Bits B
- The only bit used in the Status Bits B field indicates that the record is a ghost forwarded record.
RECORD STRUCTURE AND RECORD TYPES
• File Header Page (FH)
• Page Free Space (PFS)
• Global Allocation Map (GAM)
• Shared Global Allocation Map (SGAM)
• Differential Change Map (DCM)
• Bulk Change Map
• Boot Page
• Index Allocation Map (IAM)
ALLOCATION BITMAPS AND SPECIAL PAGES
• Page allocation
•The process of allocating new pages to an object
• Allocation units
•IN_ROW_DATA
•LOB_DATA
•ROW_OVERFLOW_DATA
• Page allocations can be analysed using DBCC page
PAGE ALLOCATION AND ALLOCATION UNITS
DBCC PAGE
DBCC PAGE ({dbid | dbname}, filenum, pagenum[, printopt])
DBCC TRACEON(3604);
GO
DBCC PAGE (AdventureWorks2012, 1, 266, 1);
ANALYZING
DATABASE STRUCTURES
DATA FILE
INTERNALS
VOLUME CONFIGURATION BEST PRACTICES
Volume
RAID 10 for
transaction log
files
RAID 10 or RAID
5 for database
data files
Store data and
transaction log
files on physically
separate volumes
Defragment disks
frequently
Size data and
transaction log
files to avoid
auto growth
NUMBER OF DATA FILES AND PL ACEMENT
For most databases
a single data file is
sufficient:
To improve
performance:
• Logical I/O
- pages read from cache
• Physical I/O
- pages read from disk
• You can view physical and logical
I/O stats using
- the DMV sys.dm_exec_query_stats
or
- by using the Transact-SQL
command SET STATISTICS IO ON
before issuing a query.
- SET STATISTICS IO ON will only return
statistics for queries in the current
session.
PHYSICAL I/O VS. LOGICAL I/O
• Buffer cache hit ratio
- percentage of pages read from cache
without having to be read from disk
- calculated by the formula ((logical
reads–physical reads)/logical reads) *
100.
- a SQL Server instance that is
performing well will have a buffer
cache hit ratio close to 100.
- The buffer cache hit ratio can be
improved by making more memory
available to SQL Server.
ALLOCATIONS WITHIN DATA FILES
Allocation is simple
in a file group that
has a single file
In a multifile group,
SQL Server uses:
• Round robin allocation
• Proportional fill
INSTANT FILE INITIALIZATION
Improves
performance by
skipping zeroing
of data pages on
file creation and
growth
Best practice is
to enable
following
assessment of
security risk
Disabled by
default: security
risk
Auto Grow
• Automatically expands a file
when space is low
• Manually manage file size for
better performance
• Auto grow best practices:
- Leave enabled to avoid
downtime in case file size limit is
reached
- Set to a fixed rather than a
percentage
AUTO GROW AND AUTO SHRINK
Auto Shrink
• Shrinks data file automatically
to release disk space
• Use with caution as:
- Auto shrink causes index
fragmentation
- It’s uncontrollable and affects
performance
- It can lead to growth-shrink cycle
severely affecting performance
DATA FILE SHRINKING
Shrink
• Causes index
fragmentation
• Resource intensive
• Degrades
performance
Best used for
• Emptying a file
before removing it
• Changing a file or
file group to read
only
• Reclaiming free
space following
large delete
operation
Alternative
• Move all indexes
to a new file group
• Move heaps with
shrink. Heaps are
not fragmented
with shrink
• Remove old file
group
Database file configuration
• SSMS database properties
• sp_helpfile and
sp_helpfilegroup
• sys.database_files and
sys.filegroups
• sys.master_files
• sys.dm_db_file_space_usage
MONITORING DATABASE FILES
Database file activity
•SSMS Activity Monitor – Data File
I/O
•Wait statistics –
PAGEIOLATCH_*, WRITELOG
•sys.dm_io_virtual_file_stats
ALLOCATIONS
WITHIN DATA FILES
TEMPDB
INTERNALS
TEMPDB USAGE
tempdb
tempdb Stores:
• Internal objects
• Version store
• Some user objects
Recreated at
startup
Must not be
allowed to run
out of space
Should be
actively
SQLServer Database Structures
VERSION STORE INTERNALS
Stores all version
records from all
databases
New allocation unit
created every minute
Cleanup happens every
minute
Nonlogged operation
Version Store
Configuration
• Enable instant file initialization
• Size for expected workload
• Isolate tempdb data files
• Use multiple data files
• Enable auto growth as a
contingency
TEMPDB CONFIGURATION
Prohibited operations
• Backup and restore
• Add file groups
• Change collation
• Set offline or read only
tempdb size can be monitored using the sys.dm_db_file_space_usage DMV
MONITORING
TEMPDB USAGE
Ask your
Questions
EVALUATIONS
http://bit.ly/2xUr3XP
EVENT EVALUATION LINK SESSIONS EVALUATION LINK
http://bit.ly/2snEVoq
Thank you
SELECT KNOWLEDGE FROM SQL SERVER
Copyright © 2018 SQLschool.gr. All right reserved.
PRESENTER MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION

More Related Content

PPT
Sql Server Basics
PPT
MySql slides (ppt)
PPTX
An Introduction To Oracle Database
PPTX
Oracle architecture with details-yogiji creations
PDF
Diving into Delta Lake: Unpacking the Transaction Log
PDF
Indexes and Indexing in Oracle 12c
PPT
Indexing and hashing
PDF
PostgreSql query planning and tuning
Sql Server Basics
MySql slides (ppt)
An Introduction To Oracle Database
Oracle architecture with details-yogiji creations
Diving into Delta Lake: Unpacking the Transaction Log
Indexes and Indexing in Oracle 12c
Indexing and hashing
PostgreSql query planning and tuning

What's hot (20)

PPT
SQL subquery
ODP
Introduction to triggers
PPT
Sql join
PPTX
SQL Joins.pptx
PPTX
Basic sql Commands
PPTX
RBS in SharePoint
PPTX
Sql server ___________session_17(indexes)
PPTX
9. index and index organized table
PPTX
MySql: Queries
PPTX
12. oracle database architecture
PDF
Cassandra Database
PPTX
introduction to NOSQL Database
PDF
MS-SQL SERVER ARCHITECTURE
PPTX
PPTX
Sql subquery
PPTX
Introduction to triggers
PDF
AWS Glue - let's get stuck in!
PPT
Joins in SQL
PPT
SQL Queries
PDF
SQL Joins and Query Optimization
SQL subquery
Introduction to triggers
Sql join
SQL Joins.pptx
Basic sql Commands
RBS in SharePoint
Sql server ___________session_17(indexes)
9. index and index organized table
MySql: Queries
12. oracle database architecture
Cassandra Database
introduction to NOSQL Database
MS-SQL SERVER ARCHITECTURE
Sql subquery
Introduction to triggers
AWS Glue - let's get stuck in!
Joins in SQL
SQL Queries
SQL Joins and Query Optimization
Ad

Similar to SQLServer Database Structures (20)

PPTX
Best Practices and Performance Tuning of U-SQL in Azure Data Lake (SQL Konfer...
PPTX
SQL Server 2014 Memory Optimised Tables - Advanced
PPTX
Pass chapter meeting dec 2013 - compression a hidden gem for io heavy databas...
PPT
Implementing the Databese Server session 02
PPTX
Best storage engine for MySQL
PPTX
Sql Bits 2020 - Designing Performant and Scalable Data Lakes using Azure Data...
PDF
MySpace Data Architecture June 2009
PDF
Prague data management meetup 2018-03-27
PPTX
VLDB Administration Strategies
PPTX
Optimize SQL server performance for SharePoint
ODP
Mysql For Developers
PPTX
SharePoint 2010 database maintenance
PPT
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
PDF
Introduction to Azure Data Lake
PDF
Dipping Your Toes: Azure Data Lake for DBAs
PDF
In-memory ColumnStore Index
PPTX
SQL Server 2016 New Features and Enhancements
PPTX
What's new in SQL Server 2016
PPT
ora_sothea
PDF
Deep Dive into DynamoDB
Best Practices and Performance Tuning of U-SQL in Azure Data Lake (SQL Konfer...
SQL Server 2014 Memory Optimised Tables - Advanced
Pass chapter meeting dec 2013 - compression a hidden gem for io heavy databas...
Implementing the Databese Server session 02
Best storage engine for MySQL
Sql Bits 2020 - Designing Performant and Scalable Data Lakes using Azure Data...
MySpace Data Architecture June 2009
Prague data management meetup 2018-03-27
VLDB Administration Strategies
Optimize SQL server performance for SharePoint
Mysql For Developers
SharePoint 2010 database maintenance
Maaz Anjum - IOUG Collaborate 2013 - An Insight into Space Realization on ODA...
Introduction to Azure Data Lake
Dipping Your Toes: Azure Data Lake for DBAs
In-memory ColumnStore Index
SQL Server 2016 New Features and Enhancements
What's new in SQL Server 2016
ora_sothea
Deep Dive into DynamoDB
Ad

More from Antonios Chatzipavlis (20)

PPTX
Data virtualization using polybase
PDF
SQL server Backup Restore Revealed
PDF
Migrate SQL Workloads to Azure
PDF
Machine Learning in SQL Server 2019
PDF
Workload Management in SQL Server 2019
PDF
Loading Data into Azure SQL DW (Synapse Analytics)
PDF
Introduction to DAX Language
PDF
Building diagnostic queries using DMVs and DMFs
PDF
Exploring T-SQL Anti-Patterns
PDF
Designing a modern data warehouse in azure
PDF
Modernizing your database with SQL Server 2019
PDF
Designing a modern data warehouse in azure
PDF
Sqlschool 2017 recap - 2018 plans
PDF
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
PDF
Microsoft SQL Family and GDPR
PDF
Statistics and Indexes Internals
PDF
Azure SQL Data Warehouse
PDF
Introduction to azure document db
PDF
Introduction to Machine Learning on Azure
PDF
Introduction to sql database on azure
Data virtualization using polybase
SQL server Backup Restore Revealed
Migrate SQL Workloads to Azure
Machine Learning in SQL Server 2019
Workload Management in SQL Server 2019
Loading Data into Azure SQL DW (Synapse Analytics)
Introduction to DAX Language
Building diagnostic queries using DMVs and DMFs
Exploring T-SQL Anti-Patterns
Designing a modern data warehouse in azure
Modernizing your database with SQL Server 2019
Designing a modern data warehouse in azure
Sqlschool 2017 recap - 2018 plans
Azure SQL Database for the SQL Server DBA - Azure Bootcamp Athens 2018
Microsoft SQL Family and GDPR
Statistics and Indexes Internals
Azure SQL Data Warehouse
Introduction to azure document db
Introduction to Machine Learning on Azure
Introduction to sql database on azure

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
KodekX | Application Modernization Development
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
KodekX | Application Modernization Development
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
Advanced methodologies resolving dimensionality complications for autism neur...
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

SQLServer Database Structures

  • 2. PRESENTERINFO 1982 I started working with computers 1988 I started my professional career in computers industry 1996 I started working with SQL Server 6.0 1998 I earned my first certification at Microsoft as Microsoft Certified Solution Developer (3rd in Greece) 1999 I started my career as Microsoft Certified Trainer (MCT) with more than 30.000 hours of training until now! 2010 I became for first time Microsoft MVP on Data Platform I created the SQL School Greece www.sqlschool.gr 2012 I became MCT Regional Lead by Microsoft Learning Program. 2013 I was certified as MCSE : Data Platform I was certified as MCSE : Business Intelligence 2016 I was certified as MCSE: Data Management & Analytics 2017 Certified as MCSA : Machine Learning Recertified as MCSE: Data Management & Analytics Antonios Chatzipavlis Data Solutions Consultant & Trainer MVP on Data Platform MCT, MCSE, MCITP, MCPD, MCSD, MCDBA, MCSA, MCTS, MCAD, MCP, OCA, ITIL-F
  • 3. Μια πηγή ενημέρωσης για την Microsoft Data Platform προς τους Έλληνες IT Professionals, DBAs, Developers, Information Workers αλλά και απλούς χομπίστες που απλά τους αρέσει ο SQL Server. Help line : help@sqlschool.gr • Articles about SQL Server • SQL Server News • SQL Nights • Webcasts • Downloads • Resources What we are doing here Follow us in socials fb/sqlschoolgr fb/groups/sqlschool @antoniosch @sqlschool yt/c/SqlschoolGr SQL School Greece group SELECT KNOWLEDGE FROM SQL SERVER
  • 4. Connect with PASS Sign up for a free membership today at: pass.org is the PASS Local Group in Greece
  • 7. PRESENTATIONCONTENT • Database Structure Internals • Data File Internals • tempdb Internals
  • 9. • 32,767 Databases per instance • 524,767 TB is the max size per database • 16 TB is the max size for each data file • 2 TB is the max size for each log file • 32,767 files per database • 32,767 filegroups per database • 64 KB is the size of each Extent - 8 pages X 8 KB per page • 8 KB is the size of each Page DATABASE COMPONENTS Database File Group (one or more) Data File (one or more) Extent (mixed or uniform) Pages (8 KB each)
  • 10. File groups • Logical grouping of data files • Can bring administration and performance benefits • FILESTREAM has its own file group FILEGROUPS AND DATABASE FILES Database Files • Data Files - At least one per database - Multiple files can: - improve performance, - aid maintainability - circumvent operating system file size limitations • Transaction Log Files - Usually only one per database - No performance advantage from multiple files
  • 11. EXTENTS Comprises eight physically continuous pages Mixed shared between different database objects Uniform owned by a single database object
  • 12. PAGE STRUCTURE AND PAGE TYPES Page Types • Data (1) • Index (2) • Text (3 and 4) • Boot (13) • File Header (15) • PFS (11) • GAM (8) • SGAM (9) • IAM (10) • DIFF_MAP (16) • ML_MAP (17)
  • 13. PAGE HEADER pageID The file number and page number of this page in the database Metadata: ObjectId The ID of the object to which this page belongs slotCnt The total number of slots (rows) used on this page Metadata: PartitionId The ID of the partition that this page is part of Type Page Type Metadata: AllocUnitId The ID of the allocation unit that contains this page LSN The LSN corresponding to the last log entry that changed this page freeData The byte offset of the first free space on this page nextPage The file number and page number of the next page if this page is in a page chain Pminlen The number of bytes in fixed-length portion of rows prevPage The file number and page number of the previous page if this page is in a page chain freeCnt The number of free bytes on the page Level The level of this page in an index (always 0 for leaf pages) indexId The index ID of this page (always 0 for data pages)
  • 14. • Data rows for in-row data - The maximum size of a single data row is 8,060 bytes of in-row data. - Rows can also have row-overflow and LOB data stored on separate pages. - The number of rows stored on a given page varies depending on the table structure and on the data being stored. - A table with all fixed-length columns always can store the same number of rows per page - Variable-length rows can store as many rows as will fit based on the actual length of the data entered. - Keeping the row length shorter allows more rows to fit on a page, thus reducing I/O and increasing the likelihood that needed data can stay in cache. • Row offset array - The row offset array is a block of 2-byte entries - Each indicating the offset on the page at which the corresponding data row begins. - The row offset array indicates the logical order of rows on a page. - For example, if a table has a clustered index, SQL Server stores the rows in the order of the clustered index key. - This doesn’t mean the rows are physically stored on the page in the order of the clustered index key. - Rather, slot 0 in the offset array refers to the first row in the clustered index key order, slot 1 refers to the second row, and so forth DATA ROWS AND ROW OFFSET ARRAY
  • 15. • Status Bits A - Bit 0. This indicates special versioning information. In SQL Server 2012, this is always 0. - Bits 1 through 3. Taken as a 3-bit value, - 0(000) indicates a primary record, - 1 (001) indicates a forwarded record, - 2 (010) indicates a forwarding stub, - 3 (011) indicates an index record, - 4 (100) indicates a BLOB fragment or row-overflow data - 5(101) indicates a ghost index record - 6(110) indicates a ghost data record, - 7(111) indicates a ghost version record. - Bit 4. This indicates that a NULL bitmap exists. In SQL Server 2012, a NULL bitmap is always present, even if no NULLs are allowed in any column. - Bit 5. This indicates that variable-length columns exist in the row. - Bit 6. This indicates that the row contains versioning information. - Bit 7. This isn’t used in SQL Server 2012. • Status Bits B - The only bit used in the Status Bits B field indicates that the record is a ghost forwarded record. RECORD STRUCTURE AND RECORD TYPES
  • 16. • File Header Page (FH) • Page Free Space (PFS) • Global Allocation Map (GAM) • Shared Global Allocation Map (SGAM) • Differential Change Map (DCM) • Bulk Change Map • Boot Page • Index Allocation Map (IAM) ALLOCATION BITMAPS AND SPECIAL PAGES
  • 17. • Page allocation •The process of allocating new pages to an object • Allocation units •IN_ROW_DATA •LOB_DATA •ROW_OVERFLOW_DATA • Page allocations can be analysed using DBCC page PAGE ALLOCATION AND ALLOCATION UNITS
  • 18. DBCC PAGE DBCC PAGE ({dbid | dbname}, filenum, pagenum[, printopt]) DBCC TRACEON(3604); GO DBCC PAGE (AdventureWorks2012, 1, 266, 1);
  • 21. VOLUME CONFIGURATION BEST PRACTICES Volume RAID 10 for transaction log files RAID 10 or RAID 5 for database data files Store data and transaction log files on physically separate volumes Defragment disks frequently Size data and transaction log files to avoid auto growth
  • 22. NUMBER OF DATA FILES AND PL ACEMENT For most databases a single data file is sufficient: To improve performance:
  • 23. • Logical I/O - pages read from cache • Physical I/O - pages read from disk • You can view physical and logical I/O stats using - the DMV sys.dm_exec_query_stats or - by using the Transact-SQL command SET STATISTICS IO ON before issuing a query. - SET STATISTICS IO ON will only return statistics for queries in the current session. PHYSICAL I/O VS. LOGICAL I/O • Buffer cache hit ratio - percentage of pages read from cache without having to be read from disk - calculated by the formula ((logical reads–physical reads)/logical reads) * 100. - a SQL Server instance that is performing well will have a buffer cache hit ratio close to 100. - The buffer cache hit ratio can be improved by making more memory available to SQL Server.
  • 24. ALLOCATIONS WITHIN DATA FILES Allocation is simple in a file group that has a single file In a multifile group, SQL Server uses: • Round robin allocation • Proportional fill
  • 25. INSTANT FILE INITIALIZATION Improves performance by skipping zeroing of data pages on file creation and growth Best practice is to enable following assessment of security risk Disabled by default: security risk
  • 26. Auto Grow • Automatically expands a file when space is low • Manually manage file size for better performance • Auto grow best practices: - Leave enabled to avoid downtime in case file size limit is reached - Set to a fixed rather than a percentage AUTO GROW AND AUTO SHRINK Auto Shrink • Shrinks data file automatically to release disk space • Use with caution as: - Auto shrink causes index fragmentation - It’s uncontrollable and affects performance - It can lead to growth-shrink cycle severely affecting performance
  • 27. DATA FILE SHRINKING Shrink • Causes index fragmentation • Resource intensive • Degrades performance Best used for • Emptying a file before removing it • Changing a file or file group to read only • Reclaiming free space following large delete operation Alternative • Move all indexes to a new file group • Move heaps with shrink. Heaps are not fragmented with shrink • Remove old file group
  • 28. Database file configuration • SSMS database properties • sp_helpfile and sp_helpfilegroup • sys.database_files and sys.filegroups • sys.master_files • sys.dm_db_file_space_usage MONITORING DATABASE FILES Database file activity •SSMS Activity Monitor – Data File I/O •Wait statistics – PAGEIOLATCH_*, WRITELOG •sys.dm_io_virtual_file_stats
  • 31. TEMPDB USAGE tempdb tempdb Stores: • Internal objects • Version store • Some user objects Recreated at startup Must not be allowed to run out of space Should be actively
  • 33. VERSION STORE INTERNALS Stores all version records from all databases New allocation unit created every minute Cleanup happens every minute Nonlogged operation Version Store
  • 34. Configuration • Enable instant file initialization • Size for expected workload • Isolate tempdb data files • Use multiple data files • Enable auto growth as a contingency TEMPDB CONFIGURATION Prohibited operations • Backup and restore • Add file groups • Change collation • Set offline or read only tempdb size can be monitored using the sys.dm_db_file_space_usage DMV
  • 37. EVALUATIONS http://bit.ly/2xUr3XP EVENT EVALUATION LINK SESSIONS EVALUATION LINK http://bit.ly/2snEVoq
  • 39. SELECT KNOWLEDGE FROM SQL SERVER Copyright © 2018 SQLschool.gr. All right reserved. PRESENTER MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION