SharePoint Config database Log file too big – Steps to reduce it

Ever faced the uphill task to manage large (over 50 GB at times) of SharePoint configuration database log file (can be MOSS 2007, SharePoint 2010 or SharePoint 2013). I have and to the extent that the Logfile might end up eating all the drive space.

Different people have different opinion on how to approach this and I have my own. Here goes my 2 cent:

1. Connect to the Configuration database SQL Server.

2. Run the following command against the configuration database (SP_config_XXXX):

DBCC SQLPERF(logspace)

The above command will show you the amount of free space available. It generally will be 99% used. Issue a checkpoint now. Run:

DBCC SQLPERF(logspace)


3. Take your Transactional logfile backup using SSMS:

Start > All Programs > Microsoft SQL Server 2008 > SQL Server Management Studio > Connect to the Configuration database SQL Server > Right Click the Config database name > Tasks > Backup > Under Backup Type Select “Transaction Log” > Provide a Backup to location > Under Options make sure “Truncate the transaction log” radio button is selected > Set Backup compression select “Compress backup”

Wait for it to finish may take 5 -7 minutes but depends on server resources available.

4. Once Step 3 is complete Run :

DBCC SQLPERF(logspace)

You should see that the logspace used % for the config db is now  0.7% or so.

5. Issue the command to find the Config database logfile name:

Select * from Sys.Database_Files

Copy the name of the Configuration database logfile cause you are going to need it in the next step.

6. Shrink the logfile now using the command below. My Logifile name is SP_Config_prod01_log and I used 1000 MB since I did not want my logfiles to be 512 KB in size and then grow rapidly (I hate illusion)

DBCC ShrinkFile (‘SP_config_prod01_log’,1000)

7. Now the fun starts. You will be surprised to note ladies and gentlemen that the logfile has not shrunk. Indeed we live in a world of illusion. At this point I will request you to maintain peace and not run like a headless chicken and follow these steps.

Redo Step 3 to take the Transactional logfile backup again and this time under Options in the backup menu > under Overwrite media > Select “Append to the exisiting backup set”.

This time the backup will be much faster than Step 3.

8. Issue the Shrink command again:

DBCC ShrinkFile (‘SP_config_prod01_log’,1000)

9. Check the Log Size using:

DBCC SQLPERF(logspace)

The Config DB logfile size should have gone down to 1000 MB.

10. And the most important. Thank God and not me that you reached this far without screwing up your production server.


PowerShell script to create many SharePoint sites in a site collection

All you need to change is the Site Title (@Subsites) and the Site Collection URL ($SiteCollectionURL):

Write-Output ” “
Write-Output “Creating Sub Sites”

$SiteCollectionURL = “http://yoursharepointsite/sitecollection/01″

$SiteCollectionTemplate = “SiteDefinitionTemplate#0”

$SiteCollectionLanguage = 1033

$SubSites = @(“Site Titel 1”, “Site Title 2”)

for($i=0 ; $i -lt $SubSites.count ; $i++)
$SiteUrl = “”
$SiteUrl = $SiteCollectionURL + “/”
$SiteUrl = $SiteUrl += $SubSites[$i]
Write-Output ” “
#Write-Output “Creating Site for ” += $SubSites[$i]
Write-Output ” “
New-SPWeb $SiteUrl -Template $SiteCollectionTemplate -Name “Your Site Name:” $SubSites -UseParentTopNav -Language $SiteCollectionLanguage -Description “Document Library description” $SubSites
Write-Output ” “
#Write-Output “Site Created for ” += $SubSites[$i]
Write-Output ” “

PowerShell to Update Created By and Modified By entries in SharePoint List or Document Library

[Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c”)

$SPSite = New-Object Microsoft.SharePoint.SPSite(http://yoursitename/site1/site2/)

$SPWeb = $SPSite.OpenWeb()

$SPList = $SPWeb.Lists[“Your List”]

$SPListItemCollection = $SPList.Items

foreach ($ListItem in $SPListItemCollection)


$SPFieldUserValue=New-Object Microsoft.SharePoint.SPFieldUserValue ($SPWeb,10, “domainname\username”)

$ListItem[“Editor”] = $SPFieldUserValue$ListItem[“Author”] = $SPFieldUserValue$ListItem.Update()



Count any type of document in your SharePoint farm using PowerShell

Have you experienced a scenario when you have multiple SharePoint content databases across multiple SQL Servers. The scenario I had was following:

1. 3 SQL Servers.

2. Each SQL Server hosts multiple content databases

I did not want to write a script with the name of all the content databases but my script should pickup any SQL Server content database with the word “contet” in the database name. I save the SQL Server to a local file and call the query from PowerShell. In the script there are 2 variables defined, 1 the queryfile and 2 the SharePoint SQL Server instances. Here I am finding the total number of PDFs in my farm but you can use it to find any type of document. The script is as below (rememeber you need Farm Admin access and also need access to SQL Servers):

Save the script below as DocumentCount.ps1 and remember to save the SQL script to your desired location.

#Script starts here

$spqueryfile = “C:\SPDBQuery.sql” 

$sharepointDBinstances = @(“Server\SQLInstance1”,“Server\SQLInstance2”,“Server3\SQLInstance3”)

 $Final = 0 

foreach($sharepointDBinstance in $sharepointDBinstances){

 $initialresult= Invoke-Sqlcmd -ServerInstance $sharepointinstance -InputFile  $spqueryfile

 if (!$initialresult.HasErrors -eq $true){

 $Qresult = $initialresult | %{$_.Count} 

$Sum = $Qresult -join ‘+’ 

$Totals = Invoke-Expression $Sum

 $output “total PDFs in your SharePoint Farm”

    $Final = $Totals $Final



Write-Host “The $output has value $Final”

#End of PowerShell script

The SQL Query is, you can change the query to report of doc or xlsx etc:

–Start of SQL Script

 for select name from sys.databases
   where name like (‘%content%’)
  SET @STMT = ‘SELECT COUNT(*) as Count FROM ‘ + @dbname + ‘.[dbo].[AllDocs] (NOLOCK) WHERE Extension = ”pdf”’
  EXEC sp_executesql @STMT

 —End of SQL Script

Hit like if you like what you see…..

How to enable delete button to delete SharePoint 2010 Content Type column

Here is the PowerShell script to bring back the Content Type delete button:

$site = Get-SPSite-Identity http://sharepointsite/sites/test 

$ctype =$site.RootWeb.Fields | ?{$_.InternalName -eq“InternalFieldName”}



Run the above script from the server and check that the content type button now appears.