MSSQL transaction logs are a key element of the database system that can quickly fill up disk space if not properly managed. In this article, I will show you how to effectively manage MSSQL transaction logs and prevent disk space issues.
The .ldf file can grow to hundreds of GB if MSSQL transaction logs are not regularly backed up or truncated.
Recovery Models for MSSQL Transaction Logs
FULL Recovery Model
- Retains every transaction until log backup
- Enables point-in-time recovery
- Requires regular log backups
SIMPLE Recovery Model
- Automatically truncates logs after checkpoint
- Recovery only to last full backup
- No log backups required
BULK_LOGGED Recovery Model
- Hybrid approach for bulk operations
- Suitable for ETL processes
More about recovery models in Microsoft SQL Server documentation.
SQL Commands for Managing MSSQL Transaction Logs
View Recovery Models
SELECT name AS Database, recovery_model_desc AS Mode
FROM sys.databases
WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb');
Change Recovery Model and Shrink Log
ALTER DATABASE [dbname] SET RECOVERY SIMPLE
DBCC SHRINKFILE ([logfile], 100)
Backup Transaction Log
BACKUP LOG [database] TO DISK = 'C:\Backups\db_log.trn'
Recommendations for MSSQL Transaction Logs
| Environment | Recovery Model |
|---|---|
| Production systems | FULL + regular log backups |
| Dev/Test | SIMPLE |
| Reporting databases | SIMPLE |
Summary
Managing MSSQL transaction logs is critical for stability. Key points:
- FULL model requires regular log backups
- SIMPLE model automatically truncates logs
- Improper configuration leads to disk filling
More guides on Azure and databases in our section.
Odborník na kybernetickú bezpečnosť, správu Azure Cloud a VMware onprem. Využíva technológie, ako Checkmk a MRTG, na monitorovanie siete a zvyšovanie efektívnosti a bezpečnosti IT infraštruktúry. Kontakt: hasin(at)mhite.sk
