Added details to space tips
This commit is contained in:
Родитель
105dd6afa6
Коммит
8e586d542e
|
@ -2,7 +2,7 @@
|
|||
Returns a set of tips to improve database design, health, and performance in Azure SQL Database.
|
||||
For a detailed description and the latest version of the script, see https://aka.ms/sqldbtips
|
||||
|
||||
v20210106.1
|
||||
v20210107.1
|
||||
*/
|
||||
|
||||
-- Set to 1 to output tips as a JSON value
|
||||
|
@ -165,7 +165,7 @@ BEGIN TRY
|
|||
DECLARE @EngineEdition int = CAST(SERVERPROPERTY('EngineEdition') AS int);
|
||||
|
||||
IF @EngineEdition NOT IN (5,8)
|
||||
THROW 50005, 'This script runs on Azure SQL Database and Azure SQL Managed Instance only.', 1;
|
||||
THROW 50005, 'This script is for Azure SQL Database and Azure SQL Managed Instance only.', 1;
|
||||
|
||||
-- Bail out if current CPU utilization is very high, to avoid impacting workloads
|
||||
IF EXISTS (
|
||||
|
@ -184,7 +184,7 @@ IF EXISTS (
|
|||
rs.avg_instance_cpu_percent > 95
|
||||
)
|
||||
)
|
||||
THROW 50010, 'CPU utilization is too high. Execute script at a later time.', 1;
|
||||
THROW 50010, 'CPU utilization is too high. Execute the script at a later time.', 1;
|
||||
|
||||
IF DB_NAME() = 'master' AND @EngineEdition = 5
|
||||
THROW 50015, 'Execute this script in a user database, not in the ''master'' database.', 1;
|
||||
|
@ -205,9 +205,9 @@ VALUES
|
|||
(1080, 'Disable AUTO_SHRINK', 99, 'https://aka.ms/sqldbtips#1080'),
|
||||
(1100, 'Avoid GUID leading columns in btree indexes', 60, 'https://aka.ms/sqldbtips#1100'),
|
||||
(1110, 'Enable FLGP auto-tuning', 95, 'https://aka.ms/sqldbtips#1110'),
|
||||
(1120, 'Used space is close to MAXSIZE', 80, 'https://aka.ms/sqldbtips#1120'),
|
||||
(1130, 'Allocated space is close to MAXSIZE', 60, 'https://aka.ms/sqldbtips#1130'),
|
||||
(1140, 'Allocated space is much larger than used space', 50, 'https://aka.ms/sqldbtips#1140'),
|
||||
(1120, 'Used data size is close to MAXSIZE', 80, 'https://aka.ms/sqldbtips#1120'),
|
||||
(1130, 'Allocated data size is close to MAXSIZE', 60, 'https://aka.ms/sqldbtips#1130'),
|
||||
(1140, 'Allocated data size is much larger than used data size', 50, 'https://aka.ms/sqldbtips#1140'),
|
||||
(1150, 'Recent CPU throttling found', 90, 'https://aka.ms/sqldbtips#1150'),
|
||||
(1160, 'Recent out of memory errors found', 80, 'https://aka.ms/sqldbtips#1160'),
|
||||
(1165, 'Recent memory grant waits and timeouts found', 70, 'https://aka.ms/sqldbtips#1165'),
|
||||
|
@ -458,22 +458,33 @@ WHERE name = 'FORCE_LAST_GOOD_PLAN'
|
|||
;
|
||||
|
||||
-- Used space close to maxsize
|
||||
INSERT INTO @DetectedTip (tip_id)
|
||||
SELECT 1120 AS tip_id
|
||||
WITH space_used AS
|
||||
(
|
||||
SELECT SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint) * 8 / 1024.) AS space_used_mb,
|
||||
CAST(DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') AS bigint) / 1024. / 1024 AS max_size_mb
|
||||
FROM sys.database_files
|
||||
WHERE @EngineEdition = 5
|
||||
AND
|
||||
type_desc = 'ROWS'
|
||||
AND
|
||||
CAST(DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') AS bigint) <> -1 -- not applicable to Hyperscale
|
||||
HAVING SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint) * 8 / 1024.)
|
||||
>
|
||||
@UsedToMaxsizeSpaceThresholdRatio * CAST(DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') AS bigint) / 1024. / 1024 -- used space > n% of db maxsize
|
||||
HAVING COUNT(1) > 0
|
||||
)
|
||||
INSERT INTO @DetectedTip (tip_id, details)
|
||||
SELECT 1120 AS tip_id,
|
||||
CONCAT(
|
||||
'Used data size (MB): ', FORMAT(space_used_mb, '#,0.00'),
|
||||
', maximum data size (MB): ', FORMAT(max_size_mb, '#,0.00')
|
||||
)
|
||||
FROM space_used
|
||||
WHERE space_used_mb > @UsedToMaxsizeSpaceThresholdRatio * max_size_mb -- used space > n% of db maxsize
|
||||
;
|
||||
|
||||
-- Allocated space close to maxsize
|
||||
INSERT INTO @DetectedTip (tip_id)
|
||||
SELECT 1130 AS tip_id
|
||||
WITH space_allocated AS
|
||||
(
|
||||
SELECT SUM(CAST(size AS bigint) * 8 / 1024.) AS space_allocated_mb,
|
||||
CAST(DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') AS bigint) / 1024. / 1024 AS max_size_mb
|
||||
FROM sys.database_files
|
||||
WHERE @EngineEdition = 5
|
||||
AND
|
||||
|
@ -481,28 +492,39 @@ WHERE @EngineEdition = 5
|
|||
AND
|
||||
CAST(DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') AS bigint) <> -1 -- not applicable to Hyperscale
|
||||
AND
|
||||
DATABASEPROPERTYEX(DB_NAME(), 'Edition') IN ('Premium','BusinessCritical')
|
||||
HAVING SUM(CAST(size AS bigint) * 8 / 1024.)
|
||||
>
|
||||
@AllocatedToMaxsizeSpaceThresholdRatio * CAST(DATABASEPROPERTYEX(DB_NAME(), 'MaxSizeInBytes') AS bigint) / 1024. / 1024 -- allocated space > n% of db maxsize
|
||||
DATABASEPROPERTYEX(DB_NAME(), 'Edition') IN ('Premium','BusinessCritical') -- not relevant for remote storage SLOs
|
||||
HAVING COUNT(1) > 0
|
||||
)
|
||||
INSERT INTO @DetectedTip (tip_id, details)
|
||||
SELECT 1130 AS tip_id,
|
||||
CONCAT(
|
||||
'Allocated data size (MB): ', FORMAT(space_allocated_mb, '#,0.00'),
|
||||
', maximum data size (MB): ', FORMAT(max_size_mb, '#,0.00')
|
||||
)
|
||||
FROM space_allocated
|
||||
WHERE space_allocated_mb > @AllocatedToMaxsizeSpaceThresholdRatio * max_size_mb -- allocated space > n% of db maxsize
|
||||
;
|
||||
|
||||
-- Allocated space >> used space
|
||||
WITH allocated_used_space AS
|
||||
(
|
||||
SELECT SUM(CAST(size AS bigint)) AS allocated_space,
|
||||
SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)) AS used_space
|
||||
SELECT SUM(CAST(size AS bigint) * 8 / 1024.) AS space_allocated_mb,
|
||||
SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)) / 1024. / 1024 AS space_used_mb
|
||||
FROM sys.database_files
|
||||
WHERE type_desc = 'ROWS'
|
||||
)
|
||||
INSERT INTO @DetectedTip (tip_id)
|
||||
SELECT 1140 AS tip_id
|
||||
INSERT INTO @DetectedTip (tip_id, details)
|
||||
SELECT 1140 AS tip_id,
|
||||
CONCAT(
|
||||
'Used data size (MB): ', FORMAT(space_used_mb, '#,0.00'),
|
||||
', allocated data size (MB): ', FORMAT(space_allocated_mb, '#,0.00')
|
||||
)
|
||||
FROM allocated_used_space
|
||||
WHERE used_space * 8 / 1024. > @UsedToAllocatedSpaceDbMinSizeMB -- not relevant for small databases
|
||||
WHERE space_used_mb * 8 / 1024. > @UsedToAllocatedSpaceDbMinSizeMB -- not relevant for small databases
|
||||
AND
|
||||
@UsedToAllocatedSpaceThresholdRatio * allocated_space > used_space -- allocated space is more than N times used space
|
||||
@UsedToAllocatedSpaceThresholdRatio * space_allocated_mb > space_used_mb -- allocated space is more than N times used space
|
||||
AND
|
||||
DATABASEPROPERTYEX(DB_NAME(), 'Edition') IN ('Premium','BusinessCritical')
|
||||
DATABASEPROPERTYEX(DB_NAME(), 'Edition') IN ('Premium','BusinessCritical') -- not relevant for remote storage SLOs
|
||||
;
|
||||
|
||||
-- Recent CPU throttling
|
||||
|
@ -853,9 +875,9 @@ INSERT INTO @DetectedTip (tip_id, details)
|
|||
SELECT 1190 AS tip_id,
|
||||
CONCAT(
|
||||
'In the last hour, there were ', count_high_log_write_intervals,
|
||||
' interval(s) with log rate staying above ', @HighLogRateThresholdPercent,
|
||||
'%. The longest such interval lasted ', FORMAT(top_log_rate_duration_seconds, '#,0'),
|
||||
' seconds, and the highest log rate was ', FORMAT(top_log_write_percent, '#,0.00'),
|
||||
' interval(s) with transaction log IO staying above ', @HighLogRateThresholdPercent,
|
||||
'% of the limit for the service objective. The longest such interval lasted ', FORMAT(top_log_rate_duration_seconds, '#,0'),
|
||||
' seconds, and the maximum log IO was ', FORMAT(top_log_write_percent, '#,0.00'),
|
||||
'%.'
|
||||
) AS details
|
||||
FROM log_rate_top_stat
|
||||
|
|
Загрузка…
Ссылка в новой задаче