shmmax/shmall和sga_max_size/sga_target应该设置多大

2013-04-10

linux环境安装oracle时候,如果有32G内存,CentOS 5.8 64bit安装oracle10g 64bit。那么shmmax/shmall和sga_max_size/sga_target这4个参数到底应该设置多大呢?因为每个数据库需求和压力都不尽相同,这里只能给出一些相对值供大家参考。

1、两个参考
参考值1:
OLTP服务器8G
kernel.shmall = 2097152
kernel.shmmax = 8589934592
sga_max_size big integer 4G
sga_target big integer 4G

参数值2:
OLAP服务器16G
kernel.shmall = 4194304
kernel.shmmax = 17179869184
sga_max_size big integer 12G
sga_target big integer 12G

# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296

2、kernel.SHMMAX
cat /etc/sysctl.conf |grep -B1 shmmax
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 68719476736

SHMMAX Available physical memory Defines the maximum allowable size
of one shared memory segment. The SHMMAX setting should be large enough
to hold the entire SGA in one shared memory segment. A low setting can
cause creation of multiple shared memory segments which may lead to
performance degradation.

Oracle recommends half the RAM.

shmmax 设置应该足够大,能在一个共享内存段下容纳下整个的SGA ,设置的过低可能会
导致需要创建多个共享内存段,这样可能导致系统性能的下降 。

Oracle 安装文档建议 32Bit Linux 系统设置shmmax 为32Bit 最大的限制值
(setting shmmax to the 32-bit number limit),也就是4G

一般设置shmmax >=SGA (32Bit 系统是否支持到1.7G 以上SGA 需要注意) 。
如果是64Bit 的Linux 操作系统,shmmax 设置为大于SGA_MAX_SIZE 即可。

ipcs -sa 可以看到共享内存段个数

3、kernel.SHMALL
[root@db03 ~]# cat /etc/sysctl.conf |grep -B1 shmall
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 4294967296

the maximum amount of memory = shmall * pagesize
where pagesize = getconf PAGE_SIZE and shmall = cat /proc/sys/kernel/shmall

kernel.shmall 参数是控制共享内存页数 。Linux 共享内存页大小为4KB, 共享内存段的大小都是共享内存页大小的整数倍。

一个共享内存段的最大大小是16G,那么需要共享内存页数是 16GB/4KB=16777216KB/4KB=4194304 (页),也就是64Bit 系统下16GB 物理内存,设置 kernel.shmall = 4194304 才符合要求(几乎是原来设置2097152的两倍)。这时可以将shmmax 参数调整到 16G 了,同时可以修改SGA_MAX_SIZE 和SGA_TARGET 为 12G(您想设置的SGA 最大大小,当然也可以是2G~14G 等,还要协调PGA参数及OS 等其他内存使用,不能设置太满,比如16G)。

4、kernel.shmmni
shmmni 内核参数是共享内存段的最大数量(注意这个参数不是 shmmin,是
shmmni, shmmin 表示内存段最小大小 ) 。shmmni 缺省值 4096 ,一般肯定是够用了 。

5、SGA_MAX_SIZE

SGA_MAX_SZIE 为实例允许使用的SGA 上限,一个静态参数,是不能动态修改的.
SGA_TARGET 为10g 推出的sga 自动管理的参数,动态参数,可以动态修改.

当oracle初始化启动时,如果sga_max_size的值小于显式的指定的各sga组件值之和,则oracle将会忽略sga_max_size

修改方法1:
vi initSID.ora

*.sga_max_size=4294967296
*.sga_target=4294967296
修改方法2:
create pfile from spfile;
alter system set sga_max_size=4G scope=spfile;
alter system set sga_target=4G scope=spfile;

注:需要重启Oracle实例才能生效。

6、 SGA_TARGET
在11g 中,这个SGA_TARGET 只能设置是等于SGA_MAX_SIZE 的大小了,设置比它小,oracle 会自动帮你调整,设置比它大,那还是出错。

select * from tab where tname like '%ADVICE%';
select * from v$sga_target_advice order by sga_size;

7、例如
1)、system A
MemTotal: 16387608 kB

The following is an example of a Linux based database server running two database instances with approx. 8 GB SGA in total. At the time of sampling there are 444 dedicated server sessions connected.

2)、System B is a Linux based system with 128 GB memory running one single database instance with 34 GB SGA and approx 400 sessions:

3)、shmall 是全部允许使用的共享内存大小,shmmax 是单个段允许使用的大小。这两个可以设置为内存的 90%。
例如 16G 内存,16*1024*1024*1024*90% = 15461882265,shmall 的大小为 15461882265/4k(getconf PAGE_SIZE可得到) = 3774873。
修改
/etc/sysctl.conf
kernel.shmmax=15461882265
kernel.shmall=3774873

sga_max_size big integer 12G
sga_target big integer 12G

8、总结:
SHMMAX = 内存的50%--80%
SHMALL = SGA/PAGE_SIZE(pagesize = getconf PAGE_SIZE)
SGA_MAX_SIZE = < SHMMAX SGA_TARGET = SGA_MAX_SIZE(根据V$SGA_TARGET_ADVICE设置)

分类:数据库 | 标签: |

相关日志

评论被关闭!