Transaction Log(T-Log) Architecture
Transaction Log(T-Log) Architecture
SQL Server Uses LSN (Log Sequential Number) for identifying the transaction. Each and every transaction
that comes to log file will associated with LSN number. Roll forward and Rollback operations will be
done internally using these LSN numbers only.
WAL (Write A Head Log): Before commit data in mdf, every transaction should write a entry in log file is
called WAL. Transactions never comes to MDF directly.
Active Log Portion: When user performs transactions it will have 3 states
All these state 3 transactions will be in active portion of log file. When check point runs committed
transactions make a copy in inactive portion and moves to mdf.
In-active Log:
Inactive potion:
This portion only used for taking the backup of log. Whenever we take log backup it copies the inactive
portion and truncates the inactive portion log.
Full backup takes the backup of mdf and active portion of the log.
This portion we call as virtual log. SQL Server does not use these records that’s y it calls as inactive
virtual logs.
Inactive portion further divided into more virtual logs. We have a property called log reusability. Log
backups copy the inactive portion to a file and truncates the log data. Same space can be used multiple
times called log reusability concept.
Transaction log is a cyclic process of writing log records into virtual logs file by SQL server. Whenever
one virtual log is filled up it will go to next virtual log. If all virtual logs files are filled up the inactive
portion will grow further and creates more virtual logs till, we have space allocated. If it can’t grow
further, it will throw an error “Transaction log for database is full and transaction will fail”
The only way to clear the inactive virtual log is to take the log backup it truncates logs. After truncation
this space will be released. Backup will not actively portion.
Advantages of T-Log:
Checkpoint occurs automatically based on workload or by a certain operation internally. We can set SQL
server level recovery interval to run checkpoint by using sp_configure or manually issue a checkpoint
using checkpoint T-SQL Command.