
Shrinking SQL Server transaction logs is a common task for DBAs, especially when logs grow unexpectedly large. Here’s a step-by-step guide to help you manage and shrink them safely:
If the log is full, start with Transaction Log Full. Shrinking does not fix a full log.
Before shrinking transaction logs
Check what is stopping the log from being reused. If it shows anything other than NOTHING, a shrink won’t release much space:
SELECT name, recovery_model_desc, log_reuse_wait_desc
FROM sys.databases
WHERE name = N'YourDB';
Important considerations when shrinking transaction logs
- Don’t shrink logs regularly—only do it when necessary (e.g., after a large transaction or maintenance).
- Set appropriate auto growth settings to avoid frequent growth/shrink cycles.
- Don’t switch to SIMPLE recovery without approval. It breaks the log backup chain and needs a full backup afterwards (see Transaction Log Full).
USE [YourDB]
GO
DBCC SHRINKFILE (N'YourDB_log' , 0, TRUNCATEONLY)
GO
If TRUNCATEONLY doesn’t release enough space, shrink to a target size in MB that covers normal peak use:
USE [YourDB]
GO
DBCC SHRINKFILE (N'YourDB_log', 1024) -- target 1 GB; never shrink a log to 1 MB
GO
For the full reference, see Microsoft’s guide to managing the size of the transaction log file.
From my SQL Server DBA handbook.
One thought on “Shrinking Transaction Logs”
Comments are closed.