转载至:http://www.imkevinyang.com/2009/09/%E9%87%8A%E6%94%BEsql-server%E5%8D%A0%E7%94%A8%E7%9A%84%E5%86%85%E5%AD%98.html 释放 SQL Server 占用 的 内存 技术随笔 SQL,SQL Server, 内存 , 内存 释放 由于Sql Server对于系统 内存 的管理策略是有多少
转载至:http://www.imkevinyang.com/2009/09/%E9%87%8A%E6%94%BEsql-server%E5%8D%A0%E7%94%A8%E7%9A%84%E5%86%85%E5%AD%98.html
释放SQL Server占用的内存
技术随笔
由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右),Sql Server才会释放一点点内存。所以很多时候,我们会发现运行Sql Server的系统内存往往居高不下。
这些内存一般都是Sql Server运行时候用作缓存的,例如你运行一个select语句,那么Sql Server会将相关的数据页(Sql Server操作的数据都是以页为单位的)加载到内存中来,下一次如果再次请求此页的数据的时候,就无需读取磁盘了,大大提高了速度。这类的缓存叫做数据缓存。还有一些其他类型的缓存,如执行存储过程时,Sql Server需要先编译再运行,编译后的结果也会缓存起来,下一次就无需再次编译了。如果这些缓存已经不需要了,那么我们可以调用以下几个DBCC管理命令来清理这些缓存:
<span class="kwrd">DBCC</span> FREEPROCCACHE <span class="kwrd">DBCC</span> FREESESSIONCACHE <span class="kwrd">DBCC</span> FREESYSTEMCACHE(<span class="str">'All'</span>) <span class="kwrd">DBCC</span> DROPCLEANBUFFERS
这几个命令分别用来清除存储过程相关的缓存、会话缓存、系统缓存以及所有所有缓存。详细的使用参考MSDN。
但是需要注意的是,这几个命令虽然会清除掉现有缓存,为新的缓存腾地方,但是Sql server并不会因此释放掉已经占用的内存。无奈的是,Sql Server并没有提供任何命令允许我们释放不用到的内存。因此我们只能通过动态调整Sql Server可用的物理内存设置来强迫它释放内存。
<span class="kwrd">USE</span> master <span class="rem">-- 打开高级设置配置</span> <span class="kwrd">EXEC</span> sp_configure <span class="str">'show advanced options'</span>, 1 <span class="kwrd">RECONFIGURE</span> <span class="kwrd">WITH</span> OVERRIDE <span class="rem">-- 先设置物理<strong>内存</strong>上限到1G</span> <span class="kwrd">EXEC</span> sp_configure <span class="str">'max server memory (MB)'</span>, 1024 <span class="kwrd">RECONFIGURE</span> <span class="kwrd">WITH</span> OVERRIDE <span class="rem">-- 还原原先的上限</span> <span class="kwrd">EXEC</span> sp_configure <span class="str">'max server memory (MB)'</span>, 5120 <span class="kwrd">RECONFIGURE</span> <span class="kwrd">WITH</span> OVERRIDE <span class="rem">-- 恢复默认配置</span> <span class="kwrd">EXEC</span> sp_configure <span class="str">'show advanced options'</span>, 0 <span class="kwrd">RECONFIGURE</span> <span class="kwrd">WITH</span> OVERRIDE
我们也可以通过Sql Server Management企业管理器进行动态控制。连接到企业管理器之后打开Sql Server实例的属性面板,找到内存设置,改变其中的最大服务器内存使用即可。
——Kevin Yang

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
