How to shrink transaction log files for SharePoint

Thanks to: http://aryannava.com


Here is the instruction to shrink transaction logs  files for SharePoint 
  1. Change the database recovery model to SIMPLE using the next command:
    • ALTER DATABASE <Your Database Name> SET RECOVERY SIMPLE;
      shrink_transaction_logs_for_sharepoint
  2. 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
    Shrink Transaction Log for SharePoint
    Or use the following command to shrink the transaction log file, for example, to 5 MB:
    • DBCC SHRINKFILE (<Your Database Name>_Log, 5);
  3. Set back the database recovery model to FULL using the next command:
    • ALTER DATABASE <Your Database Name> SET RECOVERY FULL;
      shrink_transaction_logs_for_sharepoint_recovery_full
If it’s not production database, you, in principle, can skip step 3 leaving the databaserecovery model in SIMPLETransaction log in this case will not grow. But note that some people complain that it can cause some problems while attempting to delete SiteCollectionfrom SharePoint Central Administration. I’ve never been faced with such issue, but just in case keep FULL recovery model.
Other Solution:

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.

  1. Right-click the database and select Properties -> Options.

  2. Set the recovery model to Simple and exit the menu.

  3. Right-click the database again and select Tasks -> Shrink -> Files.

  4. Change the type to Log.

  5. Under Shrink action, select Reorganize pages before releasing unused space and click OK.

  6. When the process completes, switch the recovery model back to Full or Bulk-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.

  1. Right-click the database and select Tasks -> Shrink -> Files.

  2. Change the type to Log.

  3. Under Shrink action, select Release unused space and click OK.

Comentarios

Entradas populares de este blog

Guía de herramientas básicas para estudiantes: 31 apps y webs imprescindibles para ayudarte con los estudios

Comando FOR para archivos BAT

How to Fix Failed to Connect a Hyper-V Standalone to Veeam Backup