I have a very large database (50+ GB). In order to free space in my hard drive, I tried deleting old records from one of the tables . I ran the command:
delete from Table1 where TheDate<'2004-01-01';
However, SQL Server 2012 said:
Msg 9002, Level 17, State 4, Line 1 The transaction log for database 'MyDb' is full due to 'ACTIVE_TRANSACTION'.
and it did not delete a thing. What does that message mean? How can I delete the records?
In this article, I discuss the solution for the error mentioning that the transaction log for your SQL database is full due to 'ACTIVE_TRANSACTION'. This error means that you SQL Server database has the wrong settings for the task that you want to perform.
Try one of the 4 suggestion below to fix this issue: Under SQL Server Management Studio set the Maximum File Size under options for Altiris database to Unrestricted File Growth. Increase the Restricted File Growth (MB) size to a larger value creating space for transaction logs to grow. Shrink the log files from task.
If the log has never been backed up, you must create two log backups to permit the Database Engine to truncate the log to the point of the last backup. Truncating the log frees logical space for new log records. To keep the log from filling up again, take log backups regularly and more frequently.
To delete data or log files from a databaseExpand Databases, right-click the database from which to delete the file, and then click Properties. Select the Files page. In the Database files grid, select the file to delete and then click Remove. Click OK.
Here is what I ended up doing to work around the error.
First, I set up the database recovery model as SIMPLE. More information here.
Then, by deleting some old files I was able to make 5GB of free space which gave the log file more space to grow.
I reran the DELETE statement sucessfully without any warning.
I thought that by running the DELETE statement the database would inmediately become smaller thus freeing space in my hard drive. But that was not true. The space freed after a DELETE statement is not returned to the operating system inmediatedly unless you run the following command:
DBCC SHRINKDATABASE (MyDb, 0); GO
More information about that command here.
Restarting the SQL Server will clear up the log space used by your database. If this however is not an option, you can try the following:
* Issue a CHECKPOINT command to free up log space in the log file. * Check the available log space with DBCC SQLPERF('logspace'). If only a small percentage of your log file is actually been used, you can try a DBCC SHRINKFILE command. This can however possibly introduce corruption in your database. * If you have another drive with space available you can try to add a file there in order to get enough space to attempt to resolve the issue.
Hope this will help you in finding your solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With