SlideShare a Scribd company logo
UNDERSTANDING THE
TRANSACTION LOG;
YOUR KEY TO UNLOCKING
GREATER THROUGHPUT
Richard Douglas
• Sales Engineer, SQL Sentry
• Social Media: @SQLRich, LinkedIn,
• Blog Info: http://blogs.sqlsentry.com/author/RichardDouglas/;
http://SQL.RichardDouglas.co.uk
Tuning blog: http://www.sqlperformance.com/
E-mail ebooks@sqlsentry.com for free copies of our $10 e-books:
YOUR HOST
• Richard Douglas
• Sales Engineer at SQL Sentry
• Blog:
http://SQL.RichardDouglas.co.uk
• Twitter: @SQLRich
• Email: RDouglas@SQLSentry.com
• Slides:
http://www.Slideshare.net/SQLRich
AGENDA
• When the log is used
• Internals
• Hardware
• Database Architecture
• Coding
• Monitoring
• Wrap Up
Logs, that’s all about
backups right?
SQL Server will use the
transaction log for almost
every transaction
Data
File
SNI
Phase 0
Phase 1
Phase 2
Optimizer
Command
Parser
Query
Executor
Access
Methods
Buffer
Manager
Pre-Opt
Execution Plan
TDS
TDS
Query Tree Language Event
Plan Cache
Buffer Cache
Buffer Pool
Storage
Engine
Relational Engine
Protocol
Layer
Results
SELECT
Statement
Buffer
Pool
Extension
Log
File
Data
File
SNI
Phase 0
Phase 1
Phase 2
Optimizer
Command
Parser
Query
Executor
Access
Methods
Buffer
Manager
Pre-Opt
Execution Plan
TDS
TDS
Query Tree Language Event
Plan Cache
Buffer Cache
Buffer PoolStorage
Engine
Relational Engine
Protocol
Layer
Results
Transaction
Manager
INSERT
Statement
RECOVERY MODELS
• Simple
• Full
• Bulk Logged
Data
File
Log
File
SQL
Database
Automated administration Manual Administration
Note: Recovery model will be defaulted to the one in the Model database
MINIMALLY LOGGED OPERATIONS
• Bulk import operations*
– Bcp
– Bulk Insert
– INSERT / SELECT (External Tools)
• SELECT * INTO
• .Write in UPDATE statements (new values only)
• WRITETEXT and UPDATETEXT (new values only, marked for deprecation)
• Some DDL Statements
– CREATE INDEX
– ALTER INDEX REBUILD / DBCC DBREINDEX (marked for deprecation)
– DROP INDEX (Index pages fully logged)
• When using Transactional Replication this will be fully logged.
TRANSACTION LOG INTERNALS
• The Transaction Log is segmented into pieces called
Virtual Log Files (VLF’s)
• There will always be at least one “active” VLF
• Having too many VLF’s is thought to be a bad thing.
• How many is too many and how are they calculated?
Active
VLF
Inactive
VLF
Inactive
VLF
Inactive
VLF
Inactive
VLF
Yes, another 9 sets like this would make 50 shades of grey.
CALCULATING VLFS
• Pre2014 the numberof VLF’s is determined by the size at creation / growth time.
– Under 64MB 4VLF’s
– >=64and> 1GB 8 VLF’s
– >= 1GB 16 VLF’s
• In 2014, if the growth size is less than 1/8 the size of the log
Then create1 single VLF at the size of the growth size
Else use the pre2014 formula
• But wait, there’s more. VLF’s aren’t the smallest segment of the Transaction Log …
LOG BLOCKS
• Each VLF will have a numberof “Log Blocks” inside it
• These blocks varyin size:
– Anywherebetween 512bytesand60KB
• A new block is createdwhen:
– The data insidethe blockhits the 60KB limit
– A commitor abortoccurswithin a transaction
• Each log block contains a parity bit of 64 or128 which is flipped everytime it is used.
• Inside each log block we have…
LOG RECORDS
• Log records are identified by Log Sequence Numbers or LSN’s
– VLF Sequence nbr: Logblock nbr : Logrecordnbr
• Each data page contains the LSN of the last recordthat made changes to that page.
• Log records are written in the orderthey occur.
i.e.SQL Serverwill notwait for a transaction to finish before writing away another concurrent transaction.
• Log records often storebefore and after images of changes.
• Theycontain a list of pages that this change has affected.
• Log records are stored in the buffer pool (log cache)until flushed to disk
Look for WAITLOG wait type.
CHECKPOINT
• Data pages are markedas “dirty” when they are changed.
• Thecheckpoint process writes all dirty pages to disk and marksthem as cleared.
• Checkpoint is an optimisation process, it reducesthe amount of writes to disk to keepdata up to date.
INTERESTING CHECKPOINT TRACE FLAGS
• 828 –Checkpoint resumes the behaviour that it exhibited before you installed SQLServer2000 SP3 when you
enabletrace flag 828 on a computer that is running SQL Server2000 SP4 - KB906121
• 3031 –In 2005 turns NO_LOG and TRUNCATE_ONLY backups to checkpoints in all recovery modes
http://bit.ly/1b7RFNV
• 3502 –Writes information about checkpoints tothe errorlog
• 3503 –Indicates whether the checkpointat the end of automatic recoverywas skipped for a database.
• 3504 –Writes further info about checkpoints to the errorlog
• 3505 –Disables automatic checkpoints
MAKING STUFF GO FASTER
Server / IO
Architecture
Database
Architecture
Coding
HARDWARE CHOICES
• IO Architecture can be a nightmare
• Local vs Shared
• Specifying drives
• RAID Levels
o Hardware RAID with large cash cache
DATABASE ARCHITECTURE
• Get the log size right early on
• Consider High Availability Overhead
• Only log what you need
• Beware of “evil” page splits
• Delayed Durability
HIGH AVAILABILITY OVERHEAD
• Log Shipping
• Database Mirroring
• AlwaysOn Availability Groups
• AlwaysOn Failover Clusters
• Replication
WATCH YOUR INDICES
The following add overhead, beware:
• Duplicate indices
• Unused indices
• Subsets of indices
Use the Dynamic Management Object
Sys.dm_db_Index_Usage_Stats to find out
how useful an index really is.
CODING
• “Temp Tables vs Table Variable” debate
o Blog post - http://bit.ly/1ZmvRtt
• “Rollback Gotchas”
o Blog post - http://bit.ly/1Z4ZfEm
• Batching transactions
MONITORING THE LOG
• Dynamic Management Objects
• Perfmon counters
• Wait statistics
• Reading the log!
Sys.dm_io_virtual_file_stats
Lots of Log based counters in SQLServer:Databases
LogBuffer and WriteLog are common
Understanding the Transaction Log, Your Key to Unlocking Greater Throughput
VLF RESULTS
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01
Update 02
Log Backup 02
Update 03
Log Backup 03
Backup Full
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02
Log Backup 02
Update 03
Log Backup 03
Backup Full
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02 219 209 25 27 204 210 24 25 27
Log Backup 02
Update 03
Log Backup 03
Backup Full
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02 219 209 25 27 204 210 24 25 27
Log Backup 02 237 217 21 16 231 219 18 14 15
Update 03
Log Backup 03
Backup Full
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02 219 209 25 27 204 210 24 25 27
Log Backup 02 237 217 21 16 231 219 18 14 15
Update 03 216 210 25 27 205 211 27 29 27
Log Backup 03
Backup Full
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02 219 209 25 27 204 210 24 25 27
Log Backup 02 237 217 21 16 231 219 18 14 15
Update 03 216 210 25 27 205 211 27 29 27
Log Backup 03 239 217 21 15 231 219 17 15 15
Backup Full
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02 219 209 25 27 204 210 24 25 27
Log Backup 02 237 217 21 16 231 219 18 14 15
Update 03 216 210 25 27 205 211 27 29 27
Log Backup 03 239 217 21 15 231 219 17 15 15
Backup Full 0 1 1 0 0 0 0 0 0
High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
Update 01 1673 516 222 54 1479 517 168 50 36
Log Backup 01 247 217 22 15 234 219 18 15 15
Update 02 219 209 25 27 204 210 24 25 27
Log Backup 02 237 217 21 16 231 219 18 14 15
Update 03 216 210 25 27 205 211 27 29 27
Log Backup 03 239 217 21 15 231 219 17 15 15
Backup Full 0 1 1 0 0 0 0 0 0
Totals 2831 1587 337 154 2584 1595 272 148 135
0
200
400
600
800
1000
1200
1400
1600
1800
Update 01
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
0
50
100
150
200
250
300
Update 01 Log Backup 01
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
Some outliers
have been
removed to
improve
readability
0
50
100
150
200
250
300
Update 01 Log Backup 01 Update 02
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
0
50
100
150
200
250
300
Update 01 Log Backup 01 Update 02 Log Backup 02
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
0
50
100
150
200
250
300
Update 01 Log Backup 01 Update 02 Log Backup 02 Update 03
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
0
50
100
150
200
250
300
Update 01 Log Backup 01 Update 02 Log Backup 02 Update 03 Log Backup 03
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
0
50
100
150
200
250
300
Update 01 Log Backup 01 Update 02 Log Backup 02 Update 03 Log Backup 03 Backup Full
High - 2012 External
Low - 2012 External
High - 2012 SSD
Low - 2012 SSD
High - 2014 External
Low - 2014 External
High - 2014 SSD
Low - 2014 SSD
Optimal - 2014 SSD
2014 HIGH VLF WAITS
39
58
Update 02
LOGBUFFER
QDS_SHUTDOWN_QUEUE
46
52
Update 03
LOGBUFFER
QDS_SHUTDOWN_QUEUE
7
10
4
20
7
49
Update 01
LATCH_EX
LCK_M_U
PREEMPTIVE_OS_FILEOPS
PREEMPTIVE_OS_FLUSHFILEBUFFERS
PREEMPTIVE_OS_WRITEFILEGATHER
QDS_SHUTDOWN_QUEUE
THANK YOU!
• Slides will be available at http://Slideshare.net/SQLRich
• More information at:
o SQLSkills, et al
• E-mail ebooks@sqlsentry.com for free copies of our e-books:
o Just tell them where you met me
• My contact info for other questions:
o RDouglas@SQLSentry.com
o Twitter: @SQLRich
o Blogs: http://SQL.RichardDouglas.co.uk /
http://http://blogs.sqlsentry.com/author/RichardDouglas

More Related Content

PPTX
SQLBits XIV - The Big Backup Theory
PPTX
Investigate TempDB Like Sherlock Holmes
PPTX
Understanding indices
PPTX
Wait Watchers ; Gain SQL Performance Increases Fast!
PPTX
LVOUG meetup #2 - Forcing SQL Execution Plan Instability
PDF
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
PDF
KoprowskiT - SQLBITS X - 2am a disaster just began
PDF
Database as a Service on the Oracle Database Appliance Platform
SQLBits XIV - The Big Backup Theory
Investigate TempDB Like Sherlock Holmes
Understanding indices
Wait Watchers ; Gain SQL Performance Increases Fast!
LVOUG meetup #2 - Forcing SQL Execution Plan Instability
KoprowskiT_Session2_SDNEvent_SourceControlForDBA
KoprowskiT - SQLBITS X - 2am a disaster just began
Database as a Service on the Oracle Database Appliance Platform

What's hot (19)

PPTX
Sql Server 2014 In Memory
PDF
The InnoDB Storage Engine for MySQL
PDF
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
PDF
MySQL 5.6 Performance
PDF
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
PDF
MySQL Performance Tuning: Top 10 Tips
PDF
KoprowskiT_SQLRelay2014#1_Reading_FromPlanToBackupToCloud
PDF
MySQL 5.6 - Operations and Diagnostics Improvements
PDF
DB12c: All You Need to Know About the Resource Manager
PDF
KoprowskiT-Difinify2017-SQL_ServerBackup_In_The_Cloud
PDF
Always on in sql server 2017
PDF
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
PDF
Upcoming changes in MySQL 5.7
PPTX
Drupal commerce performance profiling and tunning using loadstorm experiments...
PDF
Collaborate 2019 - How to Understand an AWR Report
PPTX
SQL Explore 2012: P&T Part 3
PPTX
My sql performance tuning course
PDF
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
PPTX
DAC 2012
Sql Server 2014 In Memory
The InnoDB Storage Engine for MySQL
KoprowskiT_SQLRelay2014#8_Birmingham_FromPlanToBackupToCloud
MySQL 5.6 Performance
MySQL Performance Tuning. Part 1: MySQL Configuration (includes MySQL 5.7)
MySQL Performance Tuning: Top 10 Tips
KoprowskiT_SQLRelay2014#1_Reading_FromPlanToBackupToCloud
MySQL 5.6 - Operations and Diagnostics Improvements
DB12c: All You Need to Know About the Resource Manager
KoprowskiT-Difinify2017-SQL_ServerBackup_In_The_Cloud
Always on in sql server 2017
PLSSUG - Troubleshoot SQL Server performance problems like a Microsoft Engineer
Upcoming changes in MySQL 5.7
Drupal commerce performance profiling and tunning using loadstorm experiments...
Collaborate 2019 - How to Understand an AWR Report
SQL Explore 2012: P&T Part 3
My sql performance tuning course
MySQL 5.7 NEW FEATURES, BETTER PERFORMANCE, AND THINGS THAT WILL BREAK -- Mid...
DAC 2012
Ad

Similar to Understanding the Transaction Log, Your Key to Unlocking Greater Throughput (20)

PDF
Technical Modifications to Compress Period End Close - R12.1.3
PDF
Pre and post tips to installing sql server correctly
PDF
More Than Just The Tip Of The Iceberg.pdf
PPTX
Storing and managing your content in share point spsnyc
PDF
Experiences from DevOps production: Deployment, performance, failure.
PPTX
Montée en version de 300 bases de données vers Oracle 12c en 300 jours. Quel...
PPTX
Microsoft sql server architecture
PPTX
Building and configuring sql server; Some Recommended Practices.
PDF
SharePoint Saturday Netherlands 2016 - SharePoint and Office 365 performances...
PPT
Windows 2012 and its functionality, decribe very well in the presentation
PDF
Database Configuration for Maximum SharePoint 2010 Performance
PDF
Backup and Restore SQL Server Databases in Microsoft Azure
PDF
Power Saturday 2019 B6 - SQL Server installation cookbook
PPTX
Datapolis Guest Expert Presentation: Top 15 SharePoint Server Configuration M...
PPTX
Deploying ssd in the data center 2014
PDF
2008 Collaborate IOUG Presentation
PPTX
Monitoring sql server
PDF
SharePoint 2013 SP1 Deployment for OneDrive use – Step by Step [Small]
PPTX
Sage 300 ERP: Environment setup and configuration
PDF
Replication features, technologies and 3rd party Extinction
Technical Modifications to Compress Period End Close - R12.1.3
Pre and post tips to installing sql server correctly
More Than Just The Tip Of The Iceberg.pdf
Storing and managing your content in share point spsnyc
Experiences from DevOps production: Deployment, performance, failure.
Montée en version de 300 bases de données vers Oracle 12c en 300 jours. Quel...
Microsoft sql server architecture
Building and configuring sql server; Some Recommended Practices.
SharePoint Saturday Netherlands 2016 - SharePoint and Office 365 performances...
Windows 2012 and its functionality, decribe very well in the presentation
Database Configuration for Maximum SharePoint 2010 Performance
Backup and Restore SQL Server Databases in Microsoft Azure
Power Saturday 2019 B6 - SQL Server installation cookbook
Datapolis Guest Expert Presentation: Top 15 SharePoint Server Configuration M...
Deploying ssd in the data center 2014
2008 Collaborate IOUG Presentation
Monitoring sql server
SharePoint 2013 SP1 Deployment for OneDrive use – Step by Step [Small]
Sage 300 ERP: Environment setup and configuration
Replication features, technologies and 3rd party Extinction
Ad

Recently uploaded (20)

PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Cloud computing and distributed systems.
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Empathic Computing: Creating Shared Understanding
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Cloud computing and distributed systems.
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Empathic Computing: Creating Shared Understanding
Agricultural_Statistics_at_a_Glance_2022_0.pdf
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
NewMind AI Weekly Chronicles - August'25 Week I
“AI and Expert System Decision Support & Business Intelligence Systems”
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks

Understanding the Transaction Log, Your Key to Unlocking Greater Throughput

  • 1. UNDERSTANDING THE TRANSACTION LOG; YOUR KEY TO UNLOCKING GREATER THROUGHPUT Richard Douglas • Sales Engineer, SQL Sentry • Social Media: @SQLRich, LinkedIn, • Blog Info: http://blogs.sqlsentry.com/author/RichardDouglas/; http://SQL.RichardDouglas.co.uk
  • 2. Tuning blog: http://www.sqlperformance.com/ E-mail ebooks@sqlsentry.com for free copies of our $10 e-books:
  • 3. YOUR HOST • Richard Douglas • Sales Engineer at SQL Sentry • Blog: http://SQL.RichardDouglas.co.uk • Twitter: @SQLRich • Email: RDouglas@SQLSentry.com • Slides: http://www.Slideshare.net/SQLRich
  • 4. AGENDA • When the log is used • Internals • Hardware • Database Architecture • Coding • Monitoring • Wrap Up
  • 5. Logs, that’s all about backups right?
  • 6. SQL Server will use the transaction log for almost every transaction
  • 7. Data File SNI Phase 0 Phase 1 Phase 2 Optimizer Command Parser Query Executor Access Methods Buffer Manager Pre-Opt Execution Plan TDS TDS Query Tree Language Event Plan Cache Buffer Cache Buffer Pool Storage Engine Relational Engine Protocol Layer Results SELECT Statement Buffer Pool Extension
  • 8. Log File Data File SNI Phase 0 Phase 1 Phase 2 Optimizer Command Parser Query Executor Access Methods Buffer Manager Pre-Opt Execution Plan TDS TDS Query Tree Language Event Plan Cache Buffer Cache Buffer PoolStorage Engine Relational Engine Protocol Layer Results Transaction Manager INSERT Statement
  • 9. RECOVERY MODELS • Simple • Full • Bulk Logged Data File Log File SQL Database Automated administration Manual Administration Note: Recovery model will be defaulted to the one in the Model database
  • 10. MINIMALLY LOGGED OPERATIONS • Bulk import operations* – Bcp – Bulk Insert – INSERT / SELECT (External Tools) • SELECT * INTO • .Write in UPDATE statements (new values only) • WRITETEXT and UPDATETEXT (new values only, marked for deprecation) • Some DDL Statements – CREATE INDEX – ALTER INDEX REBUILD / DBCC DBREINDEX (marked for deprecation) – DROP INDEX (Index pages fully logged) • When using Transactional Replication this will be fully logged.
  • 11. TRANSACTION LOG INTERNALS • The Transaction Log is segmented into pieces called Virtual Log Files (VLF’s) • There will always be at least one “active” VLF • Having too many VLF’s is thought to be a bad thing. • How many is too many and how are they calculated? Active VLF Inactive VLF Inactive VLF Inactive VLF Inactive VLF Yes, another 9 sets like this would make 50 shades of grey.
  • 12. CALCULATING VLFS • Pre2014 the numberof VLF’s is determined by the size at creation / growth time. – Under 64MB 4VLF’s – >=64and> 1GB 8 VLF’s – >= 1GB 16 VLF’s • In 2014, if the growth size is less than 1/8 the size of the log Then create1 single VLF at the size of the growth size Else use the pre2014 formula • But wait, there’s more. VLF’s aren’t the smallest segment of the Transaction Log …
  • 13. LOG BLOCKS • Each VLF will have a numberof “Log Blocks” inside it • These blocks varyin size: – Anywherebetween 512bytesand60KB • A new block is createdwhen: – The data insidethe blockhits the 60KB limit – A commitor abortoccurswithin a transaction • Each log block contains a parity bit of 64 or128 which is flipped everytime it is used. • Inside each log block we have…
  • 14. LOG RECORDS • Log records are identified by Log Sequence Numbers or LSN’s – VLF Sequence nbr: Logblock nbr : Logrecordnbr • Each data page contains the LSN of the last recordthat made changes to that page. • Log records are written in the orderthey occur. i.e.SQL Serverwill notwait for a transaction to finish before writing away another concurrent transaction. • Log records often storebefore and after images of changes. • Theycontain a list of pages that this change has affected. • Log records are stored in the buffer pool (log cache)until flushed to disk Look for WAITLOG wait type.
  • 15. CHECKPOINT • Data pages are markedas “dirty” when they are changed. • Thecheckpoint process writes all dirty pages to disk and marksthem as cleared. • Checkpoint is an optimisation process, it reducesthe amount of writes to disk to keepdata up to date.
  • 16. INTERESTING CHECKPOINT TRACE FLAGS • 828 –Checkpoint resumes the behaviour that it exhibited before you installed SQLServer2000 SP3 when you enabletrace flag 828 on a computer that is running SQL Server2000 SP4 - KB906121 • 3031 –In 2005 turns NO_LOG and TRUNCATE_ONLY backups to checkpoints in all recovery modes http://bit.ly/1b7RFNV • 3502 –Writes information about checkpoints tothe errorlog • 3503 –Indicates whether the checkpointat the end of automatic recoverywas skipped for a database. • 3504 –Writes further info about checkpoints to the errorlog • 3505 –Disables automatic checkpoints
  • 17. MAKING STUFF GO FASTER Server / IO Architecture Database Architecture Coding
  • 18. HARDWARE CHOICES • IO Architecture can be a nightmare • Local vs Shared • Specifying drives • RAID Levels o Hardware RAID with large cash cache
  • 19. DATABASE ARCHITECTURE • Get the log size right early on • Consider High Availability Overhead • Only log what you need • Beware of “evil” page splits • Delayed Durability
  • 20. HIGH AVAILABILITY OVERHEAD • Log Shipping • Database Mirroring • AlwaysOn Availability Groups • AlwaysOn Failover Clusters • Replication
  • 21. WATCH YOUR INDICES The following add overhead, beware: • Duplicate indices • Unused indices • Subsets of indices Use the Dynamic Management Object Sys.dm_db_Index_Usage_Stats to find out how useful an index really is.
  • 22. CODING • “Temp Tables vs Table Variable” debate o Blog post - http://bit.ly/1ZmvRtt • “Rollback Gotchas” o Blog post - http://bit.ly/1Z4ZfEm • Batching transactions
  • 23. MONITORING THE LOG • Dynamic Management Objects • Perfmon counters • Wait statistics • Reading the log! Sys.dm_io_virtual_file_stats Lots of Log based counters in SQLServer:Databases LogBuffer and WriteLog are common
  • 25. VLF RESULTS High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 Update 02 Log Backup 02 Update 03 Log Backup 03 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 Log Backup 02 Update 03 Log Backup 03 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 219 209 25 27 204 210 24 25 27 Log Backup 02 Update 03 Log Backup 03 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 219 209 25 27 204 210 24 25 27 Log Backup 02 237 217 21 16 231 219 18 14 15 Update 03 Log Backup 03 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 219 209 25 27 204 210 24 25 27 Log Backup 02 237 217 21 16 231 219 18 14 15 Update 03 216 210 25 27 205 211 27 29 27 Log Backup 03 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 219 209 25 27 204 210 24 25 27 Log Backup 02 237 217 21 16 231 219 18 14 15 Update 03 216 210 25 27 205 211 27 29 27 Log Backup 03 239 217 21 15 231 219 17 15 15 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 219 209 25 27 204 210 24 25 27 Log Backup 02 237 217 21 16 231 219 18 14 15 Update 03 216 210 25 27 205 211 27 29 27 Log Backup 03 239 217 21 15 231 219 17 15 15 Backup Full 0 1 1 0 0 0 0 0 0 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Update 01 1673 516 222 54 1479 517 168 50 36 Log Backup 01 247 217 22 15 234 219 18 15 15 Update 02 219 209 25 27 204 210 24 25 27 Log Backup 02 237 217 21 16 231 219 18 14 15 Update 03 216 210 25 27 205 211 27 29 27 Log Backup 03 239 217 21 15 231 219 17 15 15 Backup Full 0 1 1 0 0 0 0 0 0 Totals 2831 1587 337 154 2584 1595 272 148 135 0 200 400 600 800 1000 1200 1400 1600 1800 Update 01 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD 0 50 100 150 200 250 300 Update 01 Log Backup 01 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD Some outliers have been removed to improve readability 0 50 100 150 200 250 300 Update 01 Log Backup 01 Update 02 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD 0 50 100 150 200 250 300 Update 01 Log Backup 01 Update 02 Log Backup 02 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD 0 50 100 150 200 250 300 Update 01 Log Backup 01 Update 02 Log Backup 02 Update 03 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD 0 50 100 150 200 250 300 Update 01 Log Backup 01 Update 02 Log Backup 02 Update 03 Log Backup 03 High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD 0 50 100 150 200 250 300 Update 01 Log Backup 01 Update 02 Log Backup 02 Update 03 Log Backup 03 Backup Full High - 2012 External Low - 2012 External High - 2012 SSD Low - 2012 SSD High - 2014 External Low - 2014 External High - 2014 SSD Low - 2014 SSD Optimal - 2014 SSD
  • 26. 2014 HIGH VLF WAITS 39 58 Update 02 LOGBUFFER QDS_SHUTDOWN_QUEUE 46 52 Update 03 LOGBUFFER QDS_SHUTDOWN_QUEUE 7 10 4 20 7 49 Update 01 LATCH_EX LCK_M_U PREEMPTIVE_OS_FILEOPS PREEMPTIVE_OS_FLUSHFILEBUFFERS PREEMPTIVE_OS_WRITEFILEGATHER QDS_SHUTDOWN_QUEUE
  • 27. THANK YOU! • Slides will be available at http://Slideshare.net/SQLRich • More information at: o SQLSkills, et al • E-mail ebooks@sqlsentry.com for free copies of our e-books: o Just tell them where you met me • My contact info for other questions: o RDouglas@SQLSentry.com o Twitter: @SQLRich o Blogs: http://SQL.RichardDouglas.co.uk / http://http://blogs.sqlsentry.com/author/RichardDouglas