1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| . /etc/profile
sessionNum=`osql -E -S . -Q "select count(1) from sys.dm_exec_sessions where status!='sleeping'" | sed -n 3p | tr -d [:blank:] | tr -d [:cntrl:]`
if [ `expr $sessionNum` -ne 1 ]; then echo "存在正在执行的sql server会话,取消释放内存"; exit 0; fi
osql -E -S . -Q " DBCC FREEPROCCACHE DBCC FREESESSIONCACHE DBCC FREESYSTEMCACHE('All') DBCC DROPCLEANBUFFERS
USE master
-- 打开高级设置配置 EXEC sp_configure 'show advanced options', 1 RECONFIGURE WITH OVERRIDE
-- 先设置物理内存上限到1G EXEC sp_configure 'max server memory (MB)', 1024 RECONFIGURE WITH OVERRIDE "
sleep 10s
osql -E -S . -Q " -- 还原原先的上限 EXEC sp_configure 'max server memory (MB)', 25600 RECONFIGURE WITH OVERRIDE "
|