sga_target和sga_max_size

简介:
sga_target和sga_max_size 

1.说明 
sga_max_size是从9i以来就有的作为设置SGA大小的一个参数,而SGA_TARGET则是从10g才有的一个新参数,作为配合10g自动管理SGA而出现的 
sga_target是10g的新特性,只要sga_target为非零值,那么内存组件就是采用动态分配原则,由Oracle自动调整各内存组件的大小。 

2.参数查看: 
SQL> show parameter sga 
NAME      TYPE VALUE 
------------------------------------ ----------- ------------------------------ 
lock_sga      boolean FALSE 
pre_page_sga      boolean FALSE 
sga_max_size      big integer 1456M 
sga_target      big integer 0           --自动管理关闭,每个值都是固定的。 

SQL> select name,bytes/1024/1024 "size(MB)",resizeable from v$sgainfo; 
NAME    size(MB) RES 
-------------------------------- ---------- --- 
Fixed SGA Size 2.12534332             No 
Redo Buffers    7.359375               No 
Buffer Cache Size 544                   Yes 
Shared Pool Size 256                   Yes 
Large Pool Size 16                   Yes 
Java Pool Size 16                   Yes 
Streams Pool Size 16                   Yes 
Shared IO Pool Size   0                 Yes 
Granule Size 16                     No    --Granule Size 为16M 
Maximum SGA Size 1449.48828             No    --SGA_MAX_SIZE对应的值 
Startup overhead in Shared Pool    84.60112 No 
NAME    size(MB) RES 
-------------------------------- ---------- --- 
Free SGA Memory Available 592 


注意,resizeable值为NO的,都是不可动态调整的值, 
而所有可动态调整的几个内存组件则正好等于SGA_TARGET的值: 
2.12534332+7.359375+544+256+16+16+16+16+84.60112+592~1449.48828 

我们也可以从v$sga_dynamic_components这个视图了解各内存组件的内存分配情况,和v$sgainfo内容基本是一致的,除了没有展示Gradual Size这一项 
SQL> select component,current_size/1024/1024 "size(MB)" from v$sga_dynamic_components; 
COMPONENT                                                          size(MB) 
---------------------------------------------------------------- ---------- 
shared pool                                                             256 
large pool                                                               16 
java pool                                                                16 
streams pool                                                             16 
DEFAULT buffer cache                                                    544 
KEEP buffer cache                                                         0 
RECYCLE buffer cache                                                      0 
DEFAULT 2K buffer cache                                                   0 
DEFAULT 4K buffer cache                                                   0 
DEFAULT 8K buffer cache                                                   0 
DEFAULT 16K buffer cache                                                  0 
DEFAULT 32K buffer cache                                                  0 
Shared IO Pool                                                            0 
ASM Buffer Cache                                                          0 
14 rows selected 

SGA = shared pool + large pool + java pool + streams pool + DEFAULT buffer cache = 256+16+16+16+544=848M 
这个算出来的SGA值比SGA_TARGET的值少了4M,其实就是那个Gradual Size的值 

SQL> select name,issys_modifiable from v$parameter where name like '%sga%'; 
NAME                                ISSYS_MOD 
----------------------------------- --------- 
sga_max_size                        FALSE 
pre_page_sga                        FALSE 
lock_sga                            FALSE 
sga_target                          IMMEDIATE 
ISSYS_MODIFIABLE列的值为FALSE的,就是不能动态修改的参数,需重启生效,为IMMEDIATE的,即可以动态修改 

3.动态修改sga_target的值 
SQL> alter system set sga_target=1000m; 
System altered. 

SQL> alter system set sga_target=2000m; 
alter system set sga_target=2000m 

ERROR at line 1: 
ORA-02097: parameter cannot be modified because specified value is invalid 
ORA-00823: Specified value of sga_target greater than sga_max_size 

3.1 如果不带scope参数,默认为both,但要在内存中生效,必须满足SGA_TARGET<SGA_MAX_SIZE的条件,否则会报上述错误 

报错解决步骤: 
1)手动新建一个pfile 
vi pfilepoc.ora 
2)将原来的spfilepoc.ora里面的内容复制到pfilepoc.ora里面,修改里面错误的配置。 
3)startup pfile='/u02/oracle/dbs/pfilepoc.ora'; 
4)重新创建spfile 
create spfile from pfile='/u02/oracle/dbs/pfilepoc.ora'; 
5)再次重启 
shutdown immediate 
startup 

3.2 如果设置大于sga_max_size---启动会报错 
SQL> alter system set sga_target=2000m scope=spfile; --超过了sga_max_size的值1456M 
System altered. 
SQL> shutdown immediate; 
Database closed. 
Database dismounted. 
ORACLE instance shut down. 
--启动会报错 
SQL> startup 
ORA-00838: Specified value of MEMORY_TARGET is too small, needs to be at least 2016M  

尝试手动修改pfile里面的memory_target的值 
vi /u01/oracle/dbs/pfiletinadb.ora 
*.memory_target=2522532352 

遇到另外一个报错: 
SQL> startup pfile='/u01/oracle/dbs/pfiletinadb.ora' 
ORA-00845: MEMORY_TARGET not supported on this system 

报错是由于/dev/shm过小导致的,而且/dev/shm是一个tmpfs的文件系统,该文件系统是基于内存的,大小是随着物理内存的大小动态改变的, 
一般为物理内存的一半;tmpfs文件系统可以使用物理内容,也可以使用swap。 
/dev/shm的值必须大于memory_max_target 

[root@oratest ~]# df -Th /dev/shm 
Filesystem     Type   Size  Used Avail Use% Mounted on 
tmpfs          tmpfs  1.9G  861M  1.1G  45% /dev/shm 

[root@oratest ~]# vi /etc/fstab 
tmpfs                   /dev/shm         tmpfs   defaults,size=2G       0 0 
[root@oratest ~]# umount /dev/shm 
[root@oratest ~]# mount /dev/shm 
[root@oratest ~]# df -Th /dev/shm 
Filesystem     Type   Size  Used Avail Use% Mounted on 
tmpfs          tmpfs  2.0G     0  2.0G   0% /dev/shm 
SQL> startup pfile='/u01/oracle/dbs/pfiletinadb.ora'   
SQL> show parameter memory 
NAME      TYPE VALUE 
------------------------------------ ----------- ------------------------------ 
hi_shared_memory_address      integer 0 
memory_max_target      big integer 2000M 
memory_target       big integer 2000M 
shared_memory_address      integer 0 

SQL> show parameter sga 
NAME      TYPE VALUE 
------------------------------------ ----------- ------------------------------ 
lock_sga      boolean FALSE 
pre_page_sga      boolean FALSE 
sga_max_size      big integer 2000m   
sga_target      big integer 1504m 

spfile中的内容: 
*.memory_max_target=2097152000 
*.memory_target=2097152000 
*.sga_target=1577058304 

3.3 如果设置sga_max_size比sga_target小 
SQL> show parameter sga 
NAME      TYPE VALUE 
------------------------------------ ----------- ------------------------------ 
lock_sga      boolean FALSE 
pre_page_sga      boolean FALSE 
sga_max_size      big integer 1648M 
sga_target      big integer 1008M 
SQL> alter system set sga_max_size=500m scope=spfile; 
System altered. 

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

启动也会报错: 
SQL> startup 
ORA-00823: Specified value of sga_target greater than sga_max_size 

结论:在11g中,这个SGA_TARGET只能设置是小于等于SGA_MAX_SIZE的大小,设置比它小,oracle会自动帮你调整,设置比它大,会报错! 

4.设置的值与显示不同的原因: 
SQL> show parameter sga 

NAME                                 TYPE        VALUE 
------------------------------------ ----------- ------------------------------ 
lock_sga                             boolean     FALSE 
pre_page_sga                         boolean     FALSE 
sga_max_size                         big integer 1456M 
sga_target                           big integer 1408M 
可以看到,当调整了SGA_TARGET参数从0调整为1400M,这里还有个比较有意思的地方,这多出来的8M又是什么呢? 

SQL> select 1400/16 "Granual Count" from dual; 
Granual Count 
------------- 
         87.5 

SQL> select 88*16 "SGA_SIZE(MB)" from dual; 
SGA_SIZE(MB) 
------------ 
        1408 
刚才说了Granual Size的大小为16M,由于Granual必须完整地分配,因此会分配给SGA共88个Granual,即88*16=1408M,也就是多给了8M 

5.对比下,开启自动管理sga后,内部的参数发生了哪些变化: 
SQL> select component,current_size/1024/1024 "size(MB)" from v$sga_dynamic_components; 
COMPONENT                                                          size(MB) 
---------------------------------------------------------------- ---------- 
shared pool                                                             256 
large pool                                                               16 
java pool                                                                16 
streams pool                                                             16 
DEFAULT buffer cache                                                   1088    --这个值变化了。 
KEEP buffer cache                                                         0 
RECYCLE buffer cache                                                      0 
DEFAULT 2K buffer cache                                                   0 
DEFAULT 4K buffer cache                                                   0 
DEFAULT 8K buffer cache                                                   0 
DEFAULT 16K buffer cache                                                  0 
DEFAULT 32K buffer cache                                                  0 
Shared IO Pool                                                            0 
ASM Buffer Cache                                                          0 
14 rows selected 

SQL> select name,bytes/1024/1024 "size(MB)",resizeable from v$sgainfo; 
NAME                               size(MB) RESIZEABLE 
-------------------------------- ---------- ---------- 
Fixed SGA Size                   2.12534332 No 
Redo Buffers                       7.359375 No 
Buffer Cache Size                      1088 Yes 
Shared Pool Size                        256 Yes 
Large Pool Size                          16 Yes 
Java Pool Size                           16 Yes 
Streams Pool Size                        16 Yes 
Shared IO Pool Size                       0 Yes 
Granule Size                             16 No 
Maximum SGA Size                 1449.48828 No 
Startup overhead in Shared Pool  93.4275817 No 
Free SGA Memory Available                48      ---重要参数 
12 rows selected 

注意,48就是1456-1408得到的,相当于做了个预留,告诉SGA,你可以现在只用1408M 
但如果想增加,可以再多用48M,达到1456M。而这个时候只要SGA_TARGET重新设置的值没有超过SGA_MAX_SIZE的值,就可以在不停库的情况下增加SGA大小,这样做是有好处的 


6.关闭自动管理sga 
把SGA_TARGET设置为0,即表示禁用10g的新特性——自动分配内存,这样我们可以对各个内存组件的值进行单独设置,对于特殊的应用场景, 
有时候也是需要的 
SQL> alter system set sga_target=0; 
设置SGA_TARGET=0以后,已经分配的内存组件的值不会变化,如果不设置新值,那么依旧保持原来的值,除非单独设置, 
SQL> show parameter sga 
NAME      TYPE VALUE 
------------------------------------ ----------- ------------------------------ 
lock_sga      boolean FALSE 
pre_page_sga      boolean FALSE 
sga_max_size      big integer 1456M 
sga_target      big integer 0    


总结: 
1.SGA_MAX_SIZE是静态参数,而SGA_TARGET可以动态修改 

2.当先给SGA_MAX_SIZE设置了一个较大的值,重启数据库后,SGA_TARGET可以依然保持原有大小,相当于给SGA_TARGET先预留了一些内存, 
预先设置好SGA可分配内存,等到数据库出现压力导致SGA内存不足,可以直接通过sga_target动态修改到这一上限而无需停库。 

3.当给SGA_TARGET设置非零值时,表示采用内存组件内存由oracle动态调整,如shared pool,db buffer cache等,这些内存组件只会跟着 
SGA的大小动态进行调整(增大或减小),与其他值无关。 

4.当SGA_TARGET设置为零时,表示禁用内存组件由SGA自动管理,如果未做单独设置,那么保持原有值。此时可以根据具体场景需求,单独 
为某个内存组件配置合理的内存大小。 

5.在11g中,这个SGA_TARGET只能设置是小于等于SGA_MAX_SIZE的大小,设置比它小,oracle会自动帮你调整,设置比它大,会报错。
相关文章
|
8月前
|
前端开发
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
57 0
|
6月前
|
缓存 监控 时序数据库
influxdb报错:cache-max-memory-size exceeded
influxdb报错:cache-max-memory-size exceeded
213 0
|
8月前
|
Docker 容器
devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free dat
devmapper: Thin Pool has 162394 free data blocks which is less than minimum required 163840 free dat
77 0
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
193 0
|
缓存 应用服务中间件
Tomcat 警告:consider increasing the maximum size of the cache
Tomcat 警告:consider increasing the maximum size of the cache
574 0
Tomcat 警告:consider increasing the maximum size of the cache
|
SQL Oracle 关系型数据库
ORA-00821: Specified value of sga_target 3072M is too small, needs to be at least 12896M
在测试PlateSpine克隆的数据库服务器时,由于资源有限,克隆过来的数据库服务器只给了9G的内存,结果在测试时,老是会出现OOMkiller导致宕机,即out of memory killer,是linux下面当内存耗尽时的的一种处理机制。
2639 0
|
Oracle 关系型数据库 Java