Set-sqmTempDbFileSize
Performance
sqmSQLTool v1.9.206.0+ · Set
The target is the largest existing file unless
-TargetSizeMB asks for more. ALTER DATABASE ... MODIFY FILE can only grow a file, so nothing that has already grown is lost. The change is online and is stored as the startup size, so it survives a restart. The log file is not touched. Shrinking is deliberately not part of this function: DBCC SHRINKFILE on TempDB can fail under load and often needs a restart.
Before the first change it checks that no file has a
MAXSIZE below the target and that every volume has enough free space. If either check fails, nothing is changed, so TempDB is never left half equalized. Without VIEW SERVER STATE the space check is skipped with a warning.
Parameters
| Parameter | Type | Required | Default | Notes |
|---|---|---|---|---|
| -SqlInstance | string | Optional | local computer name | SQL Server instance. |
| -SqlCredential | PSCredential | Optional | — | Optional SQL login. |
| -TargetSizeMB | int | Optional | largest data file | Target size per data file in MB. Must not be below the largest file, because files are not shrunk here. |
| -FileGrowthMB | int | Optional | unchanged | Sets the same fixed autogrowth step on all data files. Without it, differing steps are only reported: the files drift apart again at the next growth. |
| -WhatIf / -Confirm | switch | Switch | — | Shows or confirms each file change. |
| -EnableException | switch | Switch | $false | Throw instead of logging and returning a failed result object. |
Return Value
OnePSCustomObject per data file: SqlInstance, LogicalName, PhysicalName, OldSizeMB, NewSizeMB, OldGrowth, NewGrowth, Status (Changed, Unchanged, WhatIf or Failed) and Message.
Execution Flow
Examples
Show what would change, without changing anything
Set-sqmTempDbFileSize -SqlInstance "SQL01" -WhatIf
Bring all data files to the size of the largest one
Set-sqmTempDbFileSize -SqlInstance "SQL01"
Fixed target size and one autogrowth step for every file
Set-sqmTempDbFileSize -SqlInstance "SQL01" -TargetSizeMB 8192 -FileGrowthMB 512