Oracle初始化參數之memory_target

1、引言:java

    Oracle 9i引入pga_aggregate_target,能夠自動對PGA進行調整;linux

    Oracle 10g引入sga_target,能夠自動對SGA進行調整;數據庫

    Oracle 11g則對這兩部分進行綜合,引入memory_target,能夠自動調整全部的內存,這就是新引入的自動內存管理特性。oracle

2、本文說明:less

      操做系統:rhel 5.4 x32ui

      數據庫:oracle 11g r2this

3、memory_target的介紹:spa

    3.一、下面經過示例瞭解一下memory_target的設置與PGA和SGA關係:操作系統

SQL> show parameter memory_target;

NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
memory_target                 big integer 316M
SQL> show sga;

Total System Global Area  330600448 bytes
Fixed Size            1336344 bytes
Variable Size          247466984 bytes
Database Buffers       75497472 bytes
Redo Buffers            6299648 bytes
SQL> alter system set memory_target=200m scope=spfile;

System altered.

SQL> alter system set sga_target=0 scope=spfile;

System altered.

SQL> alter system set pga_aggregate_target=0 scope=spfile;

System altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.

Total System Global Area  209235968 bytes
Fixed Size            1335528 bytes
Variable Size          201330456 bytes
Database Buffers        4194304 bytes
Redo Buffers            2375680 bytes
Database mounted.
Database opened.

    設置memory_target參數後,實際上Oracle會自動設置並調整一下兩個參數來分配SGA和PGA的內存,這和Oracle 10g自動設置sga_target後分配db_cache_size和shared_pool_size的機制是同樣的。code

SQL> col ksppinm for a20;
SQL> col ksppstvl for a20;
SQL> select a.ksppinm name,b.ksppstvl value
  2     from x$ksppi a,x$ksppcv b
  3   where a.indx = b.indx
  4      and (a.ksppinm like '%sga_target%'
  5  or a.ksppinm like '%pga_aggregate_target%');

NAME                                VALUE
-----------------------     -------------------
sga_target                           0
__sga_target                     142606336
pga_aggregate_target                 0
__pga_aggregate_target            67108864

    3.二、討論一下11g中memory_target設置和不設置對SGA/PGA的影響:

    3.2.一、若是memory_target設置爲非0值

      (下面有四種狀況來對SGA和PGA的大小進行分配)

      3.2.1.一、sga_target和pga_aggregate_target已經設置大小

        若是Oracle中已經設置了參數sga_target和pga_aggregate_target,則這兩個參數將各自被分配爲最小值爲他們的目標值。

        memory_target = sga_target + pga_aggregate_target,大小和memory_max_size一致。

      3.2.1.二、sga_target設置大小,pga_aggregate_target沒有設置大小

        那麼pga_aggregate_target初始化值=memory_target-sga_target

      3.2.1.三、sga_target沒有設置大小,pga_aggregate_target設置大小

        那麼sga_target初始化值=memory_target-pga_aggregate_target

      3.2.1.四、sga_target和pga_aggregate_target都沒有設置大小

        Oracle 11g中對這種sga_target和pag_aggregate_target都沒有設定大小的狀況下,Oracle將對這兩個值沒有最小值和默認值。Oracle將根據數據庫運行情況進行分配大小。但在數據庫啓動是會有一個固定比例來分配:

        sga_target = memory_target*60%

        pga_aggregate_target = memory_target*40%

    3.2.二、若是memory_target沒有設置或 = 0(在11g中默認爲0)

      11g中默認爲0則初始狀態下取消了memory_target的做用,徹底和10g在內存管理上一致,徹底向下兼容。(也有三種狀況來對SGA和PGA的大小進行分配)

      3.2.2.一、sga_target設置值,則自動調節SGA中的shared pool,buffer cache,redo log buffer,java pool,larger pool等內存空間的大小。PGA則依賴pga_aggregate_target的大小。sga和pga不能自動增加和自動縮小。

      3.2.2.二、sga_target和pga_aggregate_target都沒有設置

        SGA中的各組件大小都要明確設定,不能自動調整各組件大小。PGA不能自動增加和收縮。

      3.2.2.三、memory_max_target設置而memory_target = 0這種狀況先和10g同樣,不作說明。 

3、ORA-00845

    最後談一下ORA-00845的由來和解決方案:

    若是memory_max_target/memory_target設置過大,可能致使instance沒法啓動,報ORA-00845錯誤。

[oracle@yft bin]$ oerr ora 00845
00845, 00000, "MEMORY_TARGET not supported on this system"
// *Cause: The MEMORY_TARGET parameter was not supported on this operating system or /dev/shm was not sized 
// *Action: Refer to documentation for a list of supported operating systems. Or, size /dev/shm to be at leacle instance running on the system.

SQL> alter system set memory_max_target=400m scope=spfile;

System altered.

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORA-00845: MEMORY_TARGET not supported on this system

 這個錯誤有點誤導,實際上這並非說該平臺版本上不支持AMM特性,只是設置的memory_max_target超過了系統中設置的share memory(/dev/shm)而已。

[oracle@yft bin]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 395M     0  395M   0% /dev/shm

在Oracle 11g for linux中彷佛是用了一種新的機制來管理共享內存段,而不是傳統的sys /dev/shm了。在alert.ora中能夠找到更準確的錯誤描述:

Mon Feb 25 12:13:21 2013
Starting ORACLE instance (normal)
WARNING: You are trying to use the MEMORY_TARGET feature. This feature requires the /dev/shm file system to be mounted for at least 419430400 bytes. /dev/shm is either not mounted or is mounted with available space less than this size. Please fix this so that MEMORY_TARGET can work as expected. Current available is 413466624 and used is 0 bytes. Ensure that the mount point is /dev/shm for this directory.
memory_target needs larger /dev/shm

 

 解決的辦法之一是增長tmpfs文件系統的容量:

      修改/etc/fstab中tmpfs對應的行;將原來的tmpfs   /dev/shm  tmpfs defaults 0 0 改爲tmpfs /dev/shm tmpfs default,size=1024M 0 0,這樣tmpfs增大爲1G,從新mount /dev/shm使之生效。

[root@yft ~]# vi /etc/fstab
tmpfs                   /dev/shm                tmpfs   defaults,size=420m        0 0

[root@yft ~]# mount -o remount /dev/shm
[root@yft ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
tmpfs                 420M     0  420M   0% /dev/shm

SQL> startup
ORACLE instance started.

Total System Global Area  418484224 bytes
Fixed Size            1336932 bytes
Variable Size          406849948 bytes
Database Buffers        4194304 bytes
Redo Buffers            6103040 bytes
Database mounted.
相關文章
相關標籤/搜索