Fix SQL Server Error 9002 in 5 Ways
SQL Server error 9002 says that the transaction log of a database is full. Microsoft states that an online database stays online but accepts no modifications while the log is full.
Five ways follow. Check the wait reason in sys.databases first because the wait reason decides the fix.
Quick SummarySQL Server error 9002 means the transaction log is full. Check log_reuse_wait_desc to see why the engine cannot reuse the log space. Take two log backups when no log backup exists yet. Clear the blocker when the reason is an open transaction or a replication backlog. Free disk space or move the log file when the volume is full. Add a temporary log file or raise the size limit when no other fix applies.
What Does Error 9002 Say About Your Log?
Error 9002 names the database and the reason after the words due to.
Msg 9002, Level 17, State 2, Line 1
The transaction log for database 'SalesDB' is full due to 'LOG_BACKUP'.
The reason in the message matches a value of log_reuse_wait_desc in sys.databases. LOG_BACKUP in the example means that the engine waits for a log backup before it reuses the log space.
Microsoft documents the fix for a full transaction log with a list of causes. The log fills because log backups stopped, a transaction stayed open, replication or an availability group fell behind or the volume ran out of space.
How to Find Out Why the Log Is Full?
Query sys.databases for the wait reason and sys.dm_db_log_space_usage for the log size and the used space. Query sys.database_files for the size limit and the growth setting.
SELECT name, recovery_model_desc, log_reuse_wait_desc
FROM sys.databases
WHERE name = N'SalesDB';
USE SalesDB;
SELECT total_log_size_in_bytes / 1048576 AS total_mb,
used_log_space_in_bytes / 1048576 AS used_mb,
used_log_space_in_percent
FROM sys.dm_db_log_space_usage;
SELECT name, physical_name, size / 128 AS size_mb, max_size, growth
FROM sys.database_files
WHERE type_desc = N'LOG';
A max_size of -1 means the file grows until the disk is full. A growth of 0 means autogrow is off and the file never grows.
Which Fix Matches Your Wait Reason?
Match the value of log_reuse_wait_desc to the table.
| log_reuse_wait_desc | What it means | Start with |
|---|---|---|
| LOG_BACKUP | The engine waits for a log backup | Method 1 |
| ACTIVE_TRANSACTION | A long or open transaction pins the log | Method 2 |
| ACTIVE_BACKUP_OR_RESTORE | A data backup or a restore is in progress | Wait for the task or cancel it |
| REPLICATION | Replicated transactions are not delivered yet | Method 2 |
| AVAILABILITY_REPLICA | A secondary replica has not applied the log records | Method 2 |
| DATABASE_MIRRORING | Mirroring is paused or far behind | Method 2 |
| CHECKPOINT | No checkpoint happened since the last truncation | Method 2 |
| NOTHING | No blocker exists and the log has no room to grow | Methods 3 to 5 |
Do You Know?Microsoft lists version limits for some values. AVAILABILITY_REPLICA needs SQL Server 2012 or later. XTP_CHECKPOINT needs SQL Server 2014 or later. SLOG_SCAN appears on SQL Server 2019 and later when Accelerated Database Recovery is on.
How to Fix SQL Server Error 9002?
Every example uses the database SalesDB. Replace the names and the paths with your own values.
Method 1: Take a Log Backup
Use this method when the reason is LOG_BACKUP. The engine truncates the log during a log backup and reuses the freed space.
BACKUP LOG [SalesDB]
TO DISK = N'D:\Backup\SalesDB_log1.trn';
BACKUP LOG [SalesDB]
TO DISK = N'D:\Backup\SalesDB_log2.trn';
Microsoft states that a log that has no log backup yet needs two log backups before the log truncates. Store the files on a different volume from the log. Review the recovery models in SQL Server before you modify a recovery model.
Heads UpSIMPLE recovery stops log backups and ends the point in time restore. Microsoft names the log backup and the blocker as the fixes for error 9002 and does not name SIMPLE recovery.
Method 2: Clear the Blocker
Use this method when the reason is an open transaction, replication, an availability group or a checkpoint. Find the oldest open transaction first.
USE SalesDB;
DBCC OPENTRAN;
CHECKPOINT;
SELECT *
FROM sys.dm_db_log_info(DB_ID(N'SalesDB'));
DBCC OPENTRAN names the oldest transaction and its session ID. Commit it or roll it back in the application. Microsoft advises extreme caution with the KILL command and the rollback time depends on the work the transaction did.
Check the replication agents or the availability group health for the other reasons. The log truncates after the delivery or the log apply catches up.
Method 3: Free Disk Space or Move the Log File
Use this method when the log volume has no free space. Delete old backups and files on that volume or move the log to a larger volume.
ALTER DATABASE SalesDB SET OFFLINE;
-- Move SalesDB_log.ldf to G:\Log in Windows
ALTER DATABASE SalesDB
MODIFY FILE (NAME = N'SalesDB_log', FILENAME = N'G:\Log\SalesDB_log.ldf');
ALTER DATABASE SalesDB SET ONLINE;
Microsoft documents the offline and online order for a moved file. Never place a log file on a compressed file system.
Method 4: Add a Temporary Log File on Another Volume
Use this method when the log volume cannot grow and a second volume has space. The extra file is a temporary measure.
ALTER DATABASE SalesDB
ADD LOG FILE (NAME = N'SalesDB_log2',
FILENAME = N'H:\Log\SalesDB_log2.ldf',
SIZE = 1024MB,
FILEGROWTH = 256MB);
Remove the extra file after the log truncates and the file is empty. Microsoft states that REMOVE FILE works only on an empty file.
ALTER DATABASE SalesDB REMOVE FILE SalesDB_log2;
Method 5: Raise the Size Limit and Enable Autogrow
Use this method when sys.database_files shows a growth of 0 or a max_size that the log reached. Set a size that matches your busiest hours and the time between two log backups.
ALTER DATABASE SalesDB
MODIFY FILE (NAME = N'SalesDB_log',
SIZE = 8192MB,
MAXSIZE = 65536MB,
FILEGROWTH = 512MB);
Microsoft states that FILEGROWTH cannot exceed MAXSIZE and that a log file reaches at most 2 TB. MAXSIZE with the value UNLIMITED means the log can fill the disk so set a fixed cap. Database autogrowth in SQL Server explains the growth settings.
Heads UpA shrink does not fix a full log. Microsoft states that a shrink reclaims only empty space. Deleting the LDF file after a crash makes the problem worse, so follow SQL Server LDF recovery when the file is already gone.
Common Questions on Error 9002
Does Error 9002 Mean the Disk Is Full?
Not always. The log is full when the engine cannot reuse the log space or cannot grow the file. Check log_reuse_wait_desc first because the value names the reason.
Does Shrinking the Log File Fix Error 9002?
No. Microsoft states that a shrink reclaims only empty space and cannot fix a full log whose records cannot be truncated.
Should You Switch to SIMPLE Recovery to Stop the Error?
Microsoft lists the log backup and the blocker as the fixes and does not list SIMPLE recovery. SIMPLE recovery stops log backups, so the point in time restore ends. Decide with your recovery point goal and never as a quick fix.
How Many Log Backups Does a Database Need Before the Log Truncates?
Microsoft states that a log that has no log backup yet needs two log backups. The first backup starts the chain and the next backup truncates.
How Do You Bring a Database Online After Error 9002 During Recovery?
Free the log space with Method 3, 4 or 5 and then execute ALTER DATABASE with SET ONLINE. Microsoft documents this step for a database that was in recovery when the error appeared.
Can You Add a Second Log File?
Yes as a temporary measure on a different volume. Microsoft states that most databases need only one log file and that the extra file is not a long term fix.
How to Stop Error 9002 From Coming Back?
Schedule log backups on every database in the full recovery model and alert on a log that passes 80 percent of its size. Check log_reuse_wait_desc when an alert fires.
Size the log once and set a fixed autogrow step. SQL Server error 9001 shows what the engine reports when the log becomes unavailable and the purpose of the transaction log explains why the log needs backups.
Who, How and WhyAndrew Jackson, Technical Content Specialist, wrote this guide. The causes, the fixes, the two log backup rule and the warnings follow the Microsoft Learn page for error 9002. The wait reason values and the version notes follow the Microsoft page for sys.databases. The file options follow the Microsoft ALTER DATABASE file options page. The T-SQL was checked for syntax against Microsoft documentation and was not executed on a live server. The message text of error 9002 comes from public reports because the Microsoft page does not quote it. The guide exists because error 9002 looks like a disk problem and the wait reason shows a different cause in most cases.
Key Takeaways
- SQL Server error 9002 means the engine cannot reuse or grow the transaction log.
- The value of log_reuse_wait_desc names the reason and decides the fix.
- A log that has no log backup yet needs two log backups before it truncates.
- A shrink cannot fix a full log because a shrink reclaims only empty space.
- SIMPLE recovery stops log backups so never use it as a quick fix.
- Set a fixed MAXSIZE and a growth step so the log never fills the disk.