< Back

Invoke-DbaBalanceDataFiles

Mon Jan 13, 2020 12:10 pm

NAME Invoke-DbaBalanceDataFiles



SYNOPSIS

Re-balance data between data files





SYNTAX

Invoke-DbaBalanceDataFiles [-SqlCredential <Pscredential>] [-Database <System.Object[]>] [-Table

<System.Object[]>] [-RebuildOffline <Switch>] [-EnableException <Switch>] [-Force <Switch>] [<CommonParameters>]



Invoke-DbaBalanceDataFiles -SqlInstance <Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>

[-SqlCredential <Pscredential>] [-Database <System.Object[]>] [-Table <System.Object[]>] [-RebuildOffline

<Switch>] [-EnableException <Switch>] [-Force <Switch>] [<CommonParameters>]





DESCRIPTION

When you have a large database with a single data file and add another file, SQL Server will only use the new file

until it's about the same size.



You may want to balance the data between all the data files.



The function will check the server version and edition to see if the it allows for online index rebuilds.



If the server does support it, it will try to rebuild the index online.



If the server doesn't support it, it will rebuild the index offline. Be carefull though, this can cause downtime



The tables must have a clustered index to be able to balance out the data.



The function does NOT yet support heaps.



The function will also check if the file groups are subject to balance out.



A file group whould have at least have 2 data files and should be writable.



If a table is within such a file group it will be subject for processing. If not the table will be skipped.





PARAMETERS

-Database [<System.Object[]>]

The database(s) to process.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-EnableException [<Switch>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Force [<Switch>]

This will disable the check for enough disk space for the action to be successful.

Use this with caution!!



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-RebuildOffline [<Switch>]

Will set all the indexes to rebuild offline.

This option is also needed when the server version is below 2005.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlCredential [<Pscredential>]

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.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-SqlInstance [<Sqlcollaborative.Dbatools.Parameter.DbaInstanceParameter[]>]

The target SQL Server instance or instances.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



-Table [<System.Object[]>]

The tables(s) of the database to process. If unspecified, all tables will be processed.



Required? false

Position? named

Default value

Accept pipeline input? False

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Tags: Database, FileManagement, File, Space

Author: Sander Stad (@sqlstad), sqlstad.nl



Website: https://dbatools.io

Copyright: (c) 2018 by dbatools, licensed under MIT

License: MIT https://opensource.org/licenses/MIT



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Invoke-DbaBalanceDataFiles -SqlInstance sql1 -Database db1



This command will distribute the data in database db1 on instance sql1

-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Invoke-DbaBalanceDataFiles -SqlInstance sql1 -Database db1 | Select-Object -ExpandProperty DataFilesEnd



This command will distribute the data in database db1 on instance sql1

-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Invoke-DbaBalanceDataFiles -SqlInstance sql1 -Database db1 -Table table1,table2,table5



This command will distribute the data for only the tables table1,table2 and table5

-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Invoke-DbaBalanceDataFiles -SqlInstance sql1 -Database db1 -RebuildOffline



This command will consider the fact that there might be a SQL Server edition that does not support online rebuilds

of indexes.

By supplying this parameter you give permission to do the rebuilds offline if the edition does not support it.



RELATED LINKS