Tuesday, September 13, 2011

Shrinking the SharePoint Log FIle (for dev machines)

Found some useful information on taming a large log file - useful on a SharePoint development machine.

To shrink log files in sql server 2008, first change the recovery model of database to simple, then shrink the log file and finally change back to the previous recovery model. Here is the SQL:

USE dbname;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE dbname
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (2, 1); -- here 2 is the file ID for trasaction log file,you can also mention the log file name (dbname_log)
GO
-- Reset the database recovery model.
ALTER DATABASE dbname
SET RECOVERY FULL;
GO
 
Thanks to an answer by RTTAdmin on the MSDN forums for that suggestion.

No comments: