Professional Documents
Culture Documents
NOTHING
Error 9002 - the transaction log full error Currently there are one or more reusable virtual log files
and the database becomes read-only
CHECKPOINT
No checkpoint has occurred since the last log truncation, or the head of the log has not yet moved beyond a virtual log file (all recovery models)
LOG_BACKUP
/* 01. Check Log Space Usage */
A log backup is required to move the head of the log forward (full or bulk-logged recovery models only)
DBCC SQLPERF(LOGSPACE);
ACTIVE_BACKUP_OR_RESTORE
A data backup or a restore is in progress (all recovery models)
/* 02. Find the current reason why log space cannot be reused. */ ACTIVE_TRANSACTION
-- Query sys.databases again and again to examine the value of the log_reuse_wait_desc column A long-running transaction might exist at the start of the log backup/A transaction is deferred
DECLARE @DatabaseName VARCHAR(50); (A long-running or uncommitted transaction is preventing truncation of log and so space reuse)
SET @DatabaseName = 'DatabaseName'
DATABASE_MIRRORING
SELECT NAME, recovery_model_desc, log_reuse_wait_desc Database mirroring is paused, or under high-performance mode, the mirror database is significantly behind the principal database (full recovery model only)
FROM sys.databases
WHERE NAME = @DatabaseName; REPLICATION
During transactional replications, transactions relevant to the publications are still undelivered to the distribution database (full recovery model only)
DATABASE_SNAPSHOT_CREATION
A database snapshot is being created (all recovery models)
log_reuse_wait_desc
LOG_SCAN
= Log Backup ?
NO A log scan is occurring (all recovery models)
YES
/* 03. List information about the oldest open transaction in the database */ OTHER_TRANSIENT
DBCC TRACEON(3604) /* 05. Check if log backups are being taken on the database, and when the last one was taken. */ This value is currently not used
GO -- Determine when the last log backup was taken
USE msdb;
DBCC OPENTRAN; GO
GO
DECLARE @DatabaseName VARCHAR(50); The type of backupset
DBCC TRACEOFF(3604) SET @DatabaseName = 'DatabaseName'
The mode of backup GO
SELECT backup_set_id, backup_start_date, backup_finish_date, backup_size, recovery_model, [type] D - a database backup
FROM dbo.backupset L - a log backup
Simple: WHERE database_name = @DatabaseName; I - a differential backup
All transactions are written to the log. After a checkpoint, all committed transactions are
/* 04. Obtain the information to investigate log growth caused by active transactions */
automatically removed from the log, also known as truncating the log.
SELECT host_name, program_name , original_login_name, st.TEXT
No point-in-time recovery is possible.
FROM sys.dm_exec_sessions es INNER JOIN sys.dm_exec_connections ec
ON es.session_id = ec.session_id
Bulk-logged:
CROSS APPLY sys.dm_exec_sql_text(ec.most_recent_sql_handle) st Available disk space >
All transactions are written to the log except certain types of minimally logged operations
WHERE ec.session_id = SPID; Transaction log ?
such as BULK INSERT and INSERT INTO.
NO
The log can only be truncated with a log backup operation.
YES
Point-in-time recovery is possible as long as no minimally logged operations are in any of the
required log backups.
Available disk space
Full: All transactions are written to the log. The log can only be truncated with a log backup > Database file ?
operation. NO YES /* 06. Execute a transaction log backup */
Point-in-time recovery is possible. USE [DatabaseName];
GO
The database IS in
an Availability Group
/ a Database Mirror ?
NO YES
2
/* 10.a Shrink log file back to its initial size or an appropriate size */ /* 09.b Check Log Space Usage */
USE [master]; DBCC LogInfo
GO
-- Check if the value of auto_update_statistics_async in sys.databases off (default) to set
--SELECT auto_update_statistics_async FROM sys.databases;
--ALTER DATABASE DatabaseName SET AUTO_UPDATE_STATISTICS_ASYNC OFF;
ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO Status = ?
ALTER DATABASE DatabaseName SET RECOVERY SIMPLE;
0 2
NO GO
USE [DatabaseName]; /* 10.c Shrink log file back to its initial size or an appropriate size */ /* 10.b Shrink log file back to empty file */
GO --sp_helpfile --sp_helpfile
-- Shrink the log file to smallest possible size DBCC SHRINKFILE (N'LogFileName', target_size=0); DBCC SHRINKFILE (N'LogFileName', EMPTYFILE);
--sp_helpfile GO GO
DBCC SHRINKFILE (N'LogFileName', target_size=0);
GO 0
-- Resize the log file to a sensible size as well as minimize fragmentation of the log file
ALTER DATABASE [DatabaseName]
MODIFY FILE (NAME='LogFileName',SIZE='SizeMB',MAXSIZE=UNLIMITED,FILEGROWTH='GrowthSizeMB'); /* 11. Determine how much of the log file is in use */
GO USE [DatabaseName]; Status = ?
GO
USE [master];
GO SELECT name, size/128.0 AS SpaceInMB, (size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0) AS AvailableSpaceInMB
ALTER DATABASE DatabaseName SET RECOVERY FULL; FROM sys.database_files;
GO
ALTER DATABASE DatabaseName SET MULTI_USER WITH ROLLBACK IMMEDIATE;
GO
End