Author | Jason Squires (@js_0505), [email protected] |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Set-DbaDbCompression on GitHub.
Want to see the Bill Of Health for this command? Check out Set-DbaDbCompression.
Sets tables and indexes with preferred compression setting.
This function sets the appropriate compression recommendation, determined either by using the Tiger Team's query or set to the CompressionType parameter.
Remember Uptime is critical for the Tiger Team query, the longer uptime, the more accurate the analysis is.
You would probably be best if you utilized Get-DbaUptime first, before running this command.
Set-DbaDbCompression script derived from GitHub and the tigertoolbox
(https://github.com/Microsoft/tigertoolbox/tree/master/Evaluate-Compression-Gains)
Set-DbaDbCompression
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-ExcludeDatabase] <String[]>]
[[-Table] <String[]>]
[[-CompressionType] <String>]
[[-MaxRunTime] <Int32>]
[[-PercentCompression] <Int32>]
[-ForceOfflineRebuilds]
[[-InputObject] <Object>]
[-EnableException]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
PS C:\> Set-DbaDbCompression -SqlInstance localhost -MaxRunTime 60 -PercentCompression 25
Set the compression run time to 60 minutes and will start the compression of tables/indexes that have a difference of 25% or higher between current and recommended.
PS C:\> Set-DbaDbCompression -SqlInstance ServerA -Database DBName -CompressionType Page -Table table1, table2
Utilizes Page compression for tables table1 and table2 in DBName on ServerA with no time limit.
PS C:\> Set-DbaDbCompression -SqlInstance ServerA -Database DBName -PercentCompression 25 | Out-GridView
Will compress tables/indexes within the specified database that would show any % improvement with compression and with no time limit. The results will be piped into a nicely formatted GridView.
PS C:\> $testCompression = Test-DbaDbCompression -SqlInstance ServerA -Database DBName
PS C:\> Set-DbaDbCompression -SqlInstance ServerA -Database DBName -InputObject $testCompression
Gets the compression suggestions from Test-DbaDbCompression into a variable, this can then be reviewed and passed into Set-DbaDbCompression.
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Set-DbaDbCompression -SqlInstance ServerA -ExcludeDatabase Database -SqlCredential $cred -MaxRunTime 60 -PercentCompression 25
Set the compression run time to 60 minutes and will start the compression of tables/indexes for all databases except the specified excluded database. Only objects that have a difference of 25% or
higher between current and recommended will be compressed.
PS C:\> $servers = 'Server1','Server2'
PS C:\> foreach ($svr in $servers) {
>> Set-DbaDbCompression -SqlInstance $svr -MaxRunTime 60 -PercentCompression 25 | Export-Csv -Path C:\temp\CompressionAnalysisPAC.csv -Append
>> }
Set the compression run time to 60 minutes and will start the compression of tables/indexes across all listed servers that have a difference of 25% or higher between current and recommended. Output
of command is exported to a csv.
The target SQL Server instance or instances. This can be a collection and receive pipeline input to allow the function to be executed against multiple SQL Server instances.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory - Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The database(s) to process - this list is auto populated from the server. If unspecified, all databases will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The database(s) to exclude - this list is auto populated from the server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The table(s) to process. If unspecified, all tables will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Control the compression type applied. Default is 'Recommended' which uses the Tiger Team query to use the most appropriate setting per object. Other option is to compress all objects to either Row or
Page.
Alias | |
Required | False |
Pipeline | false |
Default Value | Recommended |
Accepted Values | Recommended,Page,Row,None |
Will continue to alter tables and indexes for the given amount of minutes.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Will only work on the tables/indexes that have the calculated savings at and higher for the given number provided.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
By default, this function prefers online rebuilds over offline ones.
If you are on a supported version of SQL Server but still prefer to do offline rebuilds, enable this flag
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
Takes the output of Test-DbaDbCompression as an object and applied compression based on those recommendations.
Alias | |
Required | False |
Pipeline | false |
Default Value |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.
Alias | wi |
Required | False |
Pipeline | false |
Default Value |
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.
Alias | cf |
Required | False |
Pipeline | false |
Default Value |