tempdb used% can no longer exceed 100 — total size now comes from the same snapshot as usage (#2169) - #2174
Conversation
The viewer divides in-database FILEPROPERTY(SpaceUsed) by a total taken from sys.master_files.size — which records the size set at configuration and does NOT follow autogrowth for tempdb. A grown tempdb was measured against its startup size, so the ratio ran past 100%. The per-database probe already visits sys.database_files for SpaceUsed; it now also captures df.size, and the payload prefers that over master_files. Both operands come from one snapshot. COALESCE keeps the old source as fallback so a database whose probe failed still reports a total instead of dropping out of the grid. Scope: the on-prem/RDS/MI path. Azure SQL DB already read both numbers from sys.database_files, which is why the reporter's Managed Instance (it takes the cross-database path) hit this and a true Azure SQL DB would not. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
| ### Fixed | ||
|
|
||
| - **tempdb no longer reports more than 100% used in FinOps Database Sizes** ([#2169], reported by @CatastropheOps) - the used percentage divided in-database usage by the size recorded in `sys.master_files`, which is the size set at configuration time and does not track autogrowth for tempdb. A tempdb that had grown was therefore measured against its startup size and rendered above 100%. The per-database probe now captures the file's current size in the same round trip it already makes for space-used, and the payload prefers it, so both halves of the ratio come from one snapshot; a database whose probe fails still falls back to the old source rather than vanishing from the grid. Affects the on-prem, RDS, and Managed Instance path - the Azure SQL Database path already read both numbers in-database. | ||
|
|
There was a problem hiding this comment.
Minor style nit: this entry has a trailing blank line before the next bullet, but every other entry in this ### Fixed list (and in ### Added/### Changed above) runs bullet-to-bullet with no blank line between them. Not functionally significant, just inconsistent with the surrounding convention — worth dropping the blank line for consistency.
Review summaryReviewed the fix for #2169 (tempdb reporting >100% used in FinOps Database Sizes). Correctness — The root-cause diagnosis checks out: The fix captures Azure SQL DB path — Untouched and correctly untouched: that path already reads Lite/Darling parity — No drift risk here: Security/Performance — No new dynamic SQL surface (the added Tests — The two new tests pin the on-prem query's new column, the COALESCE fallback, and the absence of the old bare- One minor style nit left as an inline comment: the new CHANGELOG entry has a trailing blank line that's inconsistent with the rest of the list's bullet-to-bullet formatting. Nothing else to flag — this looks correct and ready to merge. |
Review nit — my insert left a blank line the surrounding list doesn't use. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Reviewed the diff (collector + tests + CHANGELOG). Summary: this looks correct and well-scoped, no blocking issues found. Correctness
Lite/Darling parity
Security/perf
One very minor nit, not blocking: the CHANGELOG entry writes I wasn't able to actually execute |
Root cause
The FinOps grid computes
UsedPct = used_size_mb * 100 / total_size_mb. Those two numbers came from different places:used_size_mb—FILEPROPERTY(df.name, 'SpaceUsed'), read inside each database (sys.database_files).total_size_mb—sys.master_files.size, which records the size set at configuration time and does not follow autogrowth for tempdb.So a tempdb that has grown gets its current usage divided by its startup size, and the percentage runs past 100. Nothing is wrong with either number individually; they just aren't from the same snapshot.
Fix
The per-database probe already visits
sys.database_filesfor SpaceUsed — it now capturesdf.sizein that same round trip (no new query, no extra connection), and the payload takesCOALESCE(fs.current_size_mb, mf.size …). Both halves of the ratio come from one snapshot. TheCOALESCEfallback is deliberate: a database whose probe failed (mid-restore, permissions) still reports a total frommaster_filesrather than dropping out of the grid — worse precision, never a wrong ratio.Every database benefits, since
master_filescan lag any autogrowth, but tempdb is where it's guaranteed to.Scope note
This is the on-prem / RDS / Managed Instance path. The Azure SQL Database path already read both
sizeandSpaceUsedfromsys.database_filesand never had the skew — worth knowing because the reporter's@@VERSIONsaysMicrosoft SQL Azure, which Managed Instance also reports, and MI honors the cross-database reference so it takes the affected path. That reconciles "Azure" in the report with a bug that isn't in the Azure SQL DB query.Testing
Two pins in
DatabaseSizeCollectorDefinitionTests: the on-prem query must declarecurrent_size_mb, capturedf.sizein the probe insert, and prefer it viaCOALESCE(with the baremaster_filestotal asserted gone); and the Azure path must keep reading in-database sizes with nomaster_filesreference — pinned so a later "unify the two paths" refactor can't quietly move Azure onto the stale source. Collectors and Lite.Tests build clean.Fixes #2169.