我们遇到了一个问题,即扩展事件的内存使用量增长到超过 1 GB,然后将无法清除 - 即使我们停止了实例上的所有 XEvent 会话。这在大多数服务器上还不是问题,但它确实伤害了我们的一些较小的开发/测试服务器,只有几 GB 的内存分配给 SQL Server。我希望外面的人可能对如何解决这个问题有一些想法,而不是弹回 SQL Server。
一些相关的查询输出:
SELECT TOP 5 type
,NAME
,sum(pages_kb) / 1024 AS pages_mb
FROM sys.dm_os_memory_clerks
GROUP BY type
,NAME
ORDER BY sum(pages_kb) DESC
------------------------------
type NAME pages_mb
MEMORYCLERK_XE XE Engine 1133
USERSTORE_TOKENPERM TokenAndPermUserStore 55
MEMORYCLERK_SOSNODE SOS_Node 43
MEMORYCLERK_SQLBUFFERPOOL Default 41
MEMORYCLERK_SQLGENERAL Default 18
------------------------------
SELECT NAME
,total_buffer_size / 1024 AS total_buffer_size_kb
FROM sys.dm_xe_sessions
ORDER BY total_buffer_size_kb DESC
------------------------------
name total_buffer_size_kb
system_health 4223
SpotlightResponseTimeWaitData_3843 4223
SpotlightWorkloadAnalysis_3843 4223
SpotlightDeadlockDetection_3843 4031
sp_server_diagnostics session 383
SELECT @@VERSION
Microsoft SQL Server 2012 (SP1) - 11.0.3437.0 (X64)
May 29 2014 16:03:40
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
全面披露——我们运行 Dell Spotlight for SQL Server,默认情况下在每个实例上打开三个 XEvents 会话。这 3 个会话的代码如下。
我什至在此实例上禁用了 Spotlight,删除了三个 XEvent Spotlight 会话,并停止了 system_health 会话。MEMORYCLERK_XE 内存使用量保持在 1120 MB。DBCC FREESYSTEMCACHE ('ALL') 也没有效果。
3 个聚光灯会议:
CREATE EVENT SESSION [SpotlightDeadlockDetection_3843] ON SERVER ADD EVENT sqlserver.xml_deadlock_report ADD TARGET package0.ring_buffer (SET occurrence_number = (0))
WITH (
MAX_MEMORY = 4000 KB
,EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS
,MAX_DISPATCH_LATENCY = 10 SECONDS
,MAX_EVENT_SIZE = 0 KB
,MEMORY_PARTITION_MODE = NONE
,TRACK_CAUSALITY = OFF
,STARTUP_STATE = OFF
)
GO
CREATE EVENT SESSION [SpotlightResponseTimeWaitData_3843] ON SERVER ADD EVENT sqlos.wait_info (
ACTION(package0.collect_system_time, sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.plan_handle, sqlserver.query_hash, sqlserver.query_plan_hash, sqlserver.session_id, sqlserver.sql_text, sqlserver.username) WHERE (
[opcode] = (1)
AND (
[duration] > (0)
OR [signal_duration] > (0)
)
AND [sqlserver].[query_hash] <> (0)
AND [package0].[counter] <= (1000)
AND [wait_type] <> (214)
)
)
,ADD EVENT sqlos.wait_info_external (
ACTION(package0.collect_system_time, sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.plan_handle, sqlserver.query_hash, sqlserver.query_plan_hash, sqlserver.session_id, sqlserver.sql_text, sqlserver.username) WHERE (
[opcode] = (1)
AND [duration] > (0)
AND [sqlserver].[query_hash] <> (0)
AND [package0].[counter] <= (1000)
AND [wait_type] <> (589)
)
) ADD TARGET package0.ring_buffer (
SET max_events_limit = (4000)
,occurrence_number = (1000)
)
WITH (
MAX_MEMORY = 4096 KB
,EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS
,MAX_DISPATCH_LATENCY = 30 SECONDS
,MAX_EVENT_SIZE = 0 KB
,MEMORY_PARTITION_MODE = NONE
,TRACK_CAUSALITY = ON
,STARTUP_STATE = OFF
)
GO
CREATE EVENT SESSION [SpotlightWorkloadAnalysis_3843] ON SERVER ADD EVENT sqlserver.sp_statement_completed (
ACTION(sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.plan_handle, sqlserver.session_id, sqlserver.sql_text, sqlserver.username) WHERE (
[sqlserver].[is_system] = (0)
AND [package0].[counter] <= (1000)
)
)
,ADD EVENT sqlserver.sql_statement_completed (
ACTION(sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name, sqlserver.plan_handle, sqlserver.session_id, sqlserver.sql_text, sqlserver.username) WHERE (
[sqlserver].[is_system] = (0)
AND [package0].[counter] <= (1000)
)
) ADD TARGET package0.ring_buffer (
SET max_events_limit = (4000)
,occurrence_number = (1000)
)
WITH (
MAX_MEMORY = 4096 KB
,EVENT_RETENTION_MODE = ALLOW_SINGLE_EVENT_LOSS
,MAX_DISPATCH_LATENCY = 30 SECONDS
,MAX_EVENT_SIZE = 0 KB
,MEMORY_PARTITION_MODE = NONE
,TRACK_CAUSALITY = ON
,STARTUP_STATE = OFF
)
GO
有谁知道可能是什么原因造成的?有什么办法可以释放这个用过的内存吗?
发布此问题并获得有关将 SQL Server 升级到最新 SP 的一些评论后,我找到了这篇知识库文章。文章中描述的行为似乎与我们所看到的非常相似。
我们继续并应用SP3 + CU3来获得我们可以获得的最新版本的 SQL 2012。
安装 SP 和 CU 后,问题似乎消失了。MEMORYCLERK_XE 的内存使用似乎已经稳定,删除 XEvent 会话会释放 MEMORYCLERK_XE 使用的所有内存。
我希望这能帮助其他人,因为它让我们摸不着头脑了很长一段时间。