Jon*_*ell 4 sql-server-2005 sql-server
我在 Windows 2003 R2 SP2 上安装了一个 SQL 2005 SP3 框。这个盒子有 64GB 的内存,启用了 AWE(和 boot.ini 中的 /PAE)以及内存中的锁定页面启用和最大服务器内存设置为 45GB。该服务器还有 32 个 CPU。
我们在日志中看到如下错误:
错误:701,严重性:17,状态:123。系统内存不足,无法运行此查询。
失败的虚拟分配字节:FAIL_VIRTUAL_RESERVE 65536
sql server 进程内存的很大一部分已被调出。这可能会导致性能下降。持续时间:0 秒。工作集 (KB):43160332,已提交 (KB):467644,内存利用率:45%。
对于 Virtual Reserve 错误,我发现这通常是 MemToLeave 默认为 256MB 引起的问题,因此我使用 -g 512 启动 SQL Server 以将其加倍,然后查看 Virtual Reserve 错误是否消失。由于该更改,SQL 服务立即在 24 小时内异常终止。所以我们现在再次使用默认值运行,它记录错误但不异常终止 SQL 服务。
如果我查看环形缓冲区 (sys.dm_os_ring_buffers),我会看到如下消息:
EventTime Type Indicators Avail Phys Mem, Kb Avail VAS, Kb Avail Phys Mem, Mb Avail VAS, Mb Avail Phys Mem, Gb Avail VAS, Gb
2012-06-19 10:37:54.063 RESOURCE_MEMPHYSICAL_LOW 2 19251252 126712 18800 123 18 0
2012-06-19 10:37:54.063 RESOURCE_MEM_STEADY 1 19251244 126392 18800 123 18 0
2012-06-19 10:37:38.063 RESOURCE_MEM_STEADY 0 19252512 127752 18801 124 18 0
2012-06-19 10:37:38.063 RESOURCE_MEMPHYSICAL_HIGH 1 19252512 127752 18801 124 18 0
2012-06-19 10:37:37.063 RESOURCE_MEMPHYSICAL_LOW 2 19250852 126344 18799 123 18 0
2012-06-19 10:37:27.063 RESOURCE_MEMPHYSICAL_LOW 2 19251028 126600 18799 123 18 0
2012-06-19 10:37:27.063 RESOURCE_MEM_STEADY 0 19251284 126856 18800 123 18 0
2012-06-19 10:37:27.063 RESOURCE_MEMPHYSICAL_HIGH 1 19251284 126856 18800 123 18 0
2012-06-19 10:37:23.063 RESOURCE_MEMPHYSICAL_LOW 2 19251208 126792 18800 123 18 0
2012-06-19 10:37:23.063 RESOURCE_MEM_STEADY 0 19251192 126728 18799 123 18 0
2012-06-19 10:37:23.063 RESOURCE_MEMPHYSICAL_HIGH 1 19251192 126728 18799 123 18 0
Run Code Online (Sandbox Code Playgroud)
正在登录环形缓冲区。这些消息几乎每秒都被放置在环形缓冲区中。
如果我运行在http://blogs.msdn.com/b/sqlsakthi/archive/2011/02/28/t-sql-script-to-monitor-memory-usage-by-sql-server- 上找到的内存查询instance.aspx我得到以下结果:
----------------------------------------------------------------------------------------------------
Memory usage details for SQL Server instance HOFSQL1AP (9.00.4053.00 - X86) - Enterprise Edition)
----------------------------------------------------------------------------------------------------
--------------------------------------
Memory visible to the Operating System
Physical Memory_MB Physical Memory_GB Virtual Memory GB
--------------------------------------- --------------------------------------- ---------------------------------------
65536 64 2
-------------------------------
Buffer Pool Usage at the Moment
BPool_Committed_MB BPool_Commit_Tgt_MB BPool_Visible_MB
--------------------------------------- --------------------------------------- ---------------------------------------
45056.000000 45056.000000 920.000000
---------------------------------------------------------------------------
Total Memory used by SQL Server Buffer Pool as reported by Perfmon counters
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- --------------------------- ------------
46137344 45056.000000 44.000000000
-------------------------------------------------------------
Memory needed as per current Workload for SQL Server instance
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
46137344 45056.000000 44.000000000
------------------------------------------------------------------------------
Total amount of dynamic memory the server is using for maintaining connections
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
16128 15.750000 0.015380859
------------------------------------------------------------
Total amount of dynamic memory the server is using for locks
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
11584 11.312500 0.011047363
----------------------------------------------------------------------------
Total amount of dynamic memory the server is using for the dynamic SQL cache
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
4592 4.484375 0.004379272
-------------------------------------------------------------------------
Total amount of dynamic memory the server is using for query optimization
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
6608 6.453125 0.006301879
-------------------------------------------------------------------------------
Total amount of dynamic memory used for hash, sort and create index operations.
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
119584 116.781250 0.114044189
------------------------------------------
Total Amount of memory consumed by cursors
Mem_KB Mem_MB Mem_GB
-------------------- --------------------------------------- ---------------------------------------
2989 2.918945 0.002850532
-------------------------------------------------------------------------
Number of pages in the buffer pool (includes database, free, and stolen).
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
5767168 46137344.000000 45056.000000000
---------------------------------------
Number of Data pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
5700255 45602040.000000 44533.242187500
---------------------------------------
Number of Free pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
8046 64368.000000 62.859375000
-------------------------------------------
Number of Reserved pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
14311 114488.000000 111.804687500
-----------------------------------------
Number of Stolen pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
58867 470936.000000 459.898437500
---------------------------------------------
Number of Plan Cache pages in the buffer pool
8KB_Pages Pages_in_KB Pages_in_MB
-------------------- --------------------------------------- ---------------------------------------
24712 197696.000000 193.062500000
-----------------------------------------------------------------------------------------------
Page Life Expectancy - Number of seconds a page will stay in the buffer pool without references
Page Life in seconds PLE Status
-------------------- ------------------
1054 PLE is Healthy
--------------------------------------------------------------
Number of requests per second that had to wait for a free page
Free list stalls/sec
--------------------
506909
-----------------------------------------------------------------------------------------------------------------
Number of pages flushed to disk/sec by a checkpoint or other operation that require all dirty pages to be flushed
Checkpoint pages/sec
--------------------
27495457
------------------------------------------------------------------------
Number of buffers written per second by the buffer manager"s lazy writer
Lazy writes/sec
--------------------
4862949
--------------------------------------------------------------
Total number of processes waiting for a workspace memory grant
Memory Grants Pending
---------------------
0
----------------------------------------------------------------------------------
Total number of processes that have successfully acquired a workspace memory grant
Memory Grants Outstanding
-------------------------
7
Run Code Online (Sandbox Code Playgroud)
我曾尝试诊断此问题并遇到砖墙。我现在唯一能想到的就是向社区提出请求,看看是否有人对我如何解决这些内存瓶颈有任何建议。
顺便提一句。我最初给操作系统分配了 10GB,给 SQL 缓冲池分配了 54GB。但是当这些错误开始出现时,我认为操作系统内存不足(因为我们的基础架构人员使用 Tivoli 代理进行监控和安装在机器上的备份),所以我通过减少对 SQL 的分配来增加操作系统分配。
谢谢
乔纳森·罗素
32 位进程中的 AWE 机制只能用于数据页(缓冲池)。它不能用于过程缓存、查询内存授权、执行堆栈、访问令牌缓存、CLR 等等等,基本上除了数据页之外的所有其他分配。所有这些分配(包括代码页)都必须塞满 2GB 的进程地址空间。
您唯一值得考虑的解决方案是迁移到 64 位操作系统上的 64 位 SQL Server 部署。其他一切都是浪费时间。
请参阅使用 AWE
SQL Server 缓冲池可以充分利用 AWE 映射内存;但是,只有数据库页可以动态映射到 SQL Server 的虚拟地址空间和从其取消映射,并充分利用通过 AWE 分配的内存。AWE 不直接帮助支持永久驻留在虚拟地址空间中的其他用户、线程、数据库、查询和其他对象。
我同意@RemusRusanu,迁移到 64 位几乎可以保证消除痛苦。
由于转移到 64 位可能不是您明天 JFDI 可以做到的,我倾向于在计划升级时投入更多时间进行调查。通过暂时缓解这个问题,您或许可以让自己的头脑浮出水面。
关于 32 位虚拟地址耗尽的好参考文章是如何找到谁正在使用/占用 SQL Server 上的虚拟地址空间。特别注意需要在缓冲池外分配的组件列表。我还会关注您提到的第 3 方监控/备份组件。
如果您有属于上述类别的边缘功能(非核心/很少使用的东西),那么您可以提出禁用或删除它的理由,直到您移动到 64 位。
通常,99.99% 可用性下的 80% 功能比 90% 可用性下的 100% 功能更重要。