Sunday, October 5, 2014

How to Shrink WSS_Logging Database?

Issue:
SharePoint 2010/2013 always fill the "WSS_Logging.mdf" file continuously. If you are trying to shrink or empty the ".mdf" or ".ldf" files, you will not be able to shrink them.

Follow the below steps to shrink them immediately.

Solution:
1. Open a new Query window by right clicking the "WSS_Logging" database.
2. Paste the below query and execute it which will empty the unwanted contents from database.

DECLARE @TableName AS VARCHAR(MAX)
DECLARE table_cursor CURSOR
FOR 
SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE'
AND TABLE_NAME LIKE '%_Partition%'
OPEN table_cursor
FETCH NEXT FROM table_cursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @SQLText AS NVARCHAR(4000)

SET @SQLText = 'TRUNCATE TABLE ' + @TableName

EXEC sp_executeSQL @SQLText

FETCH NEXT FROM table_cursor INTO @TableName 
END
CLOSE table_cursor
DEALLOCATE table_cursor


3. Once the above is query executed, your SQL DB is ready to shrink. (If the above query is not executed, then you will not be able to shrink the "WSS_Content.mdf" file.

4. Now right click on the database and go to the "shrink window" as mentioned below and shrink the DB to "50 MB".

























5. Now the DB size would be re-sized to 50 MB.

Thats it...

No comments:

Post a Comment