Jam*_*ter 6 sql-server memory sql-server-2012 resource-governor
在过去的一年中,我们遇到了许多不同的查询同时失败并出现以下错误(或不同资源调控器组中的变体)的情况:资源池“默认”中的系统内存不足,无法运行此错误询问。
最近我们越来越频繁地遇到它。关于导致问题的原因以及如何解决的任何想法?
@@version 返回:
Microsoft SQL Server 2012 (SP3) (KB3072779) - 11.0.6020.0 (X64) 2015 年 10 月 20 日 15:36:27 版权所有 (c) Microsoft Corporation 企业版:Windows NT 6.1(内部版本 7601)上的基于核心的许可(64 位) : 服务包 1)
全部同时发生的示例错误:
Error: 701, Severity: 17, State: 54.
There is insufficient system memory in resource pool 'default' to run this query.
Error: 701, Severity: 17, State: 123.
There is insufficient system memory in resource pool 'dm' to run this query.
Error: 701, Severity: 17, State: 89.
There is insufficient system memory in resource pool 'default' to run this query.
Error: 701, Severity: 17, State: 123.
There is insufficient system memory in resource pool 'default' to run this query.
Error: 701, Severity: 17, State: 123.
There is insufficient system memory in resource pool 'default' to run this query.
Error: 701, Severity: 17, State: 123.
There is insufficient system memory in resource pool 'dm' to run this query.
Error: 701, Severity: 17, State: 123.
Run Code Online (Sandbox Code Playgroud)
日志中的内存值:
Buffer Pool Value
---------------------------------------- ----------
Database 8489253
Simulated 1367796
Target 9508783
Dirty 868368
In IO 1744
Latched 6720
Page Life Expectancy 12
Procedure Cache Value
---------------------------------------- ----------
TotalProcs 435
TotalPages 22156
InUsePages 9414
Global Memory Objects Pages
---------------------------------------- ----------
Resource 5696
Locks 497346
XDES 3161
DirtyPageTracking 32
SETLS 32
SubpDesc Allocators 68
SE SchemaManager 2481
SE Column Metadata Cache 6414
SE Column Metadata Cache Store 6
SQLCache 442
Replication 2
ServerGlobal 72
XP Global 2
SortTables 3
Query Memory Objects (internal) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 492067
Current Max 492067
Future Max 492067
Physical Max 16549102
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (internal) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 25898
Current Max 25898
Future Max 25898
Remote Query Memory Objects (internal) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 8274551
Current Max 8274551
Query Memory Objects (default) Value
---------------------------------------- ----------
Grants 22
Waiting 2
Available 0
Current Max 14706463
Future Max 13657740
Physical Max 15954870
Next Request 482
Waiting For 723
Cost 6
Timeout 157
Wait Time 484
Small Query Memory Objects (default) Value
---------------------------------------- ----------
Grants 3
Waiting 0
Available 122428
Current Max 122880
Future Max 122880
Remote Query Memory Objects (default) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 7977435
Current Max 7977435
Query Memory Objects (fm) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 49206
Current Max 49206
Future Max 49206
Physical Max 1654911
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (fm) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 2589
Current Max 2589
Future Max 2589
Remote Query Memory Objects (fm) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 827455
Current Max 827455
Query Memory Objects (dm) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 477304
Current Max 477304
Future Max 477304
Physical Max 16052629
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (dm) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 25121
Current Max 25121
Future Max 25121
Remote Query Memory Objects (dm) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 8026314
Current Max 8026314
Query Memory Objects (J) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 477304
Current Max 477304
Future Max 477304
Physical Max 16052629
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (J) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 25121
Current Max 25121
Future Max 25121
Remote Query Memory Objects (J) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 8026314
Current Max 8026314
Query Memory Objects (c) Value
---------------------------------------- ----------
Grants 2
Waiting 0
Available 0
Current Max 303105
Future Max 269810
Physical Max 1643300
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (c) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 14200
Current Max 14200
Future Max 14200
Remote Query Memory Objects (c) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 821650
Current Max 821650
Query Memory Objects (d8) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 472388
Current Max 472388
Future Max 472388
Physical Max 15887138
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (d8) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 24862
Current Max 24862
Future Max 24862
Remote Query Memory Objects (d8) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 7943569
Current Max 7943569
Query Memory Objects (d4) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 472388
Current Max 472388
Future Max 472388
Physical Max 15887138
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (d4) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 24862
Current Max 24862
Future Max 24862
Remote Query Memory Objects (d4) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 7943569
Current Max 7943569
Query Memory Objects (b) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 49206
Current Max 49206
Future Max 49206
Physical Max 1654911
Next Request 0
Waiting For 0
Cost 0
Timeout 0
Wait Time 0
Small Query Memory Objects (b) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 2589
Current Max 2589
Future Max 2589
Remote Query Memory Objects (b) Value
---------------------------------------- ----------
Grants 0
Waiting 0
Available 827455
Current Max 827455
Optimization Queue (internal) Value
---------------------------------------- ----------
Overall Memory 144834560000
Target Memory 4526080000
Last Notification 0
Timeout 6
Early Termination Factor 5
Small Gateway (internal) Value
---------------------------------------- ----------
Configured Units 128
Available Units 128
Acquires 0
Waiters 0
Threshold Factor 380000
Threshold 380000
Medium Gateway (internal) Value
---------------------------------------- ----------
Configured Units 32
Available Units 32
Acquires 0
Waiters 0
Threshold Factor 12
Threshold -1
Big Gateway (internal) Value
---------------------------------------- ----------
Configured Units 1
Available Units 1
Acquires 0
Waiters 0
Threshold Factor 8
Threshold -1
Optimization Queue (default) Value
---------------------------------------- ----------
Overall Memory 140489523200
Target Memory 4390297600
Last Notification 0
Timeout 6
Early Termination Factor 5
Small Gateway (default) Value
---------------------------------------- ----------
Configured Units 128
Available Units 124
Acquires 4
Waiters 0
Threshold Factor 380000
Threshold 380000
Medium Gateway (default) Value
---------------------------------------- ----------
Configured Units 32
Available Units 32
Acquires 0
Waiters 0
Threshold Factor 12
Threshold 91464533
Big Gateway (default) Value
---------------------------------------- ----------
Configured Units 1
Available Units 1
Acquires 0
Waiters 0
Threshold Factor 8
Threshold -1
Optimization Queue (fm) Value
---------------------------------------- ----------
Overall Memory 14483456000
Target Memory 452608000
Last Notification 0
Timeout 6
Early Termination Factor 5
Small Gateway (fm) Value
---------------------------------------- ----------
Configured Units 128
Available Units 128
Acquires 0
Waiters 0
Threshold Factor 380000
Threshold 380000
Medium Gateway (fm) Value
---------------------------------------- ----------
Configured Units 32
Available Units 32
Acquires 0
Waiters 0
Threshold Factor 12
Threshold -1
Big Gateway (fm) Value
---------------------------------------- ----------
Configured Units 1
Available Units 1
Acquires 0
Waiters 0
Threshold Factor 8
Threshold -1
Optimization Queue (dm) Value
---------------------------------------- ----------
Overall Memory 140489523200
Target Memory 4390297600
Last Notification 0
Timeout 6
Early Termination Factor 5
Small Gateway (dm
从你发布的输出我可以看到
MEMORYCLERK_SQLQERESERVATIONS 39874 (MB)
Run Code Online (Sandbox Code Playgroud)
价值是38G,很大。为什么 SQL Server 操作(排序和哈希)需要这么多内存
什么是 SQLRESERVATION
SQL Server 在查询执行期间为排序和哈希操作分配的内存。你真的认为 38G 是排序和哈希操作所需要的吗?这就是问题。
查看您的资源调控器配置
CREATE WORKLOAD GROUP [fm] WITH(GROUP_MAX_REQUESTS=0,
IMPORTANCE=HIGH,
REQUEST_MAX_CPU_TIME_SEC=0,
REQUEST_MAX_MEMORY_GRANT_PERCENT=100,
REQUEST_MEMORY_GRANT_TIMEOUT_SEC=0,
MAX_DOP=8) USING [fm]
GO
Run Code Online (Sandbox Code Playgroud)
看看REQUEST_MAX_MEMORY_GRANT_PERCENT=100现在这对我来说似乎是一个非常错误的配置。根据BOL文件
REQUEST_MAX_MEMORY_GRANT_PERCENT = value 指定单个请求可以从池中获取的最大内存量。该百分比相对于 MAX_MEMORY_PERCENT 指定的资源池大小
因此,这意味着当查询在此工作负载上运行时,它们可以ALL
通过迫使其他人缺乏内存来请求几乎内存作为执行的内存授予。这肯定会导致 OOM 错误。
微软进一步说的是
我们不建议将值设置为大于 70,因为如果正在运行其他并发查询,服务器可能无法留出足够的可用内存。这最终可能会导致查询超时错误 8645
您还可以分享一下输出吗
select total_request_count,blocked_task_count,max_request_grant_memory_kb,requested
from sys.dm_resource_governor_workload_groups
SELECT mg.granted_memory_kb, mg.session_id, t.text, qp.query_plan
FROM sys.dm_exec_query_memory_grants AS mg
CROSS APPLY sys.dm_exec_sql_text(mg.sql_handle) AS t
CROSS APPLY sys.dm_exec_query_plan(mg.plan_handle) AS qp
ORDER BY 1 DESC OPTION (MAXDOP 1)
USE master
GO
;WITH cte
AS ( SELECT RP.pool_id ,
RP.Name ,
RP.min_memory_percent ,
RP.max_memory_percent ,
CAST (RP.max_memory_kb / 1024. / 1024.
AS NUMERIC(12, 2)) AS max_memory_gb ,
CAST (RP.used_memory_kb / 1024. / 1024.
AS NUMERIC(12, 2)) AS used_memory_gb ,
CAST (RP.target_memory_kb / 1024. / 1024.
AS NUMERIC(12,2)) AS target_memory_gb,
CAST (SI.committed_target_kb / 1024. / 1024.
AS NUMERIC(12, 2)) AS committed_target_kb
FROM sys.dm_resource_governor_resource_pools RP
CROSS JOIN sys.dm_os_sys_info SI
)
SELECT c.pool_id ,
c.Name ,
c.min_memory_percent ,
c.max_memory_percent ,
c.max_memory_gb ,
c.used_memory_gb ,
c.target_memory_gb ,
CAST(c.committed_target_kb *
CASE WHEN c.committed_target_kb <= 8 THEN 0.7
WHEN c.committed_target_kb < 16 THEN 0.75
WHEN c.committed_target_kb < 32 THEN 0.8
WHEN c.committed_target_kb <= 96 THEN 0.85
WHEN c.committed_target_kb > 96 THEN 0.9
END * c.max_memory_percent /100 AS NUMERIC(12,2))
AS [Max_for_InMemory_Objects_gb]
FROM cte c
Run Code Online (Sandbox Code Playgroud)
编辑:
从您发布的输出中
total_request_count blocked_task_count max_request_grant_memory_kb
-------------------- ------------------ ---------------------------
553 0 18000
1633564 0 19344744
0 0 0
89509 0 23448232
2073 0 8032
24999 0 4485384
861807 0 3149248
236419 0 32241240
293 0 32241240
1735195 0 1889544
Run Code Online (Sandbox Code Playgroud)
现在您可以看到您的工作组处理了如此多的请求,并看到他们请求的内存量范围从 19G 到 32 G。这可能是一个问题,请求大量内存授予的查询可能会剥夺其他人的内存,并记录内存工作组不会被共享。
您还可以看到
granted_memory_kb session_id
-------------------- ----------
19344744 210
Run Code Online (Sandbox Code Playgroud)
会话 ID 210 被授予 19G 内存。这是错误。只需考虑一个场景,如果 5-10 个这样的查询开始运行。
您还可以添加输出
select pool_id,cache_memory_kb,used_memory_kb,out_of_memory_count,used_memgrant_kb from sys.dm_resource_governor_resource_pools
Run Code Online (Sandbox Code Playgroud)