I have a database .mdf file that is 138 GB along with a transaction log file of 55 GB.
The recovery model was set to Full (which it doesn’t need to be). I ran a full backup of the database and the transaction log. The transaction log is still 55 GB with no free space to shrink the file.
I ran that backup through SQL Server Management Studio GUI. I then ran the following commands to try to force the trans log to shrink:
BACKUP LOG database WITH TRUNCATE_ONLY
DBCC SHRINKFILE (logfile, TRUNCATEONLY )
The log file is still 55 GB. I then changed the recovery model to Simple and let it sit a few days, but it’s still at 55 GB. I tried those 2 commands above again but it still doesn’t truncate anything.
No matter what I try, this log file won’t shrink. Since we don’t need the transaction log at all, I even tried detaching the database, renaming the log file and reattaching. That doesn’t work either as there are actually 2 transaction logs, and I get an error when trying to reattach without the logs. The other log file is only 1 MB, and I’ve tried to remove that as well, but get also get an error saying it’s not empty.
Is there something I’m missing, or something else I can try?
Thanks for any help!
“I even tried detaching the database, renaming the log file and reattaching”: The log is not an optional component! Run DBCC CHECKDB immediately to see if you have caused corruption. You will cause corruption if there were unflushed pages for some reason. Even if not you are gambling.
The SQL Server log file is not an informational text log.
If you don’t need the log, switch to simple mode and shrink the log file (you already did that). TRUNCATE_ONLY is obsolete, I don’t know if it even does anything.
Look at sys.databases and look at the value in the log_reuse_wait_desc column. It will tell you what is keeping the log around.