| Auto-Truncate Log in Full Recovery Model |
|
|
|
| SQL Server - Articles | ||||||||
| Written by Sarabpreet Singh | ||||||||
|
FULL Recovery model: This means that all database changes are fully logged and ideally the log records should stay in the log file until the log records are safely stored away\backed up in a Transaction Log backup. But unfortunately this is not completely correct. Your database can be in auto-truncate mode while the recovery model is set to FULL. This document will help you know how to avoid such pitfalls and make your database fully recoverable. When the database is in auto-truncate mode, the log file will be truncated every time a CHECKPOINT is run against the database. CHECKPOINT happens at regular intervals. Log Truncation means that inactive parts of the log file will be overwritten if the log space is needed. Log Truncation does not physically shrink the log file, but it can keep it from physically growing.
There are four ways to enable auto-truncate mode:
You should also be aware that taking a log backup will truncate the log, but taking a FULL database backup will not truncate the log. (I received many calls from DBA’s asking this specific question) Now how to check whether your database is in auto-truncate mode or not? You can query an undocumented system view called sys.database_recovery_status. If the value of last_log_backup_lsn column of this view is NULL it means the database is not maintaining a sequence of log backups and it is in auto-truncate mode: Note: To see the row for a database other than master or tempdb, you should have one of the following permission:
SELECT @@servername,db_name(database_id) as 'database', last_log_backup_lsn FROM sys.database_recovery_status(nolock)
. . To replicate the same and test following is the step by step script.
CREATE DATABASE sarab_12 GO -- Check the status of auto-truncate option after first creating Database SELECT db_name(database_id) as 'database', last_log_backup_lsn FROM sys.database_recovery_status WHERE database_id = db_id('sarab_12') GO --Now take a full backup of sarab_12 Database BACKUP DATABASE sarab_12 TO disk = 'C:\sarab_12.bak' GO -- Check status of auto-truncate option after taking full backing up of sarab_12 Database SELECT db_name(database_id) AS 'database', last_log_backup_lsn FROM sys.database_recovery_status WHERE database_id = db_id('sarab_12') GO --Try to truncate the inactive portion of sarab_12 database without taking backup of the same BACKUP LOG sarab_12 WITH TRUNCATE_ONLY GO -- Check status of auto-truncate option after truncating log SELECT db_name(database_id) AS 'database', last_log_backup_lsn FROM sys.database_recovery_status WHERE database_id = db_id('sarab_12') GO --Clean your instance DROP DATABASE sarab_12 GO
APPLIES TO MS SQL Server 2005
Regards, Sarabpreet Singh
Only registered users can write comments!
Powered by !JoomlaComment 3.26
3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."
|





