How to shrink transaction log files for SharePoint
- Change the database recovery model to SIMPLE using the next command:
- ALTER DATABASE <Your Database Name> SET RECOVERY SIMPLE;
- ALTER DATABASE <Your Database Name> SET RECOVERY SIMPLE;
- Shrink the database or transaction log file using Microsoft SQL Server Management Studio:
Right click on the database which you altered to recovery simple and go to Task | Shrink | Database It will take some time depend on on the size of database- DBCC SHRINKFILE (<Your Database Name>_Log, 5);
- Set back the database recovery model to FULL using the next command:
- ALTER DATABASE <Your Database Name> SET RECOVERY FULL;
- ALTER DATABASE <Your Database Name> SET RECOVERY FULL;
Understand truncating the log
If a database is a simple recovery model, the system truncates the transaction log automatically after every transaction. For databases with a full or bulk-logged recovery model, the system truncates the transaction log only after a successful transaction log backup.
A full database backup does not truncate the log. If you don’t take regular transaction log backups, the log file continues to grow until it runs out of space. While truncating the log makes the space available for use again, it does not decrease the transaction log file size. To reduce the size of the transaction log file, you need to shrink the log file.
Truncate the transaction log
Use the following steps to truncate the transaction log file in SQL Server Management Studio (SQL Server 2008 and later). Keep in mind that following these steps might result in data loss. You should not need to manually truncate the log because regular log backups should automatically perform this task.
Note: You need the sysadmin
fixed server role or the db_owner
fixed database role to truncate the log.
Right-click the database and select Properties -> Options.
Set the recovery model to
Simple
and exit the menu.Right-click the database again and select Tasks -> Shrink -> Files.
Change the type to
Log
.Under Shrink action, select Reorganize pages before releasing unused space and click OK.
When the process completes, switch the recovery model back to
Full
orBulk-Logged
and take a full database backup.
Understand shrinking the log
If you need to recover disk space from the transaction log file, consider shrinking the log file. Shrinking recovers space by moving data from the end of the file to unoccupied space at the front of the file. After the process creates enough space at the end of the file, it can be deallocated and returned to the file system. Shrinking logs helps after you perform an action that creates a large number of logs. You can only shrink the log if there is free space on the log file.
Shrink the transaction log
Use the following steps to truncate the transaction log file:
Note: You need the sysadmin
fixed server role or the db_owner
fixed database role to shrink the log.
Right-click the database and select Tasks -> Shrink -> Files.
Change the type to
Log
.Under Shrink action, select Release unused space and click OK.
Comentarios
Publicar un comentario
Dime si la información de este blog te sirvio.