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

怎样收缩超大的SharePoint_Config数据库

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

  1、在数据库server中打开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数据库

标签:不能   记录   研究   job   日志   前言   文件的   方式   sha   

人气教程排行