暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle数据库上开启大页

学徒杨新建 2018-05-11
579

今天在调整线上数据库,服务器增大内存后,数据库需要调整大页,这其中发现这个过程中总是调整的不完全,这里做一个简单总结。

1.现有环境是oracle 11.2.0.1,需要关闭AMM,设置memory_max_target和memory_target成0表示不成功

SQL> show parameter memory_max_target


NAME   TYPE          VALUE

-----------------  ------------  ------------

memory_max_target  big integer   0

SQL> show parameter memory_target


NAME   TYPE          VALUE

-----------------  ------------  ------------

memory_target   big integer   0

2.运行脚本 hugepages_settings.sh

这个脚本是Oracle官方提供的,运行这个脚本即可得出大页的设置值,参考metalink(文档 ID 401749.1),脚本如下:

#!/bin/bash

#

# hugepages_settings.sh

#

# Linux bash script to compute values for the

# recommended HugePages/HugeTLB configuration

#

# Note: This script does calculation for all shared memory

# segments available when the script is run, no matter it

# is an Oracle RDBMS shared memory segment or not.

#

# This script is provided by Doc ID 401749.1 from My Oracle Support

# http://support.oracle.com


# Welcome text

echo "

This script is provided by Doc ID 401749.1 from My Oracle Support

(http://support.oracle.com) where it is intended to compute values for

the recommended HugePages/HugeTLB configuration for the current shared

memory segments. Before proceeding with the execution please make sure

that:

 * Oracle Database instance(s) are up and running

 * Oracle Database 11g Automatic Memory Management (AMM) is not setup

   (See Doc ID 749851.1)

 * The shared memory segments can be listed by command:

     # ipcs -m


Press Enter to proceed..."


read


# Check for the kernel version

KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`


# Find out the HugePage size

HPG_SZ=`grep Hugepagesize proc/meminfo | awk '{print $2}'`


# Initialize the counter

NUM_PG=0


# Cumulative number of pages required to handle the running shared memory segments

for SEG_BYTES in `ipcs -m | awk '{print $5}' | grep "[0-9][0-9]*"`

do

   MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`

   if [ $MIN_PG -gt 0 ]; then

      NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`

   fi

done


RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`


# An SGA less than 100MB does not make sense

# Bail out if that is the case

if [ $RES_BYTES -lt 100000000 ]; then

   echo "***********"

   echo "** ERROR **"

   echo "***********"

   echo "Sorry! There are not enough total of shared memory segments allocated for

HugePages configuration. HugePages can only be used for shared memory segments

that you can list by command:


   # ipcs -m


of a size that can match an Oracle Database SGA. Please make sure that:

 * Oracle Database instance is up and running

 * Oracle Database 11g Automatic Memory Management (AMM) is not configured"

   exit 1

fi


# Finish with results

case $KERN in

   '2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;

          echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;

   '2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;

    *) echo "Unrecognized kernel version $KERN. Exiting." ;;

esac


# End




执行这个脚本得出大页的设置值 66563

[oracle@ams_odbs_26_21 ~]$ chmod +x hugepages_settings.sh

[oracle@ams_odbs_26_21 ~]$ sh hugepages_settings.sh


hugepages_settings.sh: line 1: [oracle@newdb2: command not found


This script is provided by Doc ID 401749.1 from My Oracle Support

(http://support.oracle.com) where it is intended to compute values for

the recommended HugePages/HugeTLB configuration for the current shared

memory segments. Before proceeding with the execution please make sure

that:

 * Oracle Database instance(s) are up and running

 * Oracle Database 11g Automatic Memory Management (AMM) is not setup

   (See Doc ID 749851.1)

 * The shared memory segments can be listed by command:

     # ipcs -m


Press Enter to proceed...


Recommended setting: vm.nr_hugepages = 66563


3.更改系统参数

vi /etc/sysctl.conf


kernel.shmmax = 139586437120  

kernel.shmall = 34078720

kernel.shmmni = 4096

vm.nr_hugepages = 66564

kernel.shmmax:单个共享内存段的最大值,要大于oracle数据库中的SGA的大小, 单位是字节 
kernel.shmall: 共享内存页数,Linux 共享内存页大小为4KB 这个值等于kernel.shmmax/kernel.shmmni 
kernel.shmmni :享内存段的最大数量,默认4K 就是4096 
修改完成之后,使用命令 sysctl -p 使得参数生效。

附加:sysctl -p 命令结束后发现的问题:

问题 sysctl -p 的出的结果中发现报错

error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key

error: "net.bridge.bridge-nf-call-iptables" is an unknown key

error: "net.bridge.bridge-nf-call-arptables" is an unknown key


解决方法:加载模块后解决

modprobe bridge

修改limits.conf文件,这个文件限制着用户可以使用的最大文件数,最大线程,最大内存等资源使用量,添加最后两行

(memlock 单位是KB) 必须大于sga_max_size: 130G

vi /etc/security/limits.conf


oracle              soft    nproc   65535

oracle              hard    nproc   65535

oracle              soft    nofile  655350

oracle              hard    nofile  655350

oracle              soft    stack   10240

oracle          soft    memlock 136314880

oracle          hard    memlock 136314880

还有一个文件也需要修改,/etc/security/limits.d/90-nproc.conf (这个文件在Centos6.5中是90-nproc.conf,在7之后就是20-nproc.conf)

cd /etc/security/limits.d/

[root@ams_odbs_26_21 limits.d]# vi  90-nproc.conf

# Default limit for number of user's processes to prevent

# accidental fork bombs.

# See rhbz #432903 for reasoning.


*
         soft    nproc     65535

root       soft    nproc     unlimited

修改完成之后,切换到oracle用户下查看是否生效

[oracle@ams_odbs_26_21 ~]$ ulimit -a

core file size        (blocks, -c) 0

data seg size         (kbytes, -d) unlimited

scheduling priority         (-e) 0

file size             (blocks, -f) unlimited

pending signals               (-i) 2059863

max locked memory     (kbytes, -l) 136314880

max memory size       (kbytes, -m) unlimited

open files                    (-n) 655350

pipe size          (512 bytes, -p) 8

POSIX message queues   (bytes, -q) 819200

real-time priority            (-r) 0

stack size              (kbytes, -s) 10240

cpu time               (seconds, -t) unlimited

max user processes              (-u) 65535

virtual memory          (kbytes, -v) unlimited

file locks                      (-x) unlimited

4.重启数据库,大页才会被使用,重启过程省略。

5.查看大页是否被使用

[oracle@ams_odbs_26_21 ~]$ cat /proc/meminfo |grep -i HugePage

AnonHugePages:    681984 kB

HugePages_Total:   66564

HugePages_Free:    63228

HugePages_Rsvd:    63224

HugePages_Surp:        0

Hugepagesize:       2048 kB

HugePages_Total: 66564 —总共66564页 
HugePages_Free: 63228 —空闲63228页,即当前大页被使用了66564-63228=3236页,即被用了3236*2M=6472M,小于sga_target。 
HugePages_Rsvd: 63224 —操作系统承诺给Oracle预留63224页 
Hugepagesize: 2048 kB –每页是2M,不可修改


文章转载自学徒杨新建,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论