Professional Documents
Culture Documents
--Srikanth
What is Transaction Log File
About TLF, Architecture, Properties
Operations Supported by TLF
Logical Log File
Virtual Log File – States, Terms in VLF
Must be – uncorrupted
Initial Size - Based on Model DB. Min and default is 1MB, can give > value in Model DB.
Max Size – Based on Model DB. Default is unlimited (but limited to 2097152MB).
Rolling a restored database, file, file group, or page forward to point of failure
After hardware loss or hard disk failure affecting database fails.
Transaction Replication
Log Reader Agent monitors the transaction log and copies the transactions marked for
replication from transaction into distribution database.
Standby-Server Solutions
Database mirroring, Log Shipping.
“ It is internal division of Transaction log comprised of 1 or
more log blocks ”
• Has no fixed size.
• Cannot configure size and number of virtual log files.
• Too many VLF’s can slow down database startup and also log backup and restore
operations.
Active State
• Log records are currently using by Database engine.
• Records may be a part of active transactions, replication, mirroring , or log shipping.
• Log may be a part of transaction which is already completed but not yet written back to data file.
Inactive State
• Log whose records are written back to data file and also not using by Database Engine.
• Records may be not part of active transaction, replication, mirroring, or log shipping.
• When ever log backed up is full and bulk logged recovery model, VLF becomes inactive.
“ It is an active part of transaction part “
Log block Number – 4bytes, 10 digital decimal number with leading zeros.
Log Record Number – 2bytes, 5 digital decimal number with leading zeros.
“Each block size is integral multiple of 512 bytes, but not more than 64KB total in size”
Log Record
It is smallest unit within TLF that contains information recorded for activity within
database.
Truncated VLF
Space occupied by VLF for reuse.
Check point
-- To see how many VLF’s are existing and LSN numbers – “ dbcc loginfo ” --
“ Database cannot work if there is no transaction log; due to SQL Server Design and ACID
properties compliance ”
All Transactions must full fill these characteristics:
Atomicity -
Transaction must be either fully completed or not begun at all.
Consistency -
Ensuring that the start or end of any transaction the system is in valid state.
Isolation -
It appears to be the only action that the system is carrying out at a time. No issues in
concurrent access.
Durability –
Means it has been successfully completed, all the changes it made to the system are
permanent. Recoverability of data even after crash.
“ In Disaster Recovery , Database Restore, Transaction Replication, Standby-Server
Solutions”
Recovery Models:-
Simple – Transaction log backups are not supported, data loss risk, truncation process is automatic,
space is reclaimed for reuse.
Bulk-logged – TL backups are supported and needed on regular basis, No automated truncation,
reduces transaction log space usage.
Fully - TL backups are supported and needed on regular basis, No automated truncation, biggest
chance of transaction log growing because all transactions are logged.
Do we need SSTL backup ?
Ans: YES !
Backup is not needed only when using simple recovery model – but there is data loss
exposure
Majority of DBA’s uses 15 min’s interval or even less for high traffic SSDB.
“ Database Properties Files “
To see ‘ Current size allocated Transaction Log ‘ and ‘ Log space used ’ by all databases
of instance.
“ dbcc sqlperf(logspace) ”
Particular Database -
Ans: YES !
But recommended only in specific situations.
NOTE:
2. Adding multiple log files will not improve performance in fact llel
I/O operations are not possible.
“ It is important task of SS Admin to maintain the space of TLF ”
Monitoring is recommended on daily basis or even more often if
there is high traffic in SSDB.
Log size: current size allocated to the log. Always smaller than original
bcz.. SSDE reserves small space for internal header information
If all are full with active transaction it will grow further to create more VLF
IF it cannot it will through an error – 9002 saying TL for DB is full and Transaction will fail
Begin tran
When more transactions are created, the active portion of log will grow.
Check
Active log / Logical log
Point
Changes made by transaction 1, 2, 3 have been written to the data file.
Active portion of the log now spans from LSN 56 to 58, bcz.. Trn 3 has not
been committed.
The truncated VLF’s can only be deleted and space is reused when
the TL is backed - up
VLF 1 VLF 2 VLF 3 VLF 4
LSN LSN 57 LSN 58
56 Trn 2 Check
Trn 3 Commi point
begin t
Or
If the end of logical log reaches the end of physical log the new record
will wrap around the start of logical log.
If the end of logical log meets start of logical log, means log is full
and error no: 9002 will be thrown.
Lazy Writer
Checkpoint
Dirty Page
Transaction Log
Full Recovery
Simple RecoveryMode
Mode
Data file
References from:
SS HELP Document.
A beginner’s guide to SQL Server transaction logs – Ivan Stankovic
SQLBackupRestore.com – YOHZ Software
Transaction Log Performance Tunning (PPT ) –Chirag Roy (COEO-sr.DBA)
--Srikanth