Article ID: 317375 - Last Review: March 27, 2008 - Revision: 6.3 A transaction log grows unexpectedly or becomes full on a computer that is running SQL ServerThis article was previously published under Q317375 On This PageSUMMARY In SQL Server 7.0, in SQL Server 2000, and in SQL Server
2005, with the autogrow setting, transaction log files can expand
automatically. Typically, the size of the transaction log file stabilizes when it can hold the maximum number of transactions that can occur between transaction log truncations that either checkpoints or transaction log backups trigger. However, in some situations the transaction log may become very large and run out of space or become full. Typically, you receive the following error message when a transaction log file takes up the available disk space and cannot expand any more: Error: 9002,
Severity: 17, State: 2 The log file for database '%.*ls' is full. Error: 9002, Severity: 17,
State: 2 The transaction log for database '%.*ls' is full. To find out why space in the log cannot be reused, see the log_reuse_wait_desc column in sys.databases Additionally, transaction log expansion may result in the following situations:
CausesTransaction log expansion may occur because of the following reasons or scenarios:
Uncommitted transactionsExplicit transactions remain uncommitted if you do not issue an explicit COMMIT or ROLLBACK command. This most frequently occurs when an application issues a CANCEL or a Transact SQL KILL command without a corresponding ROLLBACK command. The transaction cancellation occurs, but it does not roll back; therefore, SQL Server cannot truncate every transaction that occurs after this because the aborted transaction is still open. You can use the DBCC OPENTRAN Transact-SQL reference to verify if there is an active transaction in a database at a particular time. For more information about this particular scenario, click the following article numbers to view the articles in the Microsoft Knowledge Base:295108
(http://support.microsoft.com/kb/295108/
)
Incomplete transaction may hold large number of locks and case blocking
171224
(http://support.microsoft.com/kb/171224/
)
Understanding how the Transact-SQL KILL command works
Additionally, see the "DBCC OPENTRAN" topic in SQL
Server Books Online.Scenarios that may result in uncommitted transactions:
Extremely large transactionsLog records in the transaction log files are truncated on a transaction-by-transaction basis. If the transaction scope is large, that transaction and any transactions started after it are not removed from the transaction log unless it completes. This can result in large log files. If the transaction is large enough, the log file might use up the available disk space and cause the "transaction log full" type of error message such as Error 9002. For additional information about what to do when you receive this type of error message is provided in the "More Information" section in this article. Additionally, it takes a lot of time and SQL Server overhead to roll back large transactions.Operations: DBCC DBREINDEX and CREATE INDEXBecause of the changes in the recovery model in SQL Server 2000, when you use the Full recovery mode and you run DBCC DBREINDEX, the transaction log may expand significantly more compared to that of SQL Server 7.0 in an equivalent recovery mode with the use of SELECT INTO or BULK COPY and with "Trunc. Log on chkpt." off.Although the size of the transaction log after the DBREINDEX operation might be an issue, this approach provides better log restore performance. While restoring from transaction log backupsThis is described in the following Microsoft Knowledge Base article:232196
(http://support.microsoft.com/kb/232196/
)
Log space used appears to grow after restoring from backup
If you set SQL Server 2000 to use Bulk-Logged mode and you issue a BULK COPY or SELECT INTO statement, every changed extent is marked and then backed up when you back up the transaction log. Although this permits you to back up transaction logs and recover from failures even after you perform bulk operations, this adds to the size of the transaction logs. SQL Server 7.0 does not include this feature. SQL Server 7.0 only records which extents are changed, but it does not record the actual extents. Therefore, the logging takes up significantly more space in SQL Server 2000 than in SQL Server 7.0 in Bulk-Log mode but not as much as it does in Full mode. Client applications do not process all resultsIf you issue a query to SQL Server and you do not handle the results immediately, you may be holding locks and reducing concurrency on your server.For example, suppose you issue a query that requires rows from two pages to populate your result set. SQL Server parses, compiles, and runs the query. This means that shared locks are placed on the two pages that contain the rows that you must have to satisfy your query. Additionally, suppose that not all rows fit onto one SQL Server TDS packet (the method by which the server communicates with the client). TDS packets are filled and sent to the client. If all rows from the first page fit on the TDS packet, SQL Server releases the shared lock on that page but leaves a shared lock on the second page. SQL Server then waits for the client to request more data (you can do this by using DBNEXTROW/DBRESULTS, SQLNextRow/SQLResults, or FetchLast/FetchFirst for example). This means that the shared lock is held until the client requests the rest of the data. Other processes that request data from the second page may be blocked. Queries time out before a transaction log completes the expansion and you receive false 'Log full' error messagesIn this situation, although there is enough disk space, you still receive an "out of space" error message.This situation varies for SQL Server 7.0 and SQL Server 2000. A query can cause the transaction log to automatically expand if the transaction log is almost full. This may take additional time, and a query may be stopped or may exceed its time-out period because of this. SQL Server 7.0 returns error 9002 in this situation. This issue does not apply to SQL Server 2000. In SQL Server 2000, if you have the auto-shrink option turned on for a database, there is an extremely small time during which a transaction log tries to automatically expand, but it cannot because the auto-shrink function is running simultaneously. This may also cause false instances of error 9002. Typically, the automatic expansion of transaction log files occurs quickly. However, in the following situations, it may take longer than usual:
Unreplicated transactionsThe transaction log size of the publisher database can expand if you are using replication. Transactions that affect the objects that are replicated are marked as "For Replication." These transactions, such as uncommitted transactions, are not deleted after checkpoint or after you back up the transaction log until the log-reader task copies the transactions to the distribution database and unmarks them. If an issue with the log-reader task prevents it from reading these transactions in the publisher database, the size of the transaction log may continue to expand as the number of non-replicated transactions increases. You can use the DBCC OPENTRAN Transact-SQL reference to identify the oldest non-replicated transaction.For more information about troubleshooting unreplicated transactions, see the "sp_replcounters" and "sp_repldone" topics in SQL Server Books Online. For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base: 306769
(http://support.microsoft.com/kb/306769/
)
FIX: Transaction log of snapshot published database cannot be truncated
240039
(http://support.microsoft.com/kb/240039/
)
FIX: DBCC OPENTRAN does not report replication information
198514
(http://support.microsoft.com/kb/198514/
)
FIX: Restore to new server causes transactions to remain in log
MORE INFORMATION The transaction log for any database is managed as a set of
virtual log files (VLFs) whose size SQL Server determines internally based on
the total size of the log file and the growth increment in use when the log
expands. A log always expands in units of whole VLFs and it can only compress
to a VLF boundary. A VLF can exist in one of three states: ACTIVE, RECOVERABLE,
and REUSABLE.
For additional information, see the "Transaction Log Physical Architecture" topic in SQL Server Books Online. Additionally, you can see an excellent diagram and discussion of this on page 190 of "Inside SQL Server 7.0" (Soukup, Ron. Inside Microsoft SQL Server 7.0, Microsoft Press, 1999), and also in pages 182 through 186 of "Inside SQL Server 2000" (Delaney, Kalen. Inside Microsoft SQL Server 2000, Microsoft Press, 2000). SQL Server 7.0 and SQL Server 2000 databases have the options to autogrow and autoshrink. You can use these options to help you to compress or expand your transaction log. For more information about how these options can affect your server, click the following article number to view the article in the Microsoft Knowledge Base: 315512
(http://support.microsoft.com/kb/315512/
)
Considerations for Autogrow and Autoshrink configuration in SQL Server
There is a difference between the truncation versus
the compression of the transaction log file. When SQL Server truncates a
transaction log file, this means that the contents of that file (for example,
the committed transactions) are deleted. However, when you are viewing the size
of the file from a disk space perspective (for example, in Windows Explorer or
by using the dir command) the size remains unchanged. However, the space inside
the .ldf file can now be reused by new transactions. Only when SQL Server
shrinks the size of the transaction log file, do you actually see a change in
the physical size of the log file.For more information about how to shrink transaction logs, click the following article numbers to view the articles in the Microsoft Knowledge Base: 256650
(http://support.microsoft.com/kb/256650/
)
How to shrink the SQL Server 7.0 transaction log
272318
(http://support.microsoft.com/kb/272318/
)
Shrinking the transaction log in SQL Server 2000 with DBCC SHRINKFILE
For more information about SQL Server 6.5 transaction log
usage, click the following article number to view the article in the Microsoft Knowledge Base:
110139
(http://support.microsoft.com/kb/110139/
)
Causes of SQL transaction log filling up
How to locate queries that consume a large amount of log space in SQL Server 2005In SQL Server 2005, you can use the sys.dm_tran_database_transactions dynamic management view (DMV) to locate queries that consume large amounts of log space. The following columns in the sys.dm_tran_database_transactions DMV can be useful:
For more information about the sys.dm_tran_database_transactions DMV, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn2.microsoft.com/en-us/library/ms186957.aspx
(http://msdn2.microsoft.com/en-us/library/ms186957.aspx)
For more information about the sys.dm_tran_session_transactions DMV, visit the following MSDN Web site: http://msdn2.microsoft.com/en-us/library/ms188739.aspx
(http://msdn2.microsoft.com/en-us/library/ms188739.aspx)
For more information about the sys.dm_exec_requests DMV, visit the following MSDN Web site: http://msdn2.microsoft.com/en-us/library/ms177648.aspx
(http://msdn2.microsoft.com/en-us/library/ms177648.aspx)
APPLIES TO
| Article Translations
|
Back to the top
