You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a -TargetFileGroup parameter that allows rebuilding clustered indexes
into a specific filegroup, enabling data migration between filegroups.
When -TargetFileGroup is specified:
- All tables with clustered indexes are eligible (bypasses the 2+ files requirement)
- The target filegroup is validated to exist and be writable
- Each clustered index's FileGroup property is set before rebuild
- The original filegroup is restored in memory if the rebuild fails
Resolves#8863
(do Invoke-DbaBalanceDataFiles)
Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
Copy file name to clipboardExpand all lines: public/Invoke-DbaBalanceDataFiles.ps1
+57-5Lines changed: 57 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,10 @@ function Invoke-DbaBalanceDataFiles {
18
18
A file group would have at least have 2 data files and should be writable.
19
19
If a table is within such a file group it will be subject for processing. If not the table will be skipped.
20
20
21
+
When the -TargetFileGroup parameter is specified, indexes can be moved from their current filegroup
22
+
to the specified target filegroup regardless of how many data files the current filegroup contains.
23
+
This allows consolidating or migrating data between filegroups.
24
+
21
25
Note: this command does not perform a disk space check for non-Windows machines so make sure you have enough space on the disk.
22
26
23
27
.PARAMETERSqlInstance
@@ -38,6 +42,12 @@ function Invoke-DbaBalanceDataFiles {
38
42
Specifies which tables to balance data for within the target databases. Only tables with clustered indexes in file groups containing multiple data files will be processed.
39
43
When omitted, all eligible tables in the database will be processed. Use this to target specific large tables that need data redistribution.
40
44
45
+
.PARAMETERTargetFileGroup
46
+
The name of the filegroup to rebuild indexes into. When specified, indexes can be moved from their current filegroup
47
+
to the target filegroup, regardless of how many data files the current filegroup contains.
48
+
49
+
When not specified, the function only processes tables in filegroups with at least 2 data files.
50
+
41
51
.PARAMETERRebuildOffline
42
52
Forces all clustered index rebuilds to occur offline, which redistributes data between files but blocks table access during the operation.
43
53
Use this switch when you need to balance data files but can accept downtime, or when working with SQL Server editions that don't support online index operations (Standard, Express, Web).
@@ -107,6 +117,16 @@ function Invoke-DbaBalanceDataFiles {
107
117
This command will consider the fact that there might be a SQL Server edition that does not support online rebuilds of indexes.
108
118
By supplying this parameter you give permission to do the rebuilds offline if the edition does not support it.
0 commit comments