Home Database Mysql Tutorial sqlserver内存释放心得

sqlserver内存释放心得

Jun 07, 2016 pm 03:40 PM
sqlserver Inside Memory Experience freed

sqlserver 内存释放心得 SQL Server 2008 或者R2的默认内存分配是2147483647MB, 差不多算是无穷大,对于系统内存的管理策略是有多少占多少。SQLserver会把所有处理过的SQL操作缓存在内存里,这样就不用总去读硬盘了。但是如果长时间运行SQL Server, 系统内存

sqlserver内存释放心得

SQL Server 2008 或者R2的默认内存分配是2147483647MB, 差不多算是无穷大,对于系统内存的管理策略是有多少占多少。SQLserver会把所有处理过的SQL操作缓存在内存里,这样就不用总去读硬盘了。但是如果长时间运行SQL Server, 系统内存被用的差不多,再开启其他程序就有可能会报内存不足。这时候就需要释放内存缓存啦。一般我用以下两种办法:

  1. 很简单,打开SQL Server configuration Manager,然后把SQL Server(MSSQLSERVER)重启一下,一般默认的instance 就是MSSQLServer,当然你如果装了其他的instance(实例)就选择相应的,例如MSSQLServer(SQLServLatin1), MSSQLServer(ARABIC)。

这种方法最简单有效,但是只能临时的清除SQLServer缓存所占的内存空间,时间长了SQLServer还会把内存占满。而且很重要的是这种方法不能在SQLserver有连接的情况下使用,那样会让正在使用SQLServer的用户暂时无法连接SQLServer,甚至导致程序处错误。而你作为管理员就……

  1. 第二种方法比较复杂,我也不是SQLServer高手,只是从网上学习得来的一些query:

DBCC FREEPROCCACHE

DBCC FREESESSIONCACHE

DBCC FREESYSTEMCACHE('All')

DBCC DROPCLEANBUFFERS

以上一段一般能释放缓存,(注意引号有的时候因为word文档里打不出英文的引号,最好拷到记事本里编辑一下)但是有的时候不是很管用。因为SQLserver不会因为Cache(缓存)释放了而释放内存,占了茅坑不一定XX。此命令只会让SQLServer不会继续占领新的内存,定期执行一下还可以。关键是还要释放一下内存。

通过以下Query 可以看出当前服务器所占内存情况

SELECT * FROM sys.dm_os_performance_counters

WHERE counter_name IN ('Target Server Memory (KB)','Total Server Memory (KB)')

Target Server Memory(KB)和 Total Server Memory(KB)字面意思所得就是目标和当前SQL Server所占的内存大小。

EXEC sp_configure 'show advanced options', 1

GO

EXEC sp_configure 'max server memory', 256

EXEC ('RECONFIGURE' )

WAITFOR DELAY '00:00:05'

EXEC  sp_configure 'max server memory', 2147483647

EXEC ('RECONFIGURE' )

GO

EXEC sp_configure 'show advanced options', 0

GO

其实我用这几句也不是很奏效,时间一长还是可能会有内存不够的情况。

 

******

总的来说我的管理办法是:

  1. 装好了SQLServer之后立刻设置最大使用内存

 

EXEC sp_configure 'show advanced options', 1 -- 这句是打开advanced options

GO

EXEC sp_configure 'max server memory', 9216 -- 设置最大内存为9G,我们server 内存是16G的,留下7G足够了

EXEC ('RECONFIGURE' )

GO

EXEC sp_configure 'show advanced options', 0 --记得用完了把advanced options关掉

GO

  1. 过一段时间觉得不行了就执行一下

DBCC FREEPROCCACHE

DBCC FREESESSIONCACHE

DBCC FREESYSTEMCACHE('All')

DBCC DROPCLEANBUFFERS

这个清缓存也很头疼,不知道什么时候合适,就这样吧,管他呢,我又不是专家,出了问题大不了来机器不行。或者写个Procedure,用job定期执行。

没办法,SQLServer太霸道了,以上方法不是万全之策,建议还是把SQLServer放到一边单独用吧。

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Large memory optimization, what should I do if the computer upgrades to 16g/32g memory speed and there is no change? Large memory optimization, what should I do if the computer upgrades to 16g/32g memory speed and there is no change? Jun 18, 2024 pm 06:51 PM

For mechanical hard drives or SATA solid-state drives, you will feel the increase in software running speed. If it is an NVME hard drive, you may not feel it. 1. Import the registry into the desktop and create a new text document, copy and paste the following content, save it as 1.reg, then right-click to merge and restart the computer. WindowsRegistryEditorVersion5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\MemoryManagement]"DisablePagingExecutive"=d

How to import mdf file into sqlserver How to import mdf file into sqlserver Apr 08, 2024 am 11:41 AM

The import steps are as follows: Copy the MDF file to SQL Server's data directory (usually C:\Program Files\Microsoft SQL Server\MSSQL\DATA). In SQL Server Management Studio (SSMS), open the database and select Attach. Click the Add button and select the MDF file. Confirm the database name and click the OK button.

What to do if the sqlserver service cannot be started What to do if the sqlserver service cannot be started Apr 05, 2024 pm 10:00 PM

When the SQL Server service fails to start, here are some steps to resolve: Check the error log to determine the root cause. Make sure the service account has permission to start the service. Check whether dependency services are running. Disable antivirus software. Repair SQL Server installation. If the repair does not work, reinstall SQL Server.

How to recover accidentally deleted database in sqlserver How to recover accidentally deleted database in sqlserver Apr 05, 2024 pm 10:39 PM

If you accidentally delete a SQL Server database, you can take the following steps to recover: stop database activity; back up log files; check database logs; recovery options: restore from backup; restore from transaction log; use DBCC CHECKDB; use third-party tools. Please back up your database regularly and enable transaction logging to prevent data loss.

Sources say Samsung Electronics and SK Hynix will commercialize stacked mobile memory after 2026 Sources say Samsung Electronics and SK Hynix will commercialize stacked mobile memory after 2026 Sep 03, 2024 pm 02:15 PM

According to news from this website on September 3, Korean media etnews reported yesterday (local time) that Samsung Electronics and SK Hynix’s “HBM-like” stacked structure mobile memory products will be commercialized after 2026. Sources said that the two Korean memory giants regard stacked mobile memory as an important source of future revenue and plan to expand "HBM-like memory" to smartphones, tablets and laptops to provide power for end-side AI. According to previous reports on this site, Samsung Electronics’ product is called LPWide I/O memory, and SK Hynix calls this technology VFO. The two companies have used roughly the same technical route, which is to combine fan-out packaging and vertical channels. Samsung Electronics’ LPWide I/O memory has a bit width of 512

Samsung announced the completion of 16-layer hybrid bonding stacking process technology verification, which is expected to be widely used in HBM4 memory Samsung announced the completion of 16-layer hybrid bonding stacking process technology verification, which is expected to be widely used in HBM4 memory Apr 07, 2024 pm 09:19 PM

According to the report, Samsung Electronics executive Dae Woo Kim said that at the 2024 Korean Microelectronics and Packaging Society Annual Meeting, Samsung Electronics will complete the verification of the 16-layer hybrid bonding HBM memory technology. It is reported that this technology has passed technical verification. The report also stated that this technical verification will lay the foundation for the development of the memory market in the next few years. DaeWooKim said that Samsung Electronics has successfully manufactured a 16-layer stacked HBM3 memory based on hybrid bonding technology. The memory sample works normally. In the future, the 16-layer stacked hybrid bonding technology will be used for mass production of HBM4 memory. ▲Image source TheElec, same as below. Compared with the existing bonding process, hybrid bonding does not need to add bumps between DRAM memory layers, but directly connects the upper and lower layers copper to copper.

How to delete sqlserver if the installation fails? How to delete sqlserver if the installation fails? Apr 05, 2024 pm 11:27 PM

If the SQL Server installation fails, you can clean it up by following these steps: Uninstall SQL Server Delete registry keys Delete files and folders Restart the computer

How to change sqlserver English installation to Chinese How to change sqlserver English installation to Chinese Apr 05, 2024 pm 10:21 PM

SQL Server English installation can be changed to Chinese by following the following steps: download the corresponding language pack; stop the SQL Server service; install the language pack; change the instance language; change the user interface language; restart the application.

See all articles