SQL Server 内存使用情况
• 查看设置的最大与最小内存:
exec sp_configure 'max server memory (MB)'
exec sp_configure 'min server memory (MB)'
• SqlServer目标内存、当前内存 、数据库内存页数:
SELECT object_name,counter_name,cntr_value,cntr_value/1024/1024 AS [cntr_value(GB)]
FROM sys.dm_os_performance_counters
WHERE counter_name in('Target Server Memory (KB)','Total Server Memory (KB)','Database pages')
• 查看设置的最大与最小内存:
SELECT * FROM sys.dm_os_sys_info
SELECT * FROM sys.dm_os_sys_memory
SELECT * FROM sys.dm_os_process_memory
• 查看当前是否有等待内存授予的进程:
Select a.*,b.text, c.query_plan
from sys.dm_exec_query_memory_grants a
CROSS APPLY sys.dm_exec_sql_text(sql_handle) b
CROSS APPLY sys.dm_exec_query_plan (plan_handle) c
• SqlServer预留和提交内存情况:
SELECT [type]
,SUM(virtual_memory_reserved_kb) AS [vm reserved]
,SUM(virtual_memory_committed_kb) AS [vm commited]
,SUM(awe_allocated_kb) AS [awe allocated]
,SUM(shared_memory_reserved_kb) AS [sm reserved]
,SUM(shared_memory_committed_kb) AS [sm committed]
,SUM(single_pages_kb) AS [Stolen in Buffer Pool]
,SUM(multi_pages_kb) AS [MemToLeave]
,SUM(single_pages_kb) + SUM(multi_pages_kb) AS [Stolen]
,SUM(virtual_memory_committed_kb) + SUM(multi_pages_kb) AS [Buffer Pool]
FROM sys.dm_os_memory_clerks
GROUP BY [type]
ORDER BY [type] desc
• 当前各数据库buffer pool的分配情况:
SELECT
CASE database_id
WHEN 32767 THEN 'ResourceDb'
ELSE db_name(database_id) END AS Database_name
,count(*) AS cached_pages_count
,count(*)*8/1024 AS cached_space_in_mb
,sum(convert(bigint,free_space_in_bytes))/1024/1024 AS free_space_in_mb
FROM sys.dm_os_buffer_descriptors(nolock)
GROUP BY db_name(database_id) ,database_id
ORDER BY cached_pages_count DESC;
• 当前数据库各表buffer pool的分配情况:
SELECT top(20) name ,index_id ,count(*)AS cached_pages_count
,count(*)*8/1024 AS cached_space_in_mb
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN (
SELECT object_name(object_id) AS name ,index_id ,allocation_unit_id
FROM sys.allocation_units AS au INNER JOIN sys.partitions AS p
ON au.container_id = p.hobt_id AND (au.type = 1 OR au.type = 3 )
UNION ALL
SELECT object_name(object_id) AS name,index_id, allocation_unit_id
FROM sys.allocation_units AS au INNER JOIN sys.partitions AS p
ON au.container_id = p.hobt_id AND au.type = 2
) AS obj ON bd.allocation_unit_id = obj.allocation_unit_id
WHERE database_id = db_id() AND obj.name NOT LIKE 'sys%'
GROUP BY name, index_id
ORDER BY cached_pages_count DESC
• 当前各表或索引在缓冲池中的页数量及大小:
SELECT obj.name ,obj.index_id,i.name ,count(*)AS cached_pages_count ,count(*)*8/1024 AS cached_space_in_mb
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN (
SELECT object_name(object_id) AS name,object_id,index_id ,allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p ON au.container_id = p.hobt_id AND (au.type = 1 OR au.type = 3)
UNION ALL
SELECT object_name(object_id) AS name,object_id,index_id, allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p ON au.container_id = p.partition_id AND au.type = 2
) AS obj ON bd.allocation_unit_id = obj.allocation_unit_id
LEFT JOIN sys.indexes i(nolock) on obj.object_id = i.object_id AND obj.index_id = i.index_id
WHERE database_id = db_id() AND obj.name NOT LIKE 'sys%'
GROUP BY obj.name ,obj.index_id,i.name
ORDER BY cached_pages_count DESC;
• 统计当前内存分配情况 :
select
physical_memory_in_bytes / 1024 / 1024 as physical_memory_mb,
virtual_memory_in_bytes / 1024 / 1024 as virtual_memory_mb,
bpool_committed * 8 / 1024 as bpool_committed_mb,
bpool_commit_target * 8 / 1024 as bpool_target_mb,
bpool_visible * 8 / 1024 as bpool_visible_mb
from sys.dm_os_sys_info
• 当前内存脏页数量及大小 :
SELECT db_name(database_id) AS 'Database'
,count(page_id) AS 'Dirty Pages'
,count(page_id)*8/1024 AS 'Dirty Pages(MB)'
FROM sys.dm_os_buffer_descriptors(nolock)
WHERE is_modified =1
GROUP BY db_name(database_id)
ORDER BY 'Dirty Pages' DESC
• 缓存类型数量大小 :
select cacheobjtype as [Cached Type]
,COUNT(*) [Number of Plans]
,SUM(CONVERT(BIGINT,size_in_bytes))/1024/1024 [Plan Cache Size(MB)]
from sys.dm_exec_cached_plans
group by cacheobjtype
order by [Plan Cache Size(MB)] desc
• 缓存对象数量大小 :
select objtype as [Cached Object Type]
,COUNT(*) as [Number of Plans]
,SUM(CONVERT(BIGINT,size_in_bytes))/1024/1024 [Plan Cache Size(MB)]
,avg(usecounts) [Avg Use Count]
from sys.dm_exec_cached_plans
group by objtype
order by [Plan Cache Size(MB)] desc
• 内存对象 :
SELECT top 10 * FROM sys.dm_os_memory_cache_counters(nolock)
ORDER BY entries_count DESC; SELECT * FROM sys.dm_os_memory_clerks a
WHERE name='TokenAndPermUserStore' SELECT * FROM sys.dm_os_memory_cache_entries(nolock)
WHERE [type]='USERSTORE_TOKENPERM' and name='TokenAndPermUserStore'
• 缓存分析对象 :
SELECT * FROM sys.syscacheobjects
SELECT * FROM sys.dm_exec_cached_plans
• 即时查询优化(运行即生效) :
EXEC sp_configure 'show advanced options',1
RECONFIGURE
EXEC sp_configure 'optimize for ad hoc workloads',1
RECONFIGURE
all code :
--查看设置的最大最小每次
exec sp_configure 'max server memory (MB)'
exec sp_configure 'min server memory (MB)' --SqlServer目标内存、当前内存 、数据库内存页数
SELECT object_name,counter_name,cntr_value,cntr_value/1024/1024 AS [cntr_value(GB)]
FROM sys.dm_os_performance_counters
WHERE counter_name in('Target Server Memory (KB)','Total Server Memory (KB)','Database pages') --系统物理内存使用情况
SELECT * FROM sys.dm_os_sys_info
SELECT * FROM sys.dm_os_sys_memory
SELECT * FROM sys.dm_os_process_memory --查看当前是否有等待内存授予的进程
Select a.*,b.text, c.query_plan
from sys.dm_exec_query_memory_grants a
CROSS APPLY sys.dm_exec_sql_text(sql_handle) b
CROSS APPLY sys.dm_exec_query_plan (plan_handle) c --SqlServer预留和提交内存情况
DBCC MEMORYSTATUS; --旧的方法 SELECT [type]
,SUM(virtual_memory_reserved_kb) AS [vm reserved]
,SUM(virtual_memory_committed_kb) AS [vm commited]
,SUM(awe_allocated_kb) AS [awe allocated]
,SUM(shared_memory_reserved_kb) AS [sm reserved]
,SUM(shared_memory_committed_kb) AS [sm committed]
,SUM(single_pages_kb) AS [Stolen in Buffer Pool]
,SUM(multi_pages_kb) AS [MemToLeave]
,SUM(single_pages_kb) + SUM(multi_pages_kb) AS [Stolen]
,SUM(virtual_memory_committed_kb) + SUM(multi_pages_kb) AS [Buffer Pool]
FROM sys.dm_os_memory_clerks
GROUP BY [type]
ORDER BY [type] desc --当前各数据库buffer pool的分配情况
SELECT
CASE database_id
WHEN 32767 THEN 'ResourceDb'
ELSE db_name(database_id) END AS Database_name
,count(*) AS cached_pages_count
,count(*)*8/1024 AS cached_space_in_mb
,sum(convert(bigint,free_space_in_bytes))/1024/1024 AS free_space_in_mb
FROM sys.dm_os_buffer_descriptors(nolock)
GROUP BY db_name(database_id) ,database_id
ORDER BY cached_pages_count DESC; --当前数据库各表buffer pool的分配情况
SELECT top(20) name ,index_id ,count(*)AS cached_pages_count
,count(*)*8/1024 AS cached_space_in_mb
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN (
SELECT object_name(object_id) AS name ,index_id ,allocation_unit_id
FROM sys.allocation_units AS au INNER JOIN sys.partitions AS p
ON au.container_id = p.hobt_id AND (au.type = 1 OR au.type = 3 )
UNION ALL
SELECT object_name(object_id) AS name,index_id, allocation_unit_id
FROM sys.allocation_units AS au INNER JOIN sys.partitions AS p
ON au.container_id = p.hobt_id AND au.type = 2
) AS obj ON bd.allocation_unit_id = obj.allocation_unit_id
WHERE database_id = db_id() AND obj.name NOT LIKE 'sys%'
GROUP BY name, index_id
ORDER BY cached_pages_count DESC -- 当前各表或索引在缓冲池中的页数量及大小
SELECT obj.name ,obj.index_id,i.name ,count(*)AS cached_pages_count ,count(*)*8/1024 AS cached_space_in_mb
FROM sys.dm_os_buffer_descriptors AS bd
INNER JOIN (
SELECT object_name(object_id) AS name,object_id,index_id ,allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p ON au.container_id = p.hobt_id AND (au.type = 1 OR au.type = 3)
UNION ALL
SELECT object_name(object_id) AS name,object_id,index_id, allocation_unit_id
FROM sys.allocation_units AS au
INNER JOIN sys.partitions AS p ON au.container_id = p.partition_id AND au.type = 2
) AS obj ON bd.allocation_unit_id = obj.allocation_unit_id
LEFT JOIN sys.indexes i(nolock) on obj.object_id = i.object_id AND obj.index_id = i.index_id
WHERE database_id = db_id() AND obj.name NOT LIKE 'sys%'
GROUP BY obj.name ,obj.index_id,i.name
ORDER BY cached_pages_count DESC; -- 统计当前内存分配情况
select
physical_memory_in_bytes / 1024 / 1024 as physical_memory_mb,
virtual_memory_in_bytes / 1024 / 1024 as virtual_memory_mb,
bpool_committed * 8 / 1024 as bpool_committed_mb,
bpool_commit_target * 8 / 1024 as bpool_target_mb,
bpool_visible * 8 / 1024 as bpool_visible_mb
from sys.dm_os_sys_info --当前内存脏页数量及大小
SELECT db_name(database_id) AS 'Database'
,count(page_id) AS 'Dirty Pages'
,count(page_id)*8/1024 AS 'Dirty Pages(MB)'
FROM sys.dm_os_buffer_descriptors(nolock)
WHERE is_modified =1
GROUP BY db_name(database_id)
ORDER BY 'Dirty Pages' DESC --缓存类型数量大小
select cacheobjtype as [Cached Type]
,COUNT(*) [Number of Plans]
,SUM(CONVERT(BIGINT,size_in_bytes))/1024/1024 [Plan Cache Size(MB)]
from sys.dm_exec_cached_plans
group by cacheobjtype
order by [Plan Cache Size(MB)] desc --缓存对象数量大小
select objtype as [Cached Object Type]
,COUNT(*) as [Number of Plans]
,SUM(CONVERT(BIGINT,size_in_bytes))/1024/1024 [Plan Cache Size(MB)]
,avg(usecounts) [Avg Use Count]
from sys.dm_exec_cached_plans
group by objtype
order by [Plan Cache Size(MB)] desc --内存对象
SELECT top 10 * FROM sys.dm_os_memory_cache_counters(nolock)
ORDER BY entries_count DESC; SELECT * FROM sys.dm_os_memory_clerks a
WHERE name='TokenAndPermUserStore' SELECT * FROM sys.dm_os_memory_cache_entries(nolock)
WHERE [type]='USERSTORE_TOKENPERM' and name='TokenAndPermUserStore' --缓存分析对象
SELECT * FROM sys.syscacheobjects
SELECT * FROM sys.dm_exec_cached_plans --即时查询优化(运行即生效)
EXEC sp_configure 'show advanced options',1
RECONFIGURE
EXEC sp_configure 'optimize for ad hoc workloads',1
RECONFIGURE
SQL Server 内存使用情况的更多相关文章
- sql server内存使用情况
查看Sql Server 数据库的内存使用情况 转自:https://www.cnblogs.com/wanghao4023030/p/8299478.html DBCC MemoryStatu ...
- SQL Server内存遭遇操作系统进程压榨案例
场景: 最近一台DB服务器偶尔出现CPU报警,我的邮件报警阈(请读yù)值设置的是15%,开始时没当回事,以为是有什么统计类的查询,后来越来越频繁. 探索: 我决定来查一下,究竟是什么在作怪,我排查的 ...
- SQL SERVER 内存分配及常见内存问题 简介
一.问题: 1.SQL Server 所占用内存数量从启动以后就不断地增加: 首先,作为成熟的产品,内存溢出的机会微乎其微.对此要了解SQL SERVER与windows是如何协调.共享内存.并且SQ ...
- SQL SERVER 内存分配及常见内存问题(1)——简介
原文:SQL SERVER 内存分配及常见内存问题(1)--简介 一.问题: 1.SQL Server 所占用内存数量从启动以后就不断地增加: 首先,作为成熟的产品,内存溢出的机会微乎其微.对此要了解 ...
- (转)SQL Server内存遭遇操作系统进程压榨案例
原文地址:http://www.cnblogs.com/zc_0101/p/3592259.html 场景: 最近一台DB服务器偶尔出现CPU报警,我的邮件报警阈(请读yù)值设置的是15%,开始时没 ...
- Sql Server 内存相关计数器以及内存压力诊断
在数据库服务器中,内存是数据库对外提供服务最重要的资源之一, 不仅仅是Sql Server,包括其他数据库,比如Oracle,MySQL等,都是一类非常喜欢内存的应用. 在Sql Server服务器中 ...
- SQL SERVER 内存学习系列(二)-DMV查看内存信息
内存管理在SQL Server中有一个三级结构.底部是内存节点,这是最低级的分配器,用于SQL Server的内存.第二个层次是由内存Clerk组成,这是用来访问内存节点和缓存存储,缓存存储则用于缓存 ...
- SQL SERVER 内存学习系列(一)
最近帮客户解决发布订阅的问题时,突然遇到这样一个问题发布订阅中报下面的错误,另外执行alter table 操作时也会报错 : 问题很奇怪发布订阅和CLR有什么关系?memtoleave内存是个啥?回 ...
- 人人都是 DBA(IV)SQL Server 内存管理
SQL Server 的内存管理是一个庞大的主题,涉及特别多的概念和技术,例如常见的 Plan Cache.Buffer Pool.Memory Clerks 等.本文仅是管中窥豹,描述常见的内存管理 ...
随机推荐
- 智能家居控制APPUI界面设计
2017年,随着智能化产业进入新的市场格局,千家品牌实验室也迎来全新的升级,致力为智能产业生态链提供更全更新更深度的行业分析和品牌数据监测服务.本文为大家带来关于中国智能家居行业发展APP设计欣赏. ...
- Domain=NSOSStatusErrorDomain Code=1937337955 关于iOS录音AVAudioRecorder与音频播放AVAudioPlayer真机调试录音不能播放的问题
error:Domain=NSOSStatusErrorDomain Code=1937337955 ,这个错误很常见, 原因是因为我们需要调用另外一个AVAudioPlayer 的初始化方法,来确定 ...
- 【Oracle】三种方式查看SQL语句的执行计划
查看执行计划的方式有三种: EXPLAIN PLAN .V$SQL_PLAN .SQL*PLUS AUTOTRACE 1.EXPLAIN PLAN: 显示执行相应语句时可以使用的理论计划 读取执行计划 ...
- C#操作Oracle数据库中文乱码问题解决
最近公司有一个对外项目,采用的是oracle数据库,以前做的项目基本都是SQLserver,有和oracle对接的也就一些简单的增删查改. 还巧合的遇到乱码问题,网上各种查找,筛选,总算是把问题解决了 ...
- JavaScript是按引用传递or值传递?
今遇js基础类型等问题,已经有点模糊,遂作总结. 前言: JavaScript原始类型:Undefined.Null.Boolean.Number.String.Symbol JavaScript引用 ...
- mysql_connect() 不支持 请检查 mysql 模块是否正确加载
php的扩展 没有配置好! 打开php.ini文件: 搜索pdo_mysql和curl ;extension=php_curl.dll ;extension=pdo_mysql.dll 然后把2者前面 ...
- css超出不换行可滑动
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name ...
- MySQL基础:安装
概述 数据库(Database)是按照数据结构来组织.存储和管理数据的仓库,它产生于距今六十多年前,随着信息技术和市场的发展,特别是二十世纪九十年代以后,数据管理不再仅仅是存储和管理数据,而转变成用户 ...
- 在使用SSH+JPA开发中,ajax使用ObjectMapper类从后台向前台传值
使用ObjectMapper对象的writeValue方法 ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValu ...
- FactoryBean简介
网上看了很多关于FactoryBean和BeanFactory的介绍,总感觉说的不够简单.直白,今天用自己的语言来描述下,如果有不对的地方,还请大家指正. 1. FactoryBean和BeanFac ...