当前位置:Gxlcms > 数据库问题 > 如何收缩超大的SharePoint_Config数据库

如何收缩超大的SharePoint_Config数据库

时间:2021-07-01 10:21:17 帮助过:4人阅读

  1、在数据库服务器中打开Microsoft SQL Server Management Studio,找到SharePoint_Config数据库,然后执行下面的语句:

EXEC sp_MSforeachtable @command1="EXEC sp_spaceused ‘?‘"

  2、看到执行的结果,就是每个数据库表的大小,然后看到TimerJobHistory这个表的行数非常多,大小也非常的大。

技术分享

  3、谷歌有类似的解决方案,说是因为job-delete-job-history这个Job运行失败,造成了Job运行的历史记录不能被及时清理,造成了配置数据库越来越大。所以运行下面的脚本,会清理一年以来的积累,而这个Job默认每周运行一次,清理上周积累下来的历史记录。

$history = get-sptimerjob | where-object {$_.name -eq “job-delete-job-history”}

$history.daystokeephistory = 365

$history.update()

$history.runnow()

  4、运行完毕以后,还要将daystokeephistory数值改回7天,如下图:

技术分享

  5、可以看到运行以后,确实有个Job再运行,不过我这里可能由于已经超过365天了,所以也没有起作用,Job依旧运行Failed。所以只能继续谷歌,寻找解决方案。

技术分享

  6、经过不懈的查找,发现了一个ps脚本,把下面脚本,存成一个ps1文件,执行一下,会起作用(至少我这里已经起作用了,会删掉多余的历史记录);

Add-PSSnapin Microsoft.SharePoint.PowerShell

Write-Host "Clearing Down Timer Job History"

$daysToKeep = 300

$daysToPurgeInOneLoop = 5

while ($daysToKeep -gt 0)

{

$history = get-sptimerjob | where-object {$_.name -eq “job-delete-job-history”}

Write-Host " "

Write-Host -NoNewLine "Setting Days to Keep:"

Write-Host -ForegroundColor Green $daysToKeep

$history.DaysToKeepHistory = $daysToKeep

$history.update()

Write-Host -ForegroundColor Green "Starting Purge Job"

$lastTimeJobRan = $history.LastRunTime

$history.runnow()

Write-Host -NoNewLine -ForegroundColor Green "Waiting For Purge Job to Complete"

$jobFinished = $false

while ($jobFinished -eq $false)

{

Start-Sleep -Seconds 2

$runningJob = Get-SPTimerJob $history.Name

Write-Host -NoNewLine -ForegroundColor Yellow "."

if ($lastTimeJobRan -ne $runningJob.LastRunTime)

{

$jobFinished = $true

}

}

Write-Host " "

Write-Host -ForegroundColor Green "Ending Purge Job"

$daysToKeep = $daysToKeep - $daysToPurgeInOneLoop

}

Write-Host -ForegroundColor Green "Setting Final Job History Retention to 3 days, and schedule to run daily @ 5am"

$history.DaysToKeepHistory = 3

$history.update()

$history.runnow()

Set-SPTimerJob -Identity $history -Schedule "Daily at 05:00"

Write-Host -ForegroundColor Yellow "Please check row counts on dbo.TimerJobHistory Table in Config DB to ensure run complete"

结束语

  当然,执行PowerShell的命令需要很长时间,我这里用了大概1天时间,将90多个GB的SharePoint_Config收缩到了15个GB,效果还是很明显的,整理出来很大一部分空间,不用经常做磁盘空间维护了。

附后

  PowerShell命令的参考地址:http://sharepoint.it-professional.co.uk/?p=228

如何收缩超大的SharePoint_Config数据库

标签:

人气教程排行