sync state

This commit is contained in:
2023-07-10 11:29:35 +02:00
parent ac6501bb42
commit cd9e3d7f82
26 changed files with 690 additions and 294 deletions

View File

@@ -38,8 +38,9 @@ FROM sys.master_files F
JOIN [#dbs] [d2] ON d2.[database_name] = d.[name]
WHERE f.type_desc IN (
'ROWS' --mdf
--'LOG'
--,'LOG'
)
--AND f.[physical_name] LIKE 'f%'
--AND d.[is_read_only] = 0
--AND d.[is_auto_shrink_on] = 0
--AND d.name NOT IN (
@@ -51,47 +52,21 @@ WHERE f.type_desc IN (
ORDER BY [d2].[row_size_mb] DESC, d.name DESC, f.name ASC ;
--free disk space
select distinct
convert(varchar(512), b.volume_mount_point) as [volume_mount_point]
, convert(varchar(512), b.logical_volume_name) as [logical_volume_name]
, convert(decimal(18,1), round(((convert(float, b.available_bytes) / convert(float, b.total_bytes)) * 100),1)) as [percent_free]
, convert(bigint, round(((b.available_bytes / 1024.0)/1024.0),0)) as [free_mb]
, convert(bigint, round(((b.total_bytes / 1024.0)/1024.0),0)) as [total_mb]
, convert(bigint, round((((b.total_bytes - b.available_bytes) / 1024.0)/1024.0),0)) as [used_mb]
, CURRENT_TIMESTAMP AS now
,REPLACE(@@SERVERNAME ,'\apssql','')AS srvName
from sys.master_files as [a]
CROSS APPLY sys.dm_os_volume_stats(a.database_id, a.[file_id]) as [b]
ORDER BY [percent_free] ASC
RETURN
SELECT *
FROM sys.master_files F WITH(NOWAIT)
WHERE f.[physical_name] LIKE 'f:%'
/*
--craft data files shrink without reorganizing
SELECT
d.[name]
,f.[physical_name]
,f.[name]
,'USE '+d.name+';
DBCC SHRINKFILE (N'''+f.[name]+''' , 0, TRUNCATEONLY);
GO
' AS shrinkData
FROM sys.master_files F
JOIN sys.databases d ON d.[database_id] = f.[database_id]
WHERE f.type_desc = 'ROWS' --mdf
AND d.[is_read_only] = 0
AND d.[is_auto_shrink_on] = 0
AND d.name NOT IN (
'master'
,'tempdb'
,'model'
,'msdb'
)
*/
SELECT DISTINCT
CONVERT(VARCHAR(512), [b].[volume_mount_point]) AS [volume_mount_point],
CONVERT(VARCHAR(512), [b].[logical_volume_name]) AS [logical_volume_name],
CONVERT(
DECIMAL(18, 1),
ROUND(((CONVERT(FLOAT, [b].[available_bytes]) / CONVERT(FLOAT, [b].[total_bytes])) * 100), 1)) AS [percent_free],
CONVERT(BIGINT, ROUND((([b].[available_bytes] / 1024.0) / 1024.0 / 1024.0), 0)) AS [free_gb],
CONVERT(BIGINT, ROUND((([b].[available_bytes] / 1024.0) / 1024.0 ), 0)) AS [free_mb],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0 / 1024.0), 0)) AS [total_gb],
CONVERT(BIGINT, ROUND(((([b].[total_bytes] - [b].[available_bytes]) / 1024.0) / 1024.0 / 1024.0), 0)) AS [used_gb],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0), 0)) / 100 * 5 / 1024.0 AS [5% space in Go is],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0), 0)) / 100 * 10 / 1024.0 AS [10% space in Go is],
CONVERT(BIGINT, ROUND((([b].[total_bytes] / 1024.0) / 1024.0), 0)) / 100 * 15 / 1024.0 AS [15% space in Go is],
CURRENT_TIMESTAMP AS now,
REPLACE(@@SERVERNAME, '\apssql', '') AS srvName
FROM sys.master_files AS [a]
CROSS APPLY sys.dm_os_volume_stats(a.database_id, a.[file_id]) AS [b]
ORDER BY [percent_free] ASC;