Register   |  Login
You are hereArticles
 Article Details
Reduce or truncate the size of the SQL Server log file

We sometimes see that log file (.ldf) is bigger than data file (.mdf). There are times we run out of disk space because of the growing log file.

 Let’s find out how to shrink or truncate the growing log file by using DBCC (Database Console Commands) commands.

Now we are interested in shrinking the log file. We need to run DBCC command against the log file. But to run against, we first need to know the log file name.

SELECT name FROM Sysfiles

The above query will return the database and log file name. Now we got the log file name.

Let’s run the DBCC command now. The following command shrinks the log file.

DBCC SHRINKFILE('SampleDB_Log', 2)

Here 'SampleDB_Log' is the log file and 2 is target file size in MB.

 

Even after executing the command, if you have not got the expected size of the log file, we might have to truncate the logs. The following command would truncate the transaction log

BACKUP LOG SampleDB WITH TRUNCATE_ONLY

Here SampleDB is the database name.

 

Now again run the shrink file command

DBCC SHRINKFILE('SampleDB_Log', 2)

Now you will be seeing the target size achieved. That’s it.

Happy Programming!!!


Written By: Kumaravel
Date Posted: 1/20/2009
Number of Views: 383


Comments
You must be logged in to submit a comment.

Return