Академический Документы
Профессиональный Документы
Культура Документы
Log Internals
Denzil Ribeiro
About me
Denzil Ribeiro
Sr. Dedicated Premier Field Engineer at Microsoft
Prior Escalation Engineer @ CTS
SQL PFE Blog
Session Assumptions & Considerations
Record 3
Log Records
Log Record Header Page Log Structure Row Log Structure Variable Log Data
Optional Optional Optional
For Update of Rows
<= 64MB 4
> 1 GB 16
How many VLFs do you need?
• It Depends!
• Too many can lengthen database restore time
• Too few may make it difficult to truncate the log
• We now alert in SQL 2012 if you have too many!
VLF Reuse
• A VLF can be reused if:
o No active transactions are contained in the VLF or previous VLFs
o No “un-replicated” transactions are contained in the VLF
Current Buffer
Current Buffer
Transaction Log Limits
• Size
o SQL 2012/SQL 2008 - limit 3840K
o SQL 2005 - limit of 480K at any given time
• Number of Outstanding IOs
o SQL 2012 – 112 outstanding IO’s ( 64 bit)
o Prior - 32 outstanding IO ( 64 bit), 8 on 32 bit
• Once Limits hit, we will wait for outstanding IO to
complete before issuing any new IO.
o Will wait on LOGMGR_FLUSH
Example Limits ( SQL 2008)
• Size Limit : 3840K
• (9.6MB Log Bytes Flushed/sec)/(5000 Log Flushes/sec) = 1.9K per flush
• (32 Outstanding I/O’s)*(1.9K per Flush) = ~60K “in-flight” at any given time (far
below the 3840K limit)
Log Wait Types
• Waiting on IO to Log file, disk • Waiting on a free log buffer, all • Tried to grow the log file but
can’t keep up or a slow disk log buffers in use, most often couldn’t, waiting on log
• Check Log disk counters due to them not being flushed truncation. Check
• Check sys.dm_io_pending_ios fast enough. sys.databases
log_reuse_wait_desc
Demo
Log Flushing
Delayed Durability (SQL 2014)
ALTER DATABASE SET DELAYED_DURABILITY
={DISABLED|ALLOWED|FORCED}
• Disabled – Normal behavior durability guaranteed.
• Allowed – Allowed at the DB Level, Transaction has to specify durability
options, default is a durable transaction.
• COMMIT TRAN……. WITH (DELAYED_DURABILITY=ON)
• FORCED – Changes default durability for the DB to “delayed”. Can be useful
for Applications bottlenecked on Log IO, that can tolerate some Data loss on a
failure.
Minimal Logging
Checkpoint Logging
Phases of Recovery
• Read the log and find • Replays all committed • Rolls back active
active transactions but un-reflected transactions
and dirty pages transactions • Starts at oldest active
• Usually starts at last • Database is available transaction
checkpoint in Enterprise Edition
• Finds where to start at this point
the Redo process
Demo
Database Recovery
Why is my log file getting so big?
• Very common problem with customers
• Adding a log file on another drive is sometimes needed
• Use log_reuse_wait_desc field in sys.databases for more info
log_reuse_wait_desc
Nothing Database Mirroring
Resolution: Checkpoint Replication