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_Updated 28/06/2026

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.

Case study RAM 100GB/node

Tham sốKhuyến nghịGhi chú
Physical Memory100GBTheo từng node RAC
Oracle memory thiết kế~70GBChừa tối thiểu ~30% cho OS/Grid/ASM/cache/process khác theo khuyến nghị Oracle HugePages
SGA_TARGET60GĐưa vào HugePages
SGA_MAX_SIZE60GBằng SGA_TARGET để dễ kiểm soát
PGA_AGGREGATE_TARGET10GPGA là private memory, không nằm trong HugePages; Oracle mô tả đây là target aggregate PGA cho server process
PGA_AGGREGATE_LIMIT20G hoặc cao hơn theo PROCESSESMặc định tối thiểu thường là 200% PGA target; RAC còn tối thiểu 5MB × PROCESSES
hugepage_size2048 KBThường gặp trên Linux x86_64
vm.nr_hugepages3080060G / 2MB = 30720, cộng dư nhẹ
kernel.shmmax9663676416090GB, đủ lớn hơn SGA
kernel.shmall2359296090GB / 4096
limits.conf memlock94371840 KB90GB; Oracle docs cho phép đặt cao hơn SGA requirement và ví dụ dùng ~90% RAM khi bật HugePages
USE_LARGE_PAGESONLYOracle khuyến nghị để đảm bảo hiệu năng ổn định
MEMORY_TARGET / MEMORY_MAX_TARGET0Không dùng AMM với HugePages

Runbook triển khai

1. Kiểm tra trước khi thay đổi

    free -g
grep Huge /proc/meminfo
getconf PAGE_SIZE
cat /sys/kernel/mm/transparent_hugepage/enabled
ulimit -l
    show parameter memory_target
show parameter memory_max_target
show parameter sga
show parameter pga
show parameter use_large_pages
show parameter processes

Nếu PROCESSES > 4096, kiểm tra lại PGA_AGGREGATE_LIMIT vì RAC yêu cầu tối thiểu 5MB * PROCESSES.

2. Cấu hình Oracle memory

    ALTER SYSTEM SET memory_target=0 SCOPE=SPFILE SID='*';
ALTER SYSTEM SET memory_max_target=0 SCOPE=SPFILE SID='*';

ALTER SYSTEM SET sga_target=60G SCOPE=SPFILE SID='*';
ALTER SYSTEM SET sga_max_size=60G SCOPE=SPFILE SID='*';

ALTER SYSTEM SET pga_aggregate_target=10G SCOPE=SPFILE SID='*';
ALTER SYSTEM SET pga_aggregate_limit=20G SCOPE=SPFILE SID='*';

ALTER SYSTEM SET use_large_pages=ONLY SCOPE=SPFILE SID='*';

3. Cấu hình kernel

Tạo file:

vi /etc/sysctl.d/97-oracle-memory.conf

Nội dung:

    kernel.shmmax = 96636764160
kernel.shmall = 23592960
vm.nr_hugepages = 30800

Apply:

sysctl -p /etc/sysctl.d/97-oracle-memory.conf

4. Cấu hình limits.conf

vi /etc/security/limits.d/99-oracle-memlock.conf

Nội dung:

    oracle soft memlock 94371840
oracle hard memlock 94371840
grid soft memlock 94371840
grid hard memlock 94371840

Đăng nhập lại user oracle/grid, kiểm tra:

    su - oracle
ulimit -l

Kỳ vọng:

    94371840

5. Disable THP cho Oracle 19c

Với Oracle 19c, nên dùng static HugePages cho toàn bộ SGA; Oracle blog mới cũng phân biệt rõ static HugePages cho SGA và THP chỉ nên theo khuyến nghị mới hơn từ 23ai/UEK mới.

    cat /sys/kernel/mm/transparent_hugepage/enabled

Kỳ vọng với 19c truyền thống:

    always madvise [never]

6. Restart rolling từng node RAC

    srvctl stop instance -d <DB_UNIQUE_NAME> -i <INSTANCE_NAME>
srvctl start instance -d <DB_UNIQUE_NAME> -i <INSTANCE_NAME>

Làm từng node, không restart đồng loạt.

7. Kiểm tra sau triển khai

    grep Huge /proc/meminfo
free -g
    select inst_id, name, value
from gv$parameter
where name in (
'memory_target',
'memory_max_target',
'sga_target',
'sga_max_size',
'pga_aggregate_target',
'pga_aggregate_limit',
'use_large_pages'
)
order by inst_id, name;

Kiểm tra alert log phải thấy SGA dùng Large Pages/HugePages. Nếu DB không startup với USE_LARGE_PAGES=ONLY, nghĩa là HugePages hoặc memlock chưa đủ.

Kết luận: với RAM 100GB/node, cấu hình an toàn là SGA 60G, PGA target 10G, PGA limit 20G, HugePages 30800, memlock 90GB.

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)kernel.shmmni (byte)kernel.shmall=shmmax/shmmnikernel.shmmax(byte)
=90%RAM
hugepage_size(KB)Hugepagelimits.conf (KB)=90%RAM
OLTP5120,72877140961207959554947802324992048146994483183821
OLTP5120,652666740961207959554947802324992048136242483183821
OLTP2560,714336409660397978247390116250204873266241591910
OLTP2560,6513333409660397978247390116250204868146241591910
OLTP1920,710826409645298483185542587187204855346181193933
OLTP1920,6510025409645298483185542587187204851250181193933
OLTP1600,79022409637748736154618822656204846130150994944
OLTP1600,658321409637748736154618822656204842546150994944
OLTP1280,77218409630198989123695058125204836914120795955
OLTP1280,656716409630198989123695058125204834354120795955
OLTP960,754134096226492429277129359420482769890596966
OLTP960,6550124096226492429277129359420482565090596966
OLTP940,753134096221773829083855831020482718688709530
OLTP940,6549124096221773829083855831020482513888709530
OLTP640,73694096150994946184752906220481848260397978
OLTP640,653394096150994946184752906220481694660397978
OLTP320,718440967549747309237645312048926630198989
OLTP320,6517440967549747309237645312048875430198989
Ghi chú: 
+ Khuyến nghị 0.7 là dùng 0.7ức là 70% RAM vật lý; 0.65 là dùng 65% RAM vật lý
+ SGA lấy làm tròn lên =ROUND(B2*C2*0.8,0) (80% memory với OLTP, DWH 50%)
+ shmmax (B) = C7*B7*1024*1024*1024 (90% RAM)
+ shmall=H/4096 (shmmax/shmmni)
+ hugepage=(D9*1024*1024/I9)+1 (SGA(MB)/2+1)
+ limits.conf (KB) =90%RAM

ĐỌC THÊM:


Hy vọng hữu ích cho bạn.
=============================
* 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 
hữ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:
=============================
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