Skip to content

Commit

Permalink
Merge pull request dataplat#2813 from Zhunya/touch_InvokeDbShrink
Browse files Browse the repository at this point in the history
Touch invoke db shrink
  • Loading branch information
potatoqualitee authored Dec 11, 2017
2 parents f266b28 + 4b6f7f5 commit c4ab646
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions functions/Invoke-DbaDatabaseShrink.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Specifies the files types that will be shrunk
Exclude statistics about fragmentation
.PARAMETER ExcludeUpdateUsage
Skips DBCC UPDATE USAGE for database
Exclude DBCC UPDATE USAGE for database
.PARAMETER WhatIf
Shows what would happen if the command were to run
Expand Down Expand Up @@ -145,7 +145,7 @@ Shrinks all databases on SQL2012 (not ideal for production)
$FileType = 'Log'
}

$StatementTimeoutMinutes = $StatementTimeout * 60
$StatementTimeoutSeconds = $StatementTimeout * 60

$sql = "SELECT
indexstats.avg_fragmentation_in_percent
Expand Down Expand Up @@ -190,7 +190,7 @@ Shrinks all databases on SQL2012 (not ideal for production)
else {
Write-Message -Level Verbose -Message "Changing statement timeout to $StatementTimeout minutes"
}
$server.ConnectionContext.StatementTimeout = $StatementTimeout
$server.ConnectionContext.StatementTimeout = $StatementTimeoutSeconds

$dbs = $server.Databases | Where-Object { $_.IsSystemObject -eq $false }

Expand Down Expand Up @@ -246,7 +246,6 @@ Shrinks all databases on SQL2012 (not ideal for production)
$db.LogFiles.Shrink($PercentFreeSpace, $ShrinkMethod)
$db.Refresh()
Write-Message -Level Verbose -Message "Recalculating space usage"
if ($False -eq $ExcludeUpdateUsage){$db.RecalculateSpaceUsage()}
$success = $true
$notes = $null
}
Expand All @@ -266,7 +265,7 @@ Shrinks all databases on SQL2012 (not ideal for production)
}
$db.Refresh()
Write-Message -Level Verbose -Message "Recalculating space usage"
if ($False -eq $ExcludeUpdateUsage){$db.RecalculateSpaceUsage()}
if (-not $ExcludeUpdateUsage) { $db.RecalculateSpaceUsage() }
$success = $true
$notes = $null
} catch {
Expand All @@ -280,7 +279,7 @@ Shrinks all databases on SQL2012 (not ideal for production)
$db.Shrink($PercentFreeSpace, $ShrinkMethod)
$db.Refresh()
Write-Message -Level Verbose -Message "Recalculating space usage"
if ($False -eq $ExcludeUpdateUsage){$db.RecalculateSpaceUsage()}
if (-not $ExcludeUpdateUsage) { $db.RecalculateSpaceUsage() }
$success = $true
$notes = $null
}
Expand Down

0 comments on commit c4ab646

Please sign in to comment.