search
HomeDatabaseMysql Tutorial合理设置SQL Server数据库内存使用

在SQL Server数据库中,有min server memory与max server memory两个内存选项。数据库管理员合理设置这两个选项可以让SQL SERVER数据库系统与其他英勇程序和平共存。顾名思义,min server memory就是设置数据系统所使用的最小内存,而max server memory用来

在SQL Server中,有min server memory与max server memory两个内存选项。管理员合理设置这两个选项可以让SQL SERVER数据库系统与其他英勇程序和平共存。顾名思义,min server memory就是设置数据系统所使用的最小内存,而max server memory用来设置其可以使用的最大内存。


合理设置内存让数据库与其他程序共存

一、SQL SERVER数据库的内存管理机制。

在数据库启动的时候,其实数据库引擎并不会马上在内存中抓取min参数规定的内存量。这种占着茅坑不拉屎的事情SQL Server数据库是不会做的。系统在刚开始启动的时候,数据库缓冲池只抓取初始化所需要的内存,如上图所示。数据库启动之后随着业务量的增大,数据库引擎的工作负荷也会随之增加。此时数据库引擎会继续获取完成工作所需要的内存。在达到min规定的内存数量之前,数据库引擎缓冲池是不会释放它获取的任何内存。如数据库初始化内存为20M,而规定的min内存数量为50M。则可能因为用户查询某个负责报表的需要,内存需要量会达到40M。查询作业执行完毕后数据库系统缓冲池实际使用的内存量可能只需要20M即可。但是只要没有达到50M这个值。则数据库系统不会把没有的20M内存还给操作系统,而是一直占用着,以方面后续的作业。

如果用户需要调用数据库系统中的函数或者过程,此时内存的需要量可能会超过规定的最小内存量,如达到80M。此时数据库引擎会根据一定的标准算法,根据需要来获取和释放内存。当需要使用超过50M的内存的时候,只要没有达到内存的最大限值之前,则会根据系统提供的标准算法来获取内存。至于这个标准算法到底是怎么样的,这不是我们数据库管理员所需要关注的内容。然后等到这个过程或者函数调用完毕后,内存使用量可能会降低到最低内存数量以下,如又回复到40M。此时数据库引擎就会释放内存,把没有用到的内存释放出来给其他应用程序使用。但是这个释放会有一个限制。数据库引擎缓冲池从不将内存分配降低到最小内存所指定的水平下。也就是说,此时数据库最多会释放30M的内存,为自己留下50M的内存空间,即使当前其可能只需要用到40M内存空间即可。当然在抓取内存空间的时候,其也不会为自己分配高于MAX内存所规定的内存空间。

二、多个应用程序共存时的内存分配。

如果一台上只运行了一个数据库应用程序,或者说数据库的应用比较简单、数据库内存使用量基本上不会超过最小内存数量的花,则可以采用默认多参数配置。但是如果在同一台服务器上部署了比较多的应用程序或者数据库设计比较复杂,此时就需要对数据库的最小内存与最大内存进行配置,以实现多个应用程序能够实现和平共处。另外如果数据库本身比较简单,但是其他应用程序比较复杂,可能会占用90%以上的内存时,数据库就需要采用一定的保护措施,需要设置最小内存与最大内存,来保障自己数据库正常运行所需要的内存空间。

1、数据库管理员需要监测内存的使用情况,并根据监测的数据来进行设置。由于采取的操作系统、部署的应用程序不同;甚至在SQL Server数据库中启用的服务不同,数据库需要使用的内存数量也是不同的。为此没有一个具体的标准说最小内存或者最大内存要配置多少。通常情况下需要数据库管理员跟踪数据库服务器一段时间,看看其内存的使用量。如笔者建议用户,数据库系统正是投入使用后,在头一年内需要每个月观测一下内存的使用情况。由于头几个月可能使用的不稳定,所得到的数据参考价值不大。而从第六个月开始到第12个月近八个月数据库内存的使用情况来看,基本上可以得出一个最小内存与最大内存的合理范围。然后数据库管理员就可以来对内存的最大最小值来进行设置。以后若前台应用程序做了新的调整或者数据库中采用了新的功能,仍然需要对内存的使用情况进行监测,来确定一个合理的内存使用范围。一般来说,最好把最小内存设置的小一点,而把最大内存的花设置的大一点。如此的话,可以让数据库引擎在管理内存的时候有比较大的灵活性。然后再进行后续监测的数据来进行相应的调整,慢慢的把内存配置调整到最优。根据笔者的经验,要达到合理的内存配置之前,往往需要一个比较漫长的时间。不过这对于数据库性能优化来说,可能这个过程也不是很长。

2、要分析数据库系统内存的使用大户,跟其他应用程序的内存使用高峰分流。数据库中函数、过程、复杂的视图、备份等作业都会用到比较可观的内存。如企业如果在SQL SERVER数据库上面部署了ERP系统,而系统中有一个“库存采购”作业,这个需要用到比较复杂的业务逻辑,需要考虑到库存、安全库存、包装数量等等比较复杂的计算。为此最好能够把这个作业放到服务器比较空的时候运行,以跟其他应用程序错开运行。如在应用程序设计的时候,可以把这个作业放在后台运行,并让其在晚上12点运行。然后在第二天早上之前出来结果。另外每个应用程序都需要对自己的数据进行备份,以防不时之需。而备份程序往往也需要用到比较多的内存。为此最好能够把各种应用程序的备份作业错开来运行。如此的话可以减少应用程序之间内存的占用。

Statement
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
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

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

Video Face Swap

Video Face Swap

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

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.