Shrink and truncate the log file

If the transaction log of a certain database is using too much disk space on the server, you might want to revisit your transaction log backups and set them to run with a higher frequency. You can always reclaim some space with a few workarounds if you really have to… be careful with these and try to understand what you are doing before simply executing commands.


-- Find the LOG file name
USE Database_Name
SELECT NAME FROM Database_Name.dbo.sysfiles WHERE NAME LIKE ('%LOG%')
-- Shrinks the file to its default size
DBCC SHRINKFILE ('Database_Name_Log')

Check whether the Log file has reduced in Size, if not, check the log for uncommitted transactions.

 -- Check open transactions
DBCC OPENTRAN('Database_Name');

In case there are many transactions open, kill them and try shrinking again. If this still doesn’t works, do the following:

USE Master
-- The shrink below may take a long time depending on the size of your DB

About Bruno Carvalho

Coffee addicted tech guy.
This entry was posted in Scripts and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s