Tho*_*mas 6 performance insert sql-server-2008-r2 cache
我的 SQL Server 2008 R2 实例有问题。上周的表现突然崩溃了。所有插入都非常非常缓慢。它需要比以前长4-5倍。在硬件上我们没有发现任何缺陷。一个月前我们遇到了同样的问题,但一周后问题消失得很快。
我不是这些方面的专家,但我注意到实例上所有数据库的性能都很差。CPU 和磁盘未达到极限,因此应该不是硬件性能问题。
我将使用此查询查看缓存页数:
select
count(*)as cached_pages_count,
obj.name as objectname,
ind.name as indexname,
obj.index_id as indexid
from sys.dm_os_buffer_descriptors as bd
inner join
(
select object_id as objectid,
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_id as objectid,
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.partition_id
and au.type = 2
) as obj
on bd.allocation_unit_id = obj.allocation_unit_id
left outer join sys.indexes ind
on obj.objectid = ind.object_id
and obj.index_id = ind.index_id
where bd.database_id = db_id()
and bd.page_type in ('data_page', 'index_page')
group by obj.name, ind.name, obj.index_id
order by cached_pages_count desc
Run Code Online (Sandbox Code Playgroud)
在这里我发现了非常高的值,但我不知道它是否坏。在不同的表和索引上,计数从 201.236 到 1。这可能是性能不佳的问题吗?
我注意到的另一件事是插入数据时的日志写入次数非常多。有了SELECT INTO ...
它,速度要快得多。
谁能给我一个提示,或者可以告诉我这个 cached_pages_count 到底是什么意思?
编辑:
我还提到了插入期间的高 waititme(最多 300.000 毫秒)Waittype isCXPACKET
和 wait ressource是e_waitPortOpen
and e_waitPipeNewRow
。高值出现在e_waitPortOpen
。
亲切的问候托马斯
听起来你的统计数据已经过时了,然后最终 SQL 的自动更新统计数据将启动并更新统计数据,正在生成正确的执行计划,然后一切都开始再次更快地运行。
如果您已经安装了 SQL Server 2008 R2 的 Service Pack 1,则可以打开跟踪标志 2371,这会将使用的算法从静态 20%+500 更改为根据表中行数变化的值。
如果您没有安装 Service Pack 1,那么我建议您设置一个每周或每晚为所有表运行 UPDATE STATISTICS 的作业。
归档时间: |
|
查看次数: |
3328 次 |
最近记录: |