Database Structures
Database Structures
Database Structures
Database Structures
Module Overview
• Database Components
• File Groups and Files
• Extents
• Page Structure and Page Types
• Record Structure and Record Types
• Allocation Bitmaps and Special Pages
• Page Allocation and Allocation Units
• Demonstration: Analyzing Database Structures
Database Components
Database
File Group
(one or more)
Data File
(one or more)
Extent
(mixed or
uniform)
Pages
(8 KB each)
File Groups and Files
File groups
• Logical grouping of data files
• Can bring administration and performance benefits
• FILESTREAM has its own file group
Database Files
• Data Files
• At least one per database
• Multiple files can help improve performance, aid
maintainability and circumvent operating system file size
limitations
• Transaction Log Files
• Usually only one per database—no performance advantage
from multiple files
Extents
Pages:
8 KB in size Page Types
96-byte page header
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)
Record Structure and Record Types
• Record Structure
• Record Types:
• Data records
• Forwarding/forwarded records
• Index records
• Leaf level index records
• Non-leaf level index records
• Text records
• Versioned records
• Ghost records
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
• To improve performance:
• Place additional data files in a separate file group to
the primary data file and mark the new file group as
DEFAULT
• Split multiple data files across different physical disks
• Place heavily used tables and their nonclustered
indexes on different physical disks
Physical I/O vs. Logical I/O
• 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 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
Demonstration: Shrinking Databases
• tempdb Usage
• Version Store Internals
• tempdb Configuration
• Demonstration: Monitoring tempdb Usage
tempdb Usage
tempdb
• Stores:
• Internal objects
• Version store
• Some user objects
• Recreated at startup
• Must not be allowed to run out of space
• Should be actively monitored
Version Store Internals
• Version store:
• Stores all version records from all databases
• New allocation unit created every minute
• Cleanup happens every minute
• Nonlogged operation
tempdb Configuration
• tempdb configuration
• Enable instant file initialization
• Size for expected workload
• Isolate tempdb data files
• Use multiple data files
• Enable auto growth as a contingency
• Prohibited operations
• Backup and restore
• Add file groups
• Change collation
• Set offline or read only
Demonstration: Monitoring tempdb Usage
Logon Information
Virtual machine: 10987C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd