Sql-server – How to shrink the MASTER log file in SQL Server 2008

sql serversql-server-2008transaction-log

This is for a non-system database:

USE AdventureWorks
GO
ALTER DATABASE AdventureWorks 
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE (AdventureWorks_Log)
GO
ALTER DATABASE AdventureWorks 
SET RECOVERY FULL
GO

But should I do something different for the MASTER database?

Best Answer

The first question that is going to come to mind for many readers is, "why is your master database log so big that you are thinking of shrinking it?" If user tables were accidentally placed in master that caused log file growth, they need to be removed.

If the master log file has become overly large for some reason and there is now free space in it, you can shrink it like any other database log file. Master should already be in simple recovery mode, so your shouldn't need to change it.

USE master
GO
DBCC SHRINKFILE (N'mastlog', 0, TRUNCATEONLY)
GO

You may want to resize it after this if it shrunk down to less than a couple MB. Not sure what the default is, but I'm looking at a later version of SQL Server and it is 3 MB, so anything in that range should be a sufficient.