search
HomeDatabaseMysql TutorialOracle性能优化 之 保留区与ORA-04031

一、保留区 没有被PIN住大对象的加载、老化将会使共享池产生碎片,Oracle想了个方法解决这个问题,它专门在共享池开辟一块区域,

一、保留区

没有被PIN住大对象的加载、老化将会使共享池产生碎片,Oracle想了个方法解决这个问题,它专门在共享池开辟一块区域,所有大小超过4400字节的对象,将在此专门开辟的区域中分配空间,这块区域被称为保留区。这样,让大对象和小对象分开存储,可以减少大对象的加载、老化以大量小对象产生的影响,并且可以减少小对象区域内的内存碎片。而且Oracle针对保留区设计了专门的内存管理算法,使得大对象可以更快速的加载。

你可以使用shared_pool_reserved_size参数设置此保留区的大小,,默认情况下,保留区将被自动设置为共享池大小的5%。另外,保留区大小不能设置为超过共享池大小的一半,否则将会报出错误。通常情况下,保留区的大小保留默认值就行,我们一般不需要调节它。

关于进入保留区对象的大小,Oracle更不建议我们调节它。但有时4400这个值对我们的系统可能并不合适。假设经常4000字节左右(不到4400)的对象被加载到共享池中,三、四千字节的对象,已经是大对象了,并且这些大对象很少使用,这样将它们PIN在内存中有点浪费空间,不到4400的大小使得它们无法被加载到保留区,这些对象每次执行时的加载需要老化很多小对象,并且还很容易造成共享池的碎片。这时,我们可以调低4400这个限制值,比如我们可以将保留区的限制降到3500,这样可以让那些本来不能进入保留区的对象可以进入保留区。这不旦可以加快这些对象的加载速度,重要的是减少了它们对众多小对象的影响。我们可以通过V$DB_ OBJECT_CACHE观察对象在共享池中所占用的内存大小,如果发现上述情况,可以调低4400这个限制值。这个限制是用一个隐藏参数来设置的:_shared_pool_reserved_min_alloc。凡是参数名前带有下划线的,都被称为隐藏参数,这些隐藏参数不能通过Show parameter显示,我们可以使用我写的脚本Show_para.sql显示隐藏参数和它们的意义,此脚本的编写见本章末尾的附录部分。

有一个视图可以用来帮助调节保留区:V$SHARED_POOL_RESERVED,它有如下的列:

FREE_SPACE:保留区中自由空间的总和

AVG_FREE_SIZE:每个自由内存块的平均大小

FREE_COUNT:自由的内存块数量

MAX_FREE_SIZE:最大的自由内存块大小

USED_SPACE:保留区中已使用的空间大小

AVG_USED_SIZE:每个已经使用的内存块的平均大小

USED_COUNT:已使用的内存块数量

MAX_USED_SIZE:已使用的最大的内存块大小

REQUESTS:在保留区中搜索自由内存块的次数

REQUEST_MISSES:保留区中没有可以满足要求的内存块并开始在保留区中LRU链中刷新对象的次数

LAST_MISS_SIZE:最后一次出现REQUEST_MISSES时,所请求的空间大小

MAX_MISS_SIZE:最大一次出现REQUEST_MISSES时,所请求的空间大小

下面的列即使SHARED_POOL_RESERVED_SIZE没有被设置也是有效的:

REQUEST_FAILURES:无论保留区还是非保留区,没有可以满足要求的内存的次数(也就是ORA-4031错误发生的次数)

LAST_FAILURE_SIZE:最后一次REQUEST_FAILURES时所请求的内存大小

后三列相关DBMS_SHARED_POOL.ABORTED_REQUEST_THRESHOLD过程。

ABORTED_REQUEST_THRESHOLD:最小的超过DBMS_SHARED_POOL.ABORTED_REQUEST_THRESHOLD设置值的大小

ABORTED_REQUESTS:超过DBMS_SHARED_POOL.ABORTED_REQUEST_THRESHOLD的次数

LAST_ABORTED_SIZE:最后一次超过DBMS_SHARED_POOL.ABORTED_REQUEST_THRESHOLD时的大小。

注意,如果REQUEST_FAILURES大于0且持续增加时,说明用户要求大小为N的内存块,但共享池内已经没有大小超过N的内存块。当REQUEST_FAILURES增加的比较快时,用户的操作将会失败并收到著名的ORA-04031错误,就是“共享池内存不足”,通常还有一句“不能申请大于N字节的内存块”。

造成这种情况有三种原因,一是内存的确不足了,这个时候你要增加内存。二是共享池中还有内存,但都是小块,没有大小超过N字节的内存块以满足用户的请求,也就是说内存中有碎片了。关于共享池内存碎片的解决方法,我们马上就说。再来看第三种情况,三是共享池中还有内存,但因为保留区设置的不合理,用户要在普通区中请求内存(用户请求的内存大小未超过4400),而普通区中已经没有自由内存了,但保留区中还有很多空闲。或者情况相反,用户在保留区中请求内存,保留区内存已经不足,但普通区中仍有大量内存空余。

当4031错误出现时,你的情况是否属于第三种―――保留设置不合理,可以通过本节所介绍的视图得知。下面我们分别介绍一下普通区空间不足和保留区空间不足这两种情况的监测和解决:

(一) 、普通区内存空间不足:

REQUEST_FAILURES不为0且持续增加时,如果LAST_FAILURE_SIZE

FREE_SPACE:保留区中自由空间的总和

AVG_FREE_SIZE:每个自由内存块的平均大小

FREE_COUNT:自由的内存块数量

MAX_FREE_SIZE:最大的自由内存块大小

USED_SPACE:保留区中已使用的空间大小

AVG_USED_SIZE:每个已经使用的内存块的平均大小

USED_COUNT:已使用的内存块数量

MAX_USED_SIZE:已使用的最大的内存块大小

如果FREE_SPACE显示的自由空间还有很多,就说明保留区中仍有大量空间,完全可以将_SHARED_POOL_RESERVED_MIN_ALLOC设置的小一些,或减少保留区所占内存。

如果保留区中空间也不是太足了,就需要检查共享池中是否碎片太多,如果不是碎片的问题,就只有增大共享池大小了。关于碎片我们马上就讨论。

(二) 、保留区空间不足

当REQUEST_FAILURES不为0且持续增加时,LAST_FAILURE_SIZE > _SHARED_POOL_RESERVED_MIN_ALLOC,就说明用户所请求的内存要在保留区中分配,而保留区这时的空间已经不足已满足用户的请求了。

这时我们可以加大_SHARED_POOL_RESERVED_MIN_ALLOC的限制值,减少进入保留区的对象数。将SHARED_POOL_RESERVED_SIZE参数的值设大一些,以增加保留区大小。当然,如果你的主机上仍有空余内存,也可以增大共享池内存大小。

linux

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

mPDF

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),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft