Monday, May 13, 2013

How to shrink SQL / SharePoint database / log files



1. First to be on the safe side, let’s back it up (this step is optional)

Select New Query

Type the following:
BACKUP LOG [Sharepoint_Config] TO DISK='D:\SharePointConfigLogBackup.bak'
GO

Where SharePoint_Config is the name of your config database file and D:\SharePoinConfiglogbackup.bak is the location and file name of where you’ll make the backup.

And click Execute


2. Use the following simple three steps to shrink your database


USE [master]  
GO  
ALTER DATABASE [SharePoint_Config] SET RECOVERY SIMPLE WITH NO_WAIT  
GO  

Click Execute

USE [Sharepoint_Config]  
GO  
DBCC SHRINKFILE ('SharePoint_Config_log')  
GO  

Click Execute


ALTER DATABASE [SharePoint_Config] SET RECOVERY FULL WITH NO_WAIT 
GO
USE [Sharepoint_Config]  
GO

Click Execute


3. If you get the below error when you run the shrink file query

Msg 8985, Level 16, State 1, Line 1
Could not locate file 'tempdb_log' for database 'tempdb' in sys.database_files. The file either does not exist, or was dropped. 

Use the below commends to shrink those system database files

USE tempdb;
GO
SELECT file_id, name FROM sys.database_files;
GO
DBCC SHRINKFILE (2, TRUNCATEONLY);

Here tempdb is your system database files name.



No comments:

Post a Comment