From dd4a7f1f7f042abe5f01325e99e39a0be25809fb Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Tue, 21 Apr 2026 19:31:38 -0400 Subject: [PATCH] Drop sys.dm_os_schedulers from memory_stats on Azure SQL DB (#857) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Azure SQL Database DBs hosted in an elastic pool (notably D365FO customer tenants) enforce VIEW SERVER PERFORMANCE STATE on sys.dm_os_schedulers regardless of the login's DB-scoped grants — VIEW DATABASE STATE + VIEW DATABASE PERFORMANCE STATE on the user DB are not sufficient. Verified by reproducing the failure in a standard Azure SQL DB elastic pool with a contained DB user; bare sys.dm_exec_requests/sys.dm_os_sys_info/sys.dm_os_performance_counters succeed but sys.dm_os_memory_clerks / sys.dm_os_schedulers / sys.dm_os_waiting_tasks fail with error 300. The other failing collectors (memory_clerks, waiting_tasks, tempdb_stats) have no DB-scoped alternative and will stay skip-gated via #870 for these users. Co-Authored-By: Claude Opus 4.7 (1M context) --- Lite/Services/RemoteCollectorService.Memory.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Lite/Services/RemoteCollectorService.Memory.cs b/Lite/Services/RemoteCollectorService.Memory.cs index e90339e..2dc6bfc 100644 --- a/Lite/Services/RemoteCollectorService.Memory.cs +++ b/Lite/Services/RemoteCollectorService.Memory.cs @@ -30,6 +30,14 @@ Use sys.dm_os_sys_info committed_target_kb/committed_kb as approximations. Azure MI (edition 8) HAS dm_os_sys_memory, sql_memory_model_desc, and behaves like on-prem. */ bool isAzureSqlDb = serverStatus.SqlEngineEdition == 5; + /* + * Azure SQL Database in an elastic pool (e.g. D365FO tenants) enforces + * VIEW SERVER PERFORMANCE STATE on sys.dm_os_schedulers regardless of + * the login's DB-scoped grants, so we skip the schedulers subquery on + * Azure SQL DB and report current_workers_count as NULL. The rest of + * the row — memory sizes from sys.dm_os_sys_info and the perf counters + * — succeeds for contained DB users. See #857. + */ string query = isAzureSqlDb ? @" SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; @@ -46,7 +54,7 @@ Azure MI (edition 8) HAS dm_os_sys_memory, sql_memory_model_desc, and behaves li buffer_pool_mb = CONVERT(decimal(18,2), pc_buffer.cntr_value / 1024.0), plan_cache_mb = CONVERT(decimal(18,2), pc_plan.cntr_value * 8.0 / 1024.0), max_workers_count = osi.max_workers_count, - current_workers_count = w.current_workers + current_workers_count = CONVERT(int, NULL) FROM sys.dm_os_sys_info AS osi CROSS JOIN ( @@ -73,12 +81,6 @@ FROM sys.dm_os_performance_counters WHERE counter_name = N'Cache Pages' AND object_name LIKE N'%:Plan Cache%' ) AS pc_plan -CROSS JOIN -( - SELECT current_workers = SUM(active_workers_count) - FROM sys.dm_os_schedulers - WHERE status = N'VISIBLE ONLINE' -) AS w OPTION(RECOMPILE);" : @" SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;