Home Database Mysql Tutorial ORA-4031错误 解决方法

ORA-4031错误 解决方法

Jun 07, 2016 pm 03:53 PM
o database

遇到ORA-4031错误时,你的心里会不会发怵?ORA-4031很容易导致数据库出现异常崩溃,当Oracle的核心进程无法获得共享池内存时,它

遇到ORA-4031错误时,你的心里会不会发怵?ORA-4031很容易导致数据库出现异常崩溃,当Oracle的核心进程无法获得共享池内存时,它们会把数据库异常宕掉。当然,ORA-4031就像黄灯一样,它在提醒你需要马上采取紧急策略了。不是说它一出现,数据库马上就会宕机。

话题讨论:
1.ORA-4031是Oracle中最令人厌恶的报错,,它的出现有哪几种原因?

2.一旦出现4031错误,也就是说共享池内存不足的情况下,我们该如何释放内存呢?你有木有遇到过相应的情形呢?请回忆下当时是如何解决的?

3.有一句俗语叫丢车保帅,执行计划是SQL核心关键所在,是否意味着在释放内存时,不应该覆盖执行计划这部分?当执行计划部分占用内存比较多时,如何优化呢?

4.消耗共享池内存的主要有两种对象,一种是SQL,而是存储过程、函数、包等这类可执行对象,当遇到4031错误时,您觉得需要优先释放哪种对象

问题分析:

1、ORA-4031错误的原因,一般是大量的hard parse导致了shared pool中的free list中产生大量的内存小碎片,当一个需要很大内存来进行hard parse的sql语句到来时,无法从free list中找到内存,即使进行内存的释放,还是不能找到符合的内存块。从而报ORA-4031错误。

2. ORA-4031错误的解决方法:

1)alter system flush shared_pool;将shared pool中的所有内存清空。该方法治标不治本。
2)共享SQL语句:规范SQL语句的书写;使用绑定变量;找到没有使用绑定变量的SQL:
  如果在结果中发现一系列仅仅字面值不同的SQL,则可以修改cursor_sharing参数:
  alter system set cursor_sharing = 'force'; 来强制使用绑定变量。
3)使用shared pool中的保留区:
  select request_misses from v$shared_pool_reserved;
  如果结果大于0,则可以调大shared_pool_reserved的大小;
SQL> show parameter shared_pool
NAME                                TYPE        VALUE
------------------------------------ ----------- ------------------------------
shared_pool_reserved_size            big integer 4M
shared_pool_size                    big integer 0
alter system set shared_pool_reserved=xxM scope=both;
4)使用dbms_shared_pool.keep('对象名')将使用内存很大的对象keep在内存中:
  先要执行:@?/rdbms/admin/dbmspool.sql
SQL> @?/rdbms/admin/dbmspool.sql
Package created.
Grant succeeded.
View created.
Package body created.

再查出需要keep的对象:
SQL> select owner,name,namespace,type,sharable_mem from v$db_object_cache where sharable_mem>10000
  2  and (type='PACKAGE' or type='PACKAGE BODY' or type='FUNCTION' or type='PROCEDURE') and kept='NO';
OWNER      NAME                      NAMESPACE          TYPE            SHARABLE_MEM
---------- ------------------------- ------------------ --------------- ------------
SYS        DBMS_BACKUP_RESTORE      TABLE/PROCEDURE    PACKAGE                33215
SYSMAN    EMD_COLLECTION            BODY              PACKAGE BODY          33233
SYS        DBMS_SHARED_POOL          BODY              PACKAGE BODY          12644
SYS        SYS$RAWTOANY              TABLE/PROCEDURE    FUNCTION              12640
SYSMAN    EMD_MAINTENANCE          TABLE/PROCEDURE    PACKAGE                29030
SYSMAN    EMD_MAINTENANCE          BODY              PACKAGE BODY          62930
SYSMAN    MGMT_JOB_ENGINE          BODY              PACKAGE BODY          218914
SYSMAN    EM_PING                  BODY              PACKAGE BODY          29086
SYS        DBMS_BACKUP_RESTORE      BODY              PACKAGE BODY          95519
SYSMAN    EMD_LOADER                TABLE/PROCEDURE    PACKAGE                12641
SYSMAN    EMD_LOADER                BODY              PACKAGE BODY          71861
SYS        PRVT_HDM                  BODY              PACKAGE BODY          43624
SYSMAN    MGMT_JOB_ENGINE          TABLE/PROCEDURE    PACKAGE                24938
SYS        STANDARD                  BODY              PACKAGE BODY          24960
SYSMAN    EM_SEVERITY_REPOS        BODY              PACKAGE BODY          33236
SYS        PRVT_ADVISOR              TABLE/PROCEDURE    PACKAGE                12640
SYSMAN    MGMT_GLOBAL              TABLE/PROCEDURE    PACKAGE                29902
SYS        DBMS_STANDARD            TABLE/PROCEDURE    PACKAGE                24929
SYS        DBMS_ADVISOR              BODY              PACKAGE BODY          25000
SYS        PRVT_HDM                  TABLE/PROCEDURE    PACKAGE                16732
SYS        PRVT_ADVISOR              BODY              PACKAGE BODY          66780
SYS        DBMS_RCVMAN              TABLE/PROCEDURE    PACKAGE                43295
SYS        STANDARD                  TABLE/PROCEDURE    PACKAGE              438648
SYS        DBMS_RCVMAN              BODY              PACKAGE BODY          375759

24 rows selected.
5)增加shared_pool_size的大小:
SQL> select component,current_size from v$sga_dynamic_components;

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)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months 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)

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How does Go WebSocket integrate with databases? How does Go WebSocket integrate with databases? Jun 05, 2024 pm 03:18 PM

How to integrate GoWebSocket with a database: Set up a database connection: Use the database/sql package to connect to the database. Store WebSocket messages to the database: Use the INSERT statement to insert the message into the database. Retrieve WebSocket messages from the database: Use the SELECT statement to retrieve messages from the database.

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

PHP connections to different databases: MySQL, PostgreSQL, Oracle and more PHP connections to different databases: MySQL, PostgreSQL, Oracle and more Jun 01, 2024 pm 03:02 PM

PHP database connection guide: MySQL: Install the MySQLi extension and create a connection (servername, username, password, dbname). PostgreSQL: Install the PgSQL extension and create a connection (host, dbname, user, password). Oracle: Install the OracleOCI8 extension and create a connection (servername, username, password). Practical case: Obtain MySQL data, PostgreSQL query, OracleOCI8 update record.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

See all articles