SharePoint Blog - René Hézser

Anmelden  RSS Feed RSS Feed
Startet die Suche

Mar 032010

Shrink SQL log files

Depending on the configuration of you databases, the log files (*.ldf) can be very large. See Selecting a Recovery Model.

Should I continue reading?

If your databases are configured to use the FULL recovery model, the log files are very large and you need some free space, you can use this SQL script to shrink them. So keep on reading :-)

The script will change the recovery model for a single database to SIMPLE and shrink the log files. At the end it will restore the recovery model to the setting it has been before.

Just copy the script to a new Query window in your SQL Management Studio. Replace the @databaseName and run the script by hitting F5. You can also change the size in MB the log file should be shrunken to.

USE [master]
GO
DECLARE @debug int
DECLARE @databaseName nvarchar(255)
DECLARE @logfile nvarchar(255)
DECLARE @newFileSize nvarchar(5) -- in MB
DECLARE @sql nvarchar(4000)
DECLARE @parmDefinition nvarchar(500)
DECLARE @recoveryModel nvarchar(10)

--
-- CHANGE HERE BEGIN
set @debug = 1
set @newFileSize = 100 -- in MB
set @databaseName = 'your database name'
-- CHANGE HERE END
--

IF @debug = 1 PRINT 'DatabaseName=' + @databaseName

-- get recovery model from database
SET @sql = N'SELECT @model = recovery_model_desc FROM sys.databases WHERE [name]=''' + @databaseName +''''
SET @ParmDefinition = N'@model nvarchar(255) OUTPUT';
EXECUTE sp_executesql @sql, @ParmDefinition, @model = @recoveryModel OUTPUT;
if @debug = 1 PRINT 'Recovery model=' + @recoveryModel

-- set recovery modell to simple
SELECT @sql = 'ALTER DATABASE [' + @databaseName + '] SET RECOVERY SIMPLE'
IF @debug = 1 PRINT @sql
EXECUTE sp_executesql @sql

-- shrink log file
-- get logfile from database
SET @sql = N'USE [' + @databaseName + ']; SELECT @logfileName = [name] FROM sys.database_files WHERE [type_desc]=''LOG'''
SET @parmDefinition = N'@logfileName nvarchar(255) OUTPUT';
EXECUTE sp_executesql @sql, @parmDefinition, @logfileName = @logFile OUTPUT;
if @debug = 1 PRINT 'Logfile Name=' + @logfile

SELECT @sql = 'USE [' + @databaseName + ']; DBCC SHRINKFILE ([' + @logfile + '] , ' + @newFileSize + ')'
IF @debug = 1 PRINT @sql
EXECUTE sp_executesql @sql

-- restore recovery modell
SELECT @sql = 'ALTER DATABASE [' + @databaseName + '] SET RECOVERY ' + @recoveryModel + ''
IF @debug = 1 PRINT @sql
EXECUTE sp_executesql @sql

-- done

Published: 3/3/2010  11:16 AM | 0  Comments | 0  Links to this post
Tagged as: SQL Server

Apr 142009

Service Pack 1 for Microsoft SQL Server 2008

The SP1 has been released. You can download it here. (Release Notes)

Some changes to make the deployment easier:

  • Slipstream – You are now able to integrate the base installation with service packs (or Hotfixes) and install in a single step.
  • Service Pack Uninstall – You are now able to uninstall only the Service Pack (without removing the whole instance)
  • Report Builder 2.0 Click Once capability

Published: 4/14/2009  3:23 PM | 0  Comments | 0  Links to this post
Tagged as: SQL Server

Mar 132009

SharePoint and Database Maintenance

In this post I would like to point to “an issue” with the Database Maintenance for Microsoft® SharePoint® Products and Technologies. It shows a stored procedure, which will defragment the index of a database.

How to defragment Windows SharePoint Services 3.0 databases and SharePoint Server 2007 databases

The problem is that it is mentioned nowhere, that the stored procedure requires the Enterprise version of the SQL Server 2005!


Published: 3/13/2009  10:15 AM | 0  Comments | 0  Links to this post
Tagged as: SQL Server, SharePoint

Dec 172008

SQL Server 2005 SP3

In case you missed it (like I did). The SP3 for SQL Server 2005 has been released. You can download it directly from Microsoft.

If you are running an Express version, you have to download an updated SQL Server 2005 Express from here.

Technorati Tags: ,,

Published: 12/17/2008  9:38 AM | 0  Comments | 0  Links to this post
Tagged as: SQL Server