Sql server sql server会占用内存,但完成后不会释放内存

Sql server sql server会占用内存,但完成后不会释放内存,sql-server,memory,memory-leaks,Sql Server,Memory,Memory Leaks,在SQLServerManagementStudio中,我运行了一个复杂的SELECT语句,运行该语句需要10分钟。它在我们的服务器上消耗10gb内存。问题是当SELECT语句完成时,它不会释放内存。我们可以将MAX SERVER MEMORY设置为某个特定的内存,但我们想要的是它可以消耗服务器中所有可用的内存,当处理完成时,它应该释放内存 我相信这是内存泄漏,但我不相信SQL SERVER中存在这样的问题。有什么解释吗?SQL server倾向于将所有可用内存占用到配置的最大内存,然后才将部分

在SQLServerManagementStudio中,我运行了一个复杂的SELECT语句,运行该语句需要10分钟。它在我们的服务器上消耗10gb内存。问题是当SELECT语句完成时,它不会释放内存。我们可以将MAX SERVER MEMORY设置为某个特定的内存,但我们想要的是它可以消耗服务器中所有可用的内存,当处理完成时,它应该释放内存


我相信这是内存泄漏,但我不相信SQL SERVER中存在这样的问题。有什么解释吗?

SQL server倾向于将所有可用内存占用到配置的最大内存,然后才将部分内存释放给自己。我发现的“处理此问题”的唯一方法是将最大内存设置为我希望引擎使用的最大内存量。

SQL server倾向于占用所有可用内存,直到配置的最大内存为止,然后才将部分内存释放给自己。我发现“处理此问题”的唯一方法是将最大内存设置为我希望引擎使用的最大内存量。

当查询SQL Server时,它将数据页中的信息读取到缓冲区缓存中,以便后续读取可以直接进入内存并避免磁盘读取:这就是设计。要找出缓冲区缓存中的内容并确认这是导致所看到内容的原因,您可以发出:

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

(摘自此答案:)

当您查询SQL Server时,它会将数据页中的信息读取到缓冲区缓存中,以便后续读取可以直接进入内存并避免磁盘读取:这就是设计。要找出缓冲区缓存中的内容并确认这是导致所看到内容的原因,您可以发出:

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

(摘自此答案:)

限制此设置的唯一方法是设置最大内存。 这不是内存泄漏。这就是SQL Server的工作方式。 它使用内存进行缓存

如果您认为SQL Server通常在专用服务器上运行,那么这并不是错的


我没有试过,但很可能DBCC FREEPROCCACHE也无法释放内存(这很危险)。

限制这一点的唯一方法是设置最大内存。 这不是内存泄漏。这就是SQL Server的工作方式。 它使用内存进行缓存

如果您认为SQL Server通常在专用服务器上运行,那么这并不是错的

我没有尝试过,但可能甚至DBCC FREEPROCCACHE都无法释放内存(这很危险)。

检查此定义“完成”:我确信它在停止时返回内存。这就是服务器完成的时候。检查这个定义“它完成了”:我确信它在停止时返回内存。这就是服务器完成的时候。