關於memory_max_target,memory_target,sga_max_size,sga_target

路途中的人2012發表於2016-05-14
首先先看下11gr2的oracle的幫助文件中關於這幾個引數的解釋:
MEMORY_TARGET

Property        Description
Parameter type        Big integer
Syntax        MEMORY_TARGET = integer [K | M | G]
Default value        0 (SGA autotuning is disabled for DEFERRED mode autotuning requests, but allowed for IMMEDIATE mode autotuning requests)
Modifiable        ALTER SYSTEM
Range of values        152 MB to MEMORY_MAX_TARGET
Basic        No
MEMORY_TARGET specifies the Oracle system-wide usable memory. The database tunes memory to the MEMORY_TARGET value, reducing or enlarging the SGA and PGA as needed.

In a text-based initialization parameter file, if you omit MEMORY_MAX_TARGET and include a value for MEMORY_TARGET, then the database automatically sets MEMORY_MAX_TARGET to the value of MEMORY_TARGET. If you omit the line for MEMORY_TARGET and include a value for MEMORY_MAX_TARGET, the MEMORY_TARGET parameter defaults to zero. After startup, you can then dynamically change MEMORY_TARGET to a nonzero value, provided that it does not exceed the value of MEMORY_MAX_TARGET.

Total memory usage can grow beyond the value of MEMORY_TARGET. For example, memory is allocated to PL/SQL tables and varrays regardless of the value of MEMORY_TARGET as long as memory is available at the operating system level.

In the Default value field, IMMEDIATE mode autotuning requests are necessary to avoid ORA-04031 errors. The DEFERRED and IMMEDIATE modes are reflected in the OPER_MODE column of the V$MEMORY_RESIZE_OPS view.

MEMORY_MAX_TARGET

Property        Description
Parameter type        Big integer
Syntax        MEMORY_MAX_TARGET = integer [K | M | G]
Default value        0
Modifiable        No
Range of values        0 to the physical memory size available to the Oracle Database
Basic        No
MEMORY_MAX_TARGET specifies the maximum value to which a DBA can set the MEMORY_TARGET initialization parameter. See the description of MEMORY_TARGET for more information about how the settings of MEMORY_MAX_TARGET and MEMORY_TARGET affect each other.

從上面描述中可以先明確幾點:
1、memory_max_target值限制了memory_targe的值。如果你需要加大memory_target並且加大的值大於memory_max_target值需要先把memory_max_target 值調大。
2、如果沒有設定memory_max_target引數,那麼memory_max_target會自動取memory_target的引數值。
3、如果沒有設定memory_target但是設定了memory_max_target,那麼memory_target預設為0,需要手動設定大小
4、如果memory_target為0,那麼需要資料庫的模式為 IMMEDIATE mode,否則會報ORA-04031錯誤。這點我在11.1.0.7環境中未驗證,不知道是否是11.2的,V$MEMORY_RESIZE_OPS這個檢視中的  OPER_MODE都是空列.
另外,根據已經測試的情況:
1、初始話引數中不存在memory_max_target和memory_target,預設值為系統的shm的值,而shm值為系統實體記憶體的一半。
2、要改大memory_target需要先調整shm的值,然後修改memory_max_target,最後調整memory_target。
3、調整方法是shm需要umount /dev/shm,然後在fstab檔案中default列後面加上:,sieze=nM,n為需要調整的記憶體值,一般我會把n值比要設定的memory_max_target大一些,接著mount /dev/shm,shm值就調整好了。另外umount之前需要把資料庫和叢集都關閉,否則shm無法umount。
4、memory_max_target是靜態引數,修改的時候只能指定scope=spfile引數,memory_target是動態引數,可以直接修改,但是修改的時候還是必須保證修改的值小於memory_max_target的值,所以在增大玩memory_max_target後需要重啟資料庫保證引數生效才行。另外在叢集環境下memory_target引數是單例項修改,需要後面加上引數sid='*'表示全部例項修改。

再來看下sga的2個引數:

SGA_MAX_SIZE

PropertyDescription
Parameter typeBig integer
SyntaxSGA_MAX_SIZE = integer [K | M | G]
Default valueInitial size of SGA at startup, dependent on the sizes of different pools in the SGA, such as buffer cache, shared pool, large pool, and so on.
ModifiableNo
Range of values0 to operating system-dependent

SGA_MAX_SIZE specifies the maximum size of the SGA for the lifetime of the instance.

On 64-bit platforms and non-Windows 32-bit platforms, when either MEMORY_TARGET or MEMORY_MAX_TARGET is specified, the default value of SGA_MAX_SIZE is set to the larger of the two parameters. This causes more address space to be reserved for expansion of the SGA.

On Windows 32-bit platforms, the default value of SGA_MAX_SIZE is the largest of the following values:

  • 60% of MEMORY_TARGET, if specified

  • 60% of MEMORY_MAX_TARGET, if specified

  • 25% of the total available virtual address space

SGA_TARGET

PropertyDescription
Parameter typeBig integer
SyntaxSGA_TARGET = integer [K | M | G]
Default value0 (SGA autotuning is disabled for DEFERRED mode autotuning requests, but allowed for IMMEDIATE mode autotuning requests)
ModifiableALTER SYSTEM
Range of values64 MB to operating system-dependent
BasicYes

SGA_TARGET specifies the total size of all SGA components. If SGA_TARGET is specified, then the following memory pools are automatically sized:

  • Buffer cache (DB_CACHE_SIZE)

  • Shared pool (SHARED_POOL_SIZE)

  • Large pool (LARGE_POOL_SIZE)

  • Java pool (JAVA_POOL_SIZE)

  • Streams pool (STREAMS_POOL_SIZE)

If these automatically tuned memory pools are set to nonzero values, then those values are used as minimum levels by Automatic Shared Memory Management. You would set minimum values if an application component needs a minimum amount of memory to function properly.

The following pools are manually sized components and are not affected by Automatic Shared Memory Management:

  • Log buffer

  • Other buffer caches, such as KEEP, RECYCLE, and other block sizes

  • Fixed SGA and other internal allocations

The memory allocated to these pools is deducted from the total available for SGA_TARGET when Automatic Shared Memory Management computes the values of the automatically tuned memory pools.

In the Default value field, IMMEDIATE mode autotuning requests are necessary to avoid  errors. The DEFERRED and IMMEDIATE modes are reflected in the OPER_MODE column of the V$MEMORY_RESIZE_OPS view.

這邊可以看到sga_max_size、 sga_target和前面的memory類似,不過sga_target引數的介紹關於預設值0可能有問題,按
這個文件的說法開啟AMM( Automatic Memory Management)的方法就是設定sga_target=0,同樣在11.1中的 V$MEMORY_RESIZE_OPS 檢視也沒有看到OPEN_MODE的值。

關於設定 sga_max_size、 sga_target 的引數可以參看下這篇文件,
實際測試中發現預設的初始化檔案中是不存在 sga_max_size,也不要去手動設定這個引數值,一旦使用alter system set  sga_max_size 後引數檔案中就會加上這個引數,而且不能設定成0,所以如果不小心設定了 sga_max_size 最好的方法是先生成pfile檔案,將該引數刪除在用pfile檔案生成spfile檔案,如果在叢集環境下生成spfile的檔案切記加上spfile檔案的路徑,否則會生成到dbs路徑下。

AMM和ASMM( Automatic SGA Memory)這2者的區別就在於sga_target這個值,如果是0表示開啟了AMM來管理sga,否則用開啟ASMM管理sga。AMM是11g新增的功能,10g新增了ASMM,9i新增了APM( Automatic PGA Memory)

大概就這些先,有問題的請留言。



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29067253/viewspace-2099931/,如需轉載,請註明出處,否則將追究法律責任。

相關文章