Thứ Năm, 9 tháng 1, 2020

[VIP5]Bí quyết thiết lập tham số hugepages cho CSDL Oracle trên Linux_Update 19/04/203

Mục đích: Với Oracle Database chạy Linux Server từ 16GB SGA (mà chỉ cần >=8GB) thì nên sử dụng HugePages. Khi đó Oracle sẽ hoạt đọng hiệu quả hơn. Khi chúng ta cấu hình HugePage, Linux Kernel sẽ dùng page hớn (gọi là huge page). Thay vì 4K với Linux x86 và x86_64 hay 16 KB với IA64 chúng ta sẽ đặt  4 MB on x86, 2MB với x86_64 hay 256MB trên IA64. Page lớn hơn tức là hệ thống sẽ cần ít bảng quản lý page (page table) hơn, do đó việc ánh xạ giữa page table và block cần truy xuất.
Tuy nhiên giới hạn của Oracle là tính năng AMM (Automatic Memory Management) không hỗ trợ HugePages. Do đó AMM disable (memory_max_size = 0, memory_target=0) và thay bằng ASMM (Automatic Shared Memory Management), tức là cấu hình SGA_MAX_SIZE, SGA_TARGET.

Bước 1: Thiết lập tham số memlock trong file /etc/security/limits.conf để giới hạn khả năng sử dụng RAM của user, ví dụ hệ thống có 64GB RAM thì thiết lập tối đa 80% của RAM tính theo KB.
# vi /etc/security/limits.conf
*   soft   memlock    53687091
*   hard   memlock    53687091

Kiểm tra lại :
(oracle)$ ulimit -l

Bước 2:Disable AMM

 Với Oracle Database từ 11g trở đi thì disable AMM bằng các  tham số MEMORY_TARGET và MEMORY_MAX_TARGET (nếu có).
ALTER SYSTEM SET MEMORY_TARGET = 0 SCOPE=SPFILE;
ALTER SYSTEM SET MEMORY_MAX_TARGET = 0 SCOPE=SPFILE;

Bước 3: Thiết lập lại giá trị SGA cho Oracle DB (memory 80% tức là 51GB, SGA 80% tức 41GB còn lại 10GB cho PGA).
ALTER SYSTEM SET SGA_MAX_SIZE = 41G scope=spfile;
ALTER SYSTEM SET SGA_TARGET = 41G  scope=spfile;
ALTER SYSTEM SET PGA_AGGREGATE_LIMIT = 20G scope=spfile;
ALTER SYSTEM SET PGA_AGGREGATE_TARGET = 10G scope=spfile;

Bước 4: Restart DB.
Nếu không thay đổi tham số SGA_MAX_SIZE thì không cần phải làm bước này.

Bước 5: Tính toán và thiết lập giá trị hugepages.
Tính bằng tay:
- Kiểm tra Hugepagesize
grep Hugepagesize /proc/meminfo

Hugepagesize:       2048 kB
- Tính vm.nr_hugepages = SGA/Hugepagesize = 41*1024*1024/2048 +1 =20973
Hoặc Chạy script hugepages_settings.sh (từ My Oracle Support (MOS) note 401749.1).) để tính toán ra giá trị hugepages cần thiết lập. Giả sử giá trị cần đặt ở đây là 22960.
#!/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.
# 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'}`
# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1
# 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
# 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  
$ chmod u+x ./hugepages_setting.sh  
$ ./hugepages_settings.sh
.
.
.
Recommended setting: vm.nr_hugepages = 20973

Bước 6: Từ root, Sửa file /etc/sysctl.conf và thiết lập tham số vm.nr_hugepages theo giá trị tính toán ở trên:
vm.nr_hugepages = 20973

Thiết lập thêm tham số: 
    kernel.shmall=13421773 (=shmmax/shmmni)
    kernel.shmmax=54975581389 (=80% RAM)

Bước 7:  Shutdown tất cả các DB instance và reboot server 

hoặc không cần reboot thì thực hiện # sysctl -p

Bước 8: Kiểm tra lại cấu hình.
Sau khi server và DB lên, kiểm tra lại cấu hình xem có chuẩn không.
# grep HugePages /proc/meminfo
HugePages_Total:    20973
HugePages_Surp:        0

# grep ^Huge /proc/meminfo
HugePages_Total:   20973
HugePages_Free:    100
HugePages_Rsvd:     2016
HugePages_Surp:        0
Hugepagesize:       2048 kB
Tham số tham khảo: 0.8 là 80% RAM vật lý, 0.65 là 65% RAM vật lý, tôi hay sử dụng 80% RAM, còn anh em thửa RAM có thể đặt 65% RAM vật lý cho memory (SGA+PGA):

Loại DBMemory (GB)Khuyến nghịSGA (GB)PGA (GB)shmmni (byte)shmmax(byte)shmallhugepage_size(KB)Hugepagelimits.conf (KB)
OLTP5120.83288240964398046511101073741822048167773429496730
OLTP5120.65266674096357341279027872415232048136316348966093
OLTP2560.816441409621990232555553687091204883887214748365
OLTP2560.6513333409617867063951443620762204868158174483046
OLTP1920.812331409616492674416640265318204862916161061274
OLTP1920.6510025409613400297963532715571204851119130862285
OLTP1600.810226409613743895347233554432204852430134217728
OLTP1600.658321409611166914969627262976204842599109051904
OLTP1280.88220409610995116277826843546204841944107374182
OLTP1280.6567174096893353197572181038120483408087241523
OLTP960.861154096824633720832013265920483145880530637
OLTP960.6550124096670014898181635778620482556065431142
OLTP940.860154096807453851651971322920483080378852915
OLTP940.6549124096656056254461601699820482502864067994
OLTP640.841104096549755813891342177320482097353687091
OLTP640.653384096446676598781090519020481704043620762
OLTP320.8205409627487790694671088620481048726843546
OLTP320.6517440962233382993954525952048852121810381
OLTP160.810340961374389534733554432048524413421773
OLTP160.658240961116691497027262982048426110905190
=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: http://bit.ly/ytb_binhoraclemaster
👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhoracle
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
Bí quyết thiết lập tham số hugepages cho CSDL Oracle trên Linux_Update 19/04/203, oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master