温馨提示×

ubuntu如何优化oracle

小樊
41
2026-09-20 02:55:04
栏目: 云计算

在 Ubuntu 上优化 Oracle 数据库(通常指 Oracle Database,多为 19c / 21c / 23c 等 Linux 版本),可以从操作系统层、内核参数、文件系统、Oracle 参数、资源限制、监控几个方面入手。下面给你一套比较实用、可落地的优化清单。


一、系统基础优化(Ubuntu 层)

1. 使用合适的 Ubuntu 版本

  • 推荐使用 Ubuntu 20.04 / 22.04 LTS
  • 使用 Server 版,关闭图形界面
  • 内核建议使用 HWE 内核
uname -a

2. 关闭不必要的服务

systemctl disable bluetooth
systemctl disable cups
systemctl disable snapd

3. 使用高性能 CPU 模式

apt install linux-tools-common
cpupower frequency-set -g performance

开机自动:

systemctl enable cpupower

二、内核参数优化(非常重要)

编辑 /etc/sysctl.conf

# 内存与共享内存
kernel.shmmax = 68719476736
kernel.shmall = 16777216
kernel.shmmni = 4096

# 信号量
kernel.sem = 250 32000 100 128

# 文件句柄
fs.file-max = 6815744

# 网络
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576

# Swap 使用策略
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5

应用:

sysctl -p

三、用户资源限制(Oracle 用户)

编辑 /etc/security/limits.conf

oracle soft nofile 65536
oracle hard nofile 65536
oracle soft nproc 16384
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768

确保 PAM 加载:

/etc/pam.d/common-session
session required pam_limits.so

四、文件系统与磁盘 IO 优化

1. 推荐使用文件系统

  • XFS(首选)
  • ❌ 不推荐 ext4(高并发下稍弱)
mkfs.xfs /dev/sdb

挂载参数示例:

/dev/sdb /u01 xfs defaults,noatime,nodiratime 0 0

2. 分离磁盘

建议:

  • /u01:Oracle 软件
  • /u02:数据文件
  • /u03:redo / archive

3. 使用多路径 / SSD / NVMe

  • 日志盘用 低延迟 SSD
  • 数据盘可用 RAID 10

五、Oracle 数据库参数优化

1. 内存参数(示例:64G 内存)

ALTER SYSTEM SET sga_target=40G SCOPE=SPFILE;
ALTER SYSTEM SET pga_aggregate_target=12G SCOPE=SPFILE;
ALTER SYSTEM SET memory_target=0 SCOPE=SPFILE;

2. 进程与连接

ALTER SYSTEM SET processes=2000 SCOPE=SPFILE;
ALTER SYSTEM SET sessions=3000 SCOPE=SPFILE;

3. redo / undo

ALTER DATABASE ADD LOGFILE GROUP 4 SIZE 2G;
ALTER SYSTEM SET undo_retention=1800;

4. 并行与 IO

ALTER SYSTEM SET db_writer_processes=4;
ALTER SYSTEM SET disk_asynch_io=TRUE;

六、Oracle 服务与启动优化

1. 使用 systemd 管理 Oracle

示例 /etc/systemd/system/oracle.service

[Unit]
Description=Oracle Database
After=network.target

[Service]
User=oracle
Type=forking
Environment=ORACLE_HOME=/u01/app/oracle/product/19c/dbhome_1
ExecStart=/u01/app/oracle/product/19c/dbhome_1/bin/dbstart
ExecStop=/u01/app/oracle/product/19c/dbhome_1/bin/dbshut

[Install]
WantedBy=multi-user.target

七、监控与调优工具

# OS
top, htop, iostat -x 1, vmstat 1

# Oracle
sqlplus / as sysdba
SELECT * FROM v$sysstat;
SELECT * FROM v$session_wait;

八、常见性能问题速查

问题 可能原因
CPU 高 缺少索引 / 硬解析
IO 高 redo 小 / 随机写
内存换页 swappiness 高
连接慢 processes 不足

如果你愿意,可以告诉我:

  • Oracle 版本(19c / 21c?)
  • 内存 & CPU 配置
  • 主要用途(OLTP / 数据仓库)

我可以给你更精确的参数模板

0