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

Video Face Swap

Video Face Swap

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

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 to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings PHP Database Connection Pitfalls: Avoid Common Mistakes and Misunderstandings Jun 05, 2024 pm 10:21 PM

To avoid PHP database connection errors, follow best practices: check for connection errors and match variable names with credentials. Use secure storage or environment variables to avoid hardcoding credentials. Close the connection after use to prevent SQL injection and use prepared statements or bound parameters.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

How to install and register the btc trading app? How to install and register the btc trading app? Feb 21, 2025 pm 07:09 PM

This article will provide a detailed introduction to how to install and register a Bitcoin trading application. The Bitcoin trading app allows users to manage and trade cryptocurrencies such as Bitcoin. The article guides users through the installation and registration process step by step, including downloading applications, creating accounts, performing identity verification, and first deposit. The goal of the article is to provide beginners with clear and easy-to-understand guidelines to help them easily enter the world of Bitcoin trading.

Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Top 10 global digital currency trading apps recommended (2025 currency trading software ranking) Mar 12, 2025 pm 05:48 PM

This article recommends the top ten digital currency trading apps in the world, including Binance, OKX, Huobi Global, Coinbase, Kraken, Gate.io, KuCoin, Bitfinex, Gemini and Bitstamp. These platforms have their own characteristics in terms of transaction pair quantity, transaction speed, security, compliance, user experience, etc. For example, Binance is known for its high transaction speed and extensive services, while Coinbase is more suitable for novices. Choosing a platform that suits you requires comprehensive consideration of your own needs and risk tolerance. Learn about the world's mainstream digital currency trading platforms to help you conduct digital asset trading safely and efficiently.

See all articles