Skip to content

Instantly share code, notes, and snippets.

@stummsft
Created October 11, 2019 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stummsft/a5380ebf14309ad63a4b4da629b5e33a to your computer and use it in GitHub Desktop.
Save stummsft/a5380ebf14309ad63a4b4da629b5e33a to your computer and use it in GitHub Desktop.
/*
In SQL 2016, there is a feature to allow effective Backup Compression for databases protected by TDE.
There is however a caution that this feature should not be used when the database has VLFs which are
larger than 4GB. This short script can help identify if any of your databases would be affected.
*/
DECLARE @dbname SYSNAME = 'foo';
--TODO: Add switch to only show noncompliance
--TODO: Add switch to only evaluate databases with TDE active
--------------------------------------------------------------------
DECLARE @size_limit BIGINT = POWER(CONVERT(BIGINT, 2),32); --4GB
DECLARE @vlfs TABLE (
[RecoveryUnitId] INT
, [FileId] INT
, [FileSize] BIGINT
, [StartOffset] BIGINT
, [FSeqNo] INT
, [Status] INT
, [Parity] TINYINT
, [CreateLSN] NUMERIC(25,0)
);
INSERT @vlfs
EXEC('DBCC LOGINFO(''' + @dbname + ''')');
SELECT
@dbname
, SUM(1) AS [vlf_count]
, SUM (CASE
WHEN [FileSize] > @size_limit THEN 1
ELSE 0
END) AS [vlfs_too_large]
FROM @vlfs;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment