Author | Jason Squires (@js_0505), [email protected] |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Test-DbaDbCompression on GitHub.
Want to see the Bill Of Health for this command? Check out Test-DbaDbCompression.
Returns tables and indexes with preferred compression setting.
This function returns the results of a full table/index compression analysis and the estimated, best option to date for either NONE, Page, or Row Compression.
Remember Uptime is critical, the longer uptime, the more accurate the analysis is, and it would be best if you utilized Get-DbaUptime first, before running this command.
Test-DbaDbCompression script derived from GitHub and the Tiger Team's repository: (https://github.com/Microsoft/tigertoolbox/tree/master/Evaluate-Compression-Gains)
In the output, you will find the following information:
This script will execute on the context of the current database.
Also be aware that this may take a while to execute on large objects, because if the IS locks taken by the
sp_estimate_data_compression_savings cannot be honored, the SP will be blocked.
It only considers Row or Page Compression (not column compression)
It only evaluates User Tables
Test-DbaDbCompression
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Database] <String[]>]
[[-ExcludeDatabase] <String[]>]
[[-Schema] <String[]>]
[[-Table] <String[]>]
[[-ResultSize] <Int32>]
[[-Rank] <String>]
[[-FilterBy] <String>]
[-EnableException]
[<CommonParameters>]
PS C:\> Test-DbaDbCompression -SqlInstance localhost
Returns results of all potential compression options for all databases for the default instance on the local host. Returns a recommendation of either Page, Row or NO_GAIN
PS C:\> Test-DbaDbCompression -SqlInstance ServerA
Returns results of all potential compression options for all databases on the instance ServerA
PS C:\> Test-DbaDbCompression -SqlInstance ServerA -Database DBName | Out-GridView
Returns results of all potential compression options for a single database DBName with the recommendation of either Page or Row or NO_GAIN in a nicely formatted GridView
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Test-DbaDbCompression -SqlInstance ServerA -ExcludeDatabase MyDatabase -SqlCredential $cred
Returns results of all potential compression options for all databases except MyDatabase on instance ServerA using SQL credentials to authentication to ServerA.
Returns the recommendation of either Page, Row or NO_GAIN
PS C:\> Test-DbaDbCompression -SqlInstance ServerA -Schema Test -Table MyTable
Returns results of all potential compression options for the Table Test.MyTable in instance ServerA on ServerA and ServerB.
Returns the recommendation of either Page, Row or NO_GAIN.
Returns a result for each partition of any Heap, Clustered or NonClustered index.
PS C:\> Test-DbaDbCompression -SqlInstance ServerA, ServerB -ResultSize 10
Returns results of all potential compression options for all databases on ServerA and ServerB.
Returns the recommendation of either Page, Row or NO_GAIN.
Returns results for the top 10 partitions by TotalPages used per database.
PS C:\> ServerA | Test-DbaDbCompression -Schema Test -ResultSize 10 -Rank UsedPages -FilterBy Table
Returns results of all potential compression options for all databases on ServerA containing a schema Test
Returns results for the top 10 Tables by Used Pages per database.
Results are split by Table, Index and Partition so more than 10 results may be returned.
PS C:\> $servers = 'Server1','Server2'
PS C:\> $servers | Test-DbaDbCompression -Database DBName | Out-GridView
Returns results of all potential compression options for a single database DBName on Server1 or Server2
Returns the recommendation of either Page, Row or NO_GAIN in a nicely formatted GridView
PS C:\> $cred = Get-Credential sqladmin
PS C:\> Test-DbaDbCompression -SqlInstance ServerA -Database MyDB -SqlCredential $cred -Schema Test -Table Test1, Test2
Returns results of all potential compression options for objects in Database MyDb on instance ServerA using SQL credentials to authentication to ServerA.
Returns the recommendation of either Page, Row or NO_GAIN for tables with Schema Test and name in Test1 or Test2
PS C:\> $servers = 'Server1','Server2'
PS C:\> foreach ($svr in $servers) {
>> Test-DbaDbCompression -SqlInstance $svr | Export-Csv -Path C:\temp\CompressionAnalysisPAC.csv -Append
>> }
This produces a full analysis of all your servers listed and is pushed to a csv for you to analyze.
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 |
Filter to only get specific schemas If unspecified, all schemas will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Filter to only get specific tables If unspecified, all User tables will be processed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Allows you to limit the number of results returned, as some systems can have very large number of tables. Default value is no restriction.
Alias | |
Required | False |
Pipeline | false |
Default Value | 0 |
Allows you to specify the field used for ranking when determining the ResultSize
Can be either TotalPages, UsedPages or TotalRows with default of TotalPages. Only applies when ResultSize is used.
Alias | |
Required | False |
Pipeline | false |
Default Value | TotalPages |
Accepted Values | TotalPages,UsedPages,TotalRows |
Allows you to specify level of filtering when determining the ResultSize
Can be at either Table, Index or Partition level with default of Partition. Only applies when ResultSize is used.
Alias | |
Required | False |
Pipeline | false |
Default Value | Partition |
Accepted Values | Partition,Index,Table |
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 |