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
Copy file name to clipboardExpand all lines: SpaceCapacity-Automation/Automation - Restrict File growth.sql
+98-12
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ GO
14
14
-- DECLARE @_errorOccurred BIT; EXEC @_errorOccurred = tempdb..[usp_AnalyzeSpaceCapacity] ; SELECT CASE WHEN @_errorOccurred = 1 THEN 'fail' ELSE 'pass' END AS [Pass/Fail];
-- If both parameters are NULL, use @tempDbMaxSizeThresholdInGB with default
273
+
IF (@tempDbMaxSizeThresholdInGB ISNULLAND @tempDBMountPointPercent ISNULL)
274
+
BEGIN
275
+
SET @_errorMSG =' /* Value for neither @tempDbMaxSizeThresholdInGB or @tempDBMountPointPercent is provided. So, proceeding with @tempDbMaxSizeThresholdInGB = ';
276
+
SET @tempDbMaxSizeThresholdInGB =16;
277
+
278
+
IF @forceExecute =0
279
+
BEGIN
280
+
SET @_errorMSG = @_errorMSG +CAST( @tempDbMaxSizeThresholdInGB ASVARCHAR(5)) +'
281
+
*/';
282
+
PRINT @_errorMSG;
283
+
END
284
+
END
285
+
END
286
+
287
+
-- Check if valid parameter is selected for procedure
239
288
IF (COALESCE(@getInfo,@help,@addDataFiles,@addLogFiles,@restrictDataFileGrowth,@restrictLogFileGrowth,@generateCapacityException,@unrestrictFileGrowth
-- Check if valid parameter is selected for procedure
285
339
IF ( (@addDataFiles=1OR @addLogFiles=1) AND (@newVolume ISNULLOR @oldVolume ISNULL))
286
340
BEGIN
287
341
SET @_errorMSG ='@oldVolume & @newVolume parameters must be specified with '+(CASEWHEN @addDataFiles=1THEN'@addDataFiles'ELSE'@addLogFiles'END)+' = 1 parameter.';
-- Check if valid parameter is selected for procedure
294
349
IF ( (@restrictDataFileGrowth=1OR @restrictLogFileGrowth=1OR @restrictMountPointGrowth=1) AND (@oldVolume ISNULL))
295
350
BEGIN
296
351
SET @_errorMSG ='@oldVolume parameters must be specified with '+(CASEWHEN @restrictDataFileGrowth=1THEN'@restrictDataFileGrowth'WHEN @restrictLogFileGrowth=1THEN'@restrictLogFileGrowth'ELSE'@restrictMountPointGrowth'END)+' = 1 parameter.';
SELECT'@getInfo','TINYINT','0','Displays distribution of Data Files across multiple data volumes. It presents file details like database name, its file groups, db status, logical name and autogrowth setting, and volume details like free space and total space.'
1634
+
--
1635
+
UNION ALL
1636
+
--
1637
+
SELECT'@volumeInfo','TINYINT','0','Displays Total size, Used Space, Free Space and percentage for all Volumes/disk drives.'
SELECT'@tempDBMountPointPercent','TINYINT','79','Threshold value in percentage for restricting tempdb data files on @oldVolume. This will be used with @expandTempDBSize parameter to re-size the tempdb files if space is added on volume.'
1636
1698
--
1637
1699
UNION ALL
1638
-
--
1700
+
--
1701
+
SELECT'@tempDbMaxSizeThresholdInGB','INT','16','Threshold value for total size of all data files of tempdb database.'
1702
+
--
1703
+
UNION ALL
1704
+
--
1639
1705
SELECT'@DBs2Consider','VARCHAR(1000)',NULL,'Comma (,) separated database names to filter the result set action'
This generates TSQL code for expanding tempdb data files upto @tempDBMountPointPercent % of total tempdb volume capacity.
1781
1850
When @output4IdealScenario set to 1, will generate TSQL code to add/remove data files based on the number Logical cores on server upto 8, and delete extra data files created on non-tempdb volumes, and re-size TempdDB data files to occupy 89% of mount point volume.
@@ -3113,7 +3182,7 @@ ALTER DATABASE ['+DbName+'] MODIFY FILE ( NAME = N'''+[FileName]+''', SIZE = '+C
SELECTDB_NAME(mf.database_id) as DBName, mf.nameas LogicalName, mf.physical_name, ((mf.size*8.0)/1024) as FileSize_MB,
@@ -3139,14 +3208,16 @@ ALTER DATABASE ['+DbName+'] MODIFY FILE ( NAME = N'''+[FileName]+''', SIZE = '+C
3139
3208
IF @verbose =1
3140
3209
PRINT' Logical CPU = '+CAST(@_logicalCores ASVARCHAR(10));
3141
3210
3211
+
-- Get Integer value for [tempdb] data files. For example, value would be 8 from file name [tempdev8].
3142
3212
SET @_maxFileNO = (SELECTMAX( CAST(RIGHT(REPLACE(REPLACE(LogicalName,']',''),'[',''),PATINDEX('%[a-zA-Z_ ]%',REVERSE(REPLACE(REPLACE(LogicalName,']',''),'[','')))-1) ASBIGINT)) FROM @tempDBFiles);
3143
3213
3144
3214
IF @verbose =1
3145
3215
PRINT' @_maxFileNO for Tempdb files = '+CAST(@_maxFileNO ASVARCHAR(10));
3146
3216
3217
+
-- Get count of Valid tempdb data files
3147
3218
SET @_fileCounts = (SELECTCOUNT(*) FROM @tempDBFiles as f WHERE [isToBeDeleted] =0);
3148
3219
IF @verbose =1
3149
-
PRINT' Current TempDB data files (@_fileCounts) = '+CAST(@_fileCounts ASVARCHAR(10));
3220
+
PRINT' Current Valid TempDB data files (@_fileCounts) = '+CAST(@_fileCounts ASVARCHAR(10));
3150
3221
3151
3222
IF @_fileCounts <> (CASEWHEN @_logicalCores >=8THEN8ELSE @_logicalCores END)
3152
3223
SET @_counts_of_Files_To_Be_Created = (CASEWHEN @_logicalCores >=8THEN8ELSE @_logicalCores END) - @_fileCounts;
@@ -3161,6 +3232,7 @@ ALTER DATABASE ['+DbName+'] MODIFY FILE ( NAME = N'''+[FileName]+''', SIZE = '+C
3161
3232
IF @verbose =1
3162
3233
PRINT' Dropping and creating temp table #tempDBFiles';
3163
3234
3235
+
/* This table will contain tempdb files upto 8 */
3164
3236
IFOBJECT_ID('tempdb..#tempDBFiles') ISNOTNULL
3165
3237
DROPTABLE #tempDBFiles
3166
3238
SELECT O.*
@@ -3204,7 +3276,7 @@ ALTER DATABASE ['+DbName+'] MODIFY FILE ( NAME = N'''+[FileName]+''', SIZE = '+C
3204
3276
CROSSJOIN
3205
3277
(SELECTTOP1*FROM @tempDBFiles WHERE [isToBeDeleted] =0ORDER BY LogicalName DESC) AS t
0 commit comments