Montag, 26. September 2011

MS SQL Server 2008 R2: Transaktionsprotokoll shrinken

Problem: Das Transaktionsprotokoll einer Datenbank läßt sich nicht verkleinern.

Lösung: Sichern des Transaktionsprotokolls mit TRUNCATE ONLY. Danach mit DBCC shrinken.

USE myDatabase
GO
DBCC SHRINKFILE(DatabaseTransactionLog, 1)
BACKUP LOG myDatabase WITH TRUNCATE_ONLY
DBCC SHRINKFILE(myDatabaseTransactionLog, 1)
GO


Ebenfalls bewährt hat sich folgende Vorgehensweise:
--set database in recovery model simple
alter database myDatabase set recovery simple
--backup database
backup database myDatabase to disk='C:\backups\myDatabase.bak' with init
--shrink transaction log file
dbcc shrinkfile ('myDatabase_log',10)
--set database in recovery model full
alter database myDatabase set recovery full
--backup database again
backup database myDatabase to disk='C:\backups\myDatabase.bak' with init







Keine Kommentare: