SQL> show parameter sga
NAME TYPE VALUE
------------------------------------ ----------- -------------------------
lock_sga boolean FALSE
pre_page_sga boolean FALSE
sga_max_size big integer 416M
sga_target big integer 200M
SQL> alter system set sga_target=500m scope=spfile ;
alter system set sga_target=500m scope=spfile ;
*
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
SQL> select name,bytes/1024/1024 m from v$sgainfo;
NAME M
-------------------------------- ----------
Fixed SGA Size 1.27510452
Redo Buffers 5.78515625
Buffer Cache Size 80
Shared Pool Size 148
Large Pool Size 4
Java Pool Size 4
Streams Pool Size 0
Shared IO Pool Size 0
Granule Size 4
Maximum SGA Size 415.0625
Startup overhead in Shared Pool 52
NAME M
-------------------------------- ----------
Free SGA Memory Available 172
12 rows selected.
案例:设置sga_target
SQL> ALTER system SET sga_max_size=1000m scope=spfile;
SQL> ALTER system SET sga_target=1000m scope=spfile;
关闭数据库
shutdown immediate;
启动数据库
startup;
注意:
#修改/dev/shm的大小为2g: 要修改etc/fstab 文件,然后重新挂载一下。
[root@gc1 ~]vi etc/fstab
#重新挂载
只需要设置一个目标内存大小初始化参数( MEMORY_TARGET ) 和一个最大内存大小初始化参数( MEMORY_MAX_TARGET),数据库就会根据处理需求在SGA 与实例 PGA 之间动态交换内存。
③.自动内存管理是用两个初始化参数进行配置的:
MEMORY_TARGET:动态控制SGA和PGA时,Oracle总共可以使用的共享内存大小,这个参数是动态的,因此提供给Oracle的内存总量是可以动态增大,也可以动态减小的。它不能超过MEMORY_MAX_TARGET参数设置的大小。默认值是0。
MEMORY_MAX_TARGET:这个参数定义了MEMORY_TARGET最大可以达到而不用重启实例的值,如果没有设置MEMORY_MAX_TARGET值,默认等于MEMORY_TARGET的值。
使用动态内存管理时,SGA_TARGET和PGA_AGGREGATE_TARGET代表它们各自内存区域的最小设置,要让Oracle完全控制内存管理,这两个参数应该设置为0。但并不会因为设置了MEMORY_TARGET,这两个参数就会自动变回0。
④.ORACLE的内存管理参数下图所示:
3.shared pool的调整:
#查看shared pool 参数 (为0表示shared pool为自动管理)
SQL> show parameter shared_pool_size
NAME TYPE VALUE
------------------------------------ ----------- -------------------------
shared_pool_size big integer 0
#查看shared pool的真实大小
SQL> select name,bytes/1024/1024 m from v$sgainfo;
NAME M
-------------------------------- ----------
Fixed SGA Size 1.27510452
Redo Buffers 5.78515625
Buffer Cache Size 80
Shared Pool Size 148
Large Pool Size 4
Java Pool Size 4
Streams Pool Size 0
Shared IO Pool Size 0
Granule Size 4
Maximum SGA Size 415.0625
Startup overhead in Shared Pool 52
#调大shared pool 的值
SQL> alter system set shared_pool_size=160m ;
System altered.
#查询
SQL> select name,bytes/1024/1024 m from v$sgainfo;
NAME M
-------------------------------- ----------
Fixed SGA Size 1.27510452
Redo Buffers 5.78515625
Buffer Cache Size 68
Shared Pool Size 160
Large Pool Size 4
Java Pool Size 4
Streams Pool Size 0
Shared IO Pool Size 0
Granule Size 4
Maximum SGA Size 415.0625
Startup overhead in Shared Pool 52
NAME M
-------------------------------- ----------
Free SGA Memory Available 172
12 rows selected.
#调小 shared pool的值, 发现shared pool还是160m,所以shared pool 只能调大不能调小。
SQL> alter system set shared_pool_size=148m;
System altered.
SQL> select name,bytes/1024/1024 m from v$sgainfo;
NAME M
-------------------------------- ----------
Fixed SGA Size 1.27510452
Redo Buffers 5.78515625
Buffer Cache Size 68
Shared Pool Size 160
Large Pool Size 4
Java Pool Size 4
Streams Pool Size 0
Shared IO Pool Size 0
Granule Size 4
Maximum SGA Size 415.0625
Startup overhead in Shared Pool 52
NAME M
-------------------------------- ----------
Free SGA Memory Available 172
12 rows selected.
二.案例总结:
1.swap区大小设置:
关于操作系统,一般Swap区的推荐值为2*RAM。如果物理内存(RAM)很大,不一定非要把Swap设置为2xSwap,通常可以设置Swap = Ram或者小于物理内存(如内存超过32G则完全可以设置Swap为16G )。
如果物理内存(RAM)过小,在系统繁忙期间,产生大量交换无法换到磁盘,就会出现问题。
另外,如果系统物理内存较小,通常设置SGA < 1/2 Ram ,要考虑为Server process 的PGA消耗及OS保留足够的内存空间.