不重启释放MSSqlServer内存
----自动强制释放内存的SQL脚本 DECLARE @TargetMemory decimal(19,2),@TotalMemory decimal(19,2),@UseMemoryPecent decimal(19,2) SELECT @TargetMemory=cntr_value FROM sys.dm_os_performance_counters WHERE counter_name='Target Server Memory (KB)' SELECT @TotalMemory=cntr_value FROM sys.dm_os_performance_counters WHERE counter_name='Total Server Memory (KB)' SET @UseMemoryPecent=@TotalMemory/@TargetMemory SELECT @UseMemoryPecent IF @UseMemoryPecent>0.5 BEGIN --清除存储过程缓存 DBCC FREEPROCCACHE --清除会话缓存 DBCC FREESESSIONCACHE --清除系统缓存 DBCC FREESYSTEMCACHE('All') --清除所有缓存 DBCC DROPCLEANBUFFERS --打开高级配置 EXEC sp_configure 'show advanced options', 1 --设置最大内存值,清除现有缓存空间 100000 M (根据实际情况设置,具体思路是最大值先调小,然后再设回合适的值。) EXEC sp_configure 'max server memory', 100000 EXEC ('RECONFIGURE') --设置等待时间,强制释放内存需等待一些时间 WAITFOR DELAY '00:20:00' --重新设置最大内存值 236000 M 根据实际情况设置,具体思路是最大值先调小,然后再设回合适的值。) EXEC sp_configure 'max server memory', 236000 EXEC ('RECONFIGURE') --关闭高级配置 EXEC sp_configure 'show advanced options', 0 END