Upon startup of Linux database get ORA-27102: out of memory Linux-X86_64 Error: 28: [ID 301830.1]

本文介绍了解决在Linux 64位系统上启动Oracle数据库时遇到的ORA-27102: out of memory错误的方法。该问题通常发生在尝试将SGA设置接近系统可用RAM一半的情况下,尽管shmmax已正确配置。文章详细解释了如何调整shmall参数来解决此问题。

Upon startup of Linux database get ORA-27102: out of memory Linux-X86_64 Error: 28: No space left on device [ID 301830.1]

Applies to:

Oracle Server - Enterprise Edition - Version: 9.2.0.4 to 11.2.0.2 - Release: 9.2 to 11.2
Red Hat Enterprise Linux Advanced Server x86-64 (AMD Opteron Architecture)
x86 64 bit (for Enterprise Linux only)
SUSE / UnitedLinux x86-64

Symptoms

When trying to increase the SGA to approach half available RAM with an Oracle 64bit version on a Linux 64bit operating system, even thoughshmmaxis set to match half the amount of RAM, you get the following error when trying to start the instance:

SQL> startup nomount
ORA-27102: out of memory
Linux-x86_64 Error: 28: No space left on device

Changes

shmallis too small, most likely is set to the default setting of 2097152

$ cat /proc/sys/kernel/shmall
2097152

Cause

shmallis the total amount of shared memory, in pages, that the system can use at one time.

Solution

Setshmallequal to the sum of all the SGAs on the system, divided by the page size.

The page size can be determined using the following command:

$ getconf PAGE_SIZE
4096

For example, if the sum of all the SGAs on the system is 16Gb and the result of'$ getconf PAGE_SIZE'is 4096 (4Kb) then set shmall to 4194304 pages

As the root user set theshmallto 4194304 in the /etc/sysctl.conf file:

kernel.shmall = 4194304

then run the following command:

# sysctl -p
# cat /proc/sys/kernel/shmall
4194304

NOTE:

The above command loads the new value and a reboot is not necessary

Switch back to being the oracle user and retry the startup command.

From Oracle

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

你遇到的错误: ``` ORA-27102: out of memory Linux-x86_64 Error: 28: No space left on device Additional information: 8388608 Additional information: 1 ``` 虽然提示是 "No space left on device",但这个错误 **通常不是磁盘空间不足**,而是 **共享内存(Shared Memory)或大页内存(HugePages)配置问题**,尤其是在 Oracle 数据库启动时分配 SGA 失败的情况下。 --- ### 🔍 错误分析 - `ORA-27102: out of memory`:Oracle 无法分配所需的系统内存。 - `Error: 28: No space left on device`:这是 Linux 内核返回的误导性错误,实际上是指 **共享内存段无法创建**,可能因为: - 系统限制了共享内存大小(`shmmax`, `shmall`) - 使用了 HugePages,但配置不当或内存不足 - `/dev/shm` 空间不够(如果使用了临时文件系统) - `Additional information: 8388608`:表示 Oracle 想要分配的页数(这里是 8,388,608 页) - `Additional information: 1`:通常是子错误码,表示内存类型(如 shared memory segment) --- ## ✅ 解决方案 ### ✅ 方案一:检查并调整内核参数(`/etc/sysctl.conf`) Oracle 实例需要足够的共享内存来分配 SGA。请检查以下参数: ```bash # 查看当前设置 sysctl kernel.shmmax sysctl kernel.shmall sysctl kernel.shmmni ``` #### 推荐设置(根据你的物理内存调整): 假设你有 16GB 内存(16 * 1024^3 = 17179869184 字节),可设置如下: ```conf # 编辑 /etc/sysctl.conf kernel.shmmax = 17179869184 # 最大共享内存段,建议为物理内存的 80%~100% kernel.shmall = 4194304 # 可用共享内存总页数(shmall = shmmax / page_size;page_size=4096 → 17179869184/4096≈4194304) kernel.shmmni = 4096 # 共享内存段数量限制 ``` 应用配置: ```bash sysctl -p ``` > ⚠️ 注意:`shmmax` 应 ≥ Oracle 的 SGA 大小。 --- ### ✅ 方案二:检查 `/dev/shm` 大小 Oracle 在某些模式下会使用 `/dev/shm`(tmpfs),默认挂载大小可能是 RAM 的一半。 ```bash df -h /dev/shm ``` 输出示例: ``` tmpfs 8G 0 8G 0% /dev/shm ``` 如果你的 SGA 超过了这个值(比如 SGA 是 10G,而 `/dev/shm` 只有 8G),就会失败。 #### 解决方法:重新挂载更大的 `/dev/shm` ```bash mount -o remount,size=12g /dev/shm ``` 永久生效:修改 `/etc/fstab` ```conf tmpfs /dev/shm tmpfs defaults,size=12g 0 0 ``` --- ### ✅ 方案三:检查 HugePages 配置(常见根源!) 如果启用了 HugePages,但未预留足够内存,也会导致 ORA-27102。 #### 检查是否启用 HugePages: ```bash grep Huge /proc/meminfo ``` 输出类似: ``` AnonHugePages: 2048 kB HugePages_Total: 2000 HugePages_Free: 1000 HugePages_Rsvd: 800 Hugepagesize: 2048 kB ``` - 如果 `HugePages_Total > 0`,说明已启用。 - Oracle 启动时必须有足够的 **Free + Reserved** HugePages。 #### 计算所需 HugePages 数量: 你需要知道 Oracle SGA 总大小(比如 8GB): ```bash SGA_SIZE_KB=8388608 # 8GB in KB HUGEPAGE_SIZE_KB=2048 # Usually 2MB NUM_HUGEPAGES=$((SGA_SIZE_KB / HUGEPAGE_SIZE_KB + 1)) echo $NUM_HUGEPAGES # e.g., ~4096 ``` 确保 `HugePages_Total >= NUM_HUGEPAGES`,并且 `HugePages_Free + HugePages_Rsvd >= NUM_HUGEPAGES` #### 修改 HugePages(以 CentOS/RHEL 为例): 编辑 `/etc/sysctl.conf`: ```conf vm.nr_hugepages = 4096 ``` 然后重启或运行脚本重新加载(需释放旧页)。 > 📌 参考 Oracle 文档:[HugePages on Linux: What Every DBA (Should) Know](https://docs.oracle.com/en/database/oracle/oracle-database/) --- ### ✅ 方案四:检查 pfile 中 SGA 设置是否过大 打开你的 pfile: ```bash cat /data/oracle/product/11.2.0/db_1/dbs/initcatinfo.ora ``` 查找: ```sql sga_max_size=... sga_target=... pga_aggregate_target=... ``` 确认这些值没有超过物理内存或可用共享内存。 例如: ```sql sga_target=10G ``` 但服务器只有 8G 内存?那就必须调小。 --- ### ✅ 方案五:临时禁用 Automatic Memory Management(AMM) Oracle 11g 中,若使用 `memory_target` 或 `memory_max_target`,会使用 `/dev/shm` 映射整个内存区域,容易触发该问题。 #### 修改 pfile,替换为手动 SGA+PGA 管理: ```sql *.memory_target=0 *.memory_max_target=0 *.sga_target=4G *.sga_max_size=4G *.pga_aggregate_target=1G ``` 再尝试启动: ```sql SQL> startup pfile='/data/oracle/product/11.2.0/db_1/dbs/initcatinfo.ora'; ``` ✅ 这是最常见的解决方式! --- ## 🧪 验证步骤总结 1. 检查 `/dev/shm` 是否足够大(至少等于 SGA) 2. 检查 `memory_target` 是否启用 → 建议关闭,改用 SGA/PGA 手动管理 3. 调整 `kernel.shmmax` 和 `shmall` 4. 检查 HugePages 配置是否合理 5. 确保物理内存足够支持 SGA 设置 --- ## ✅ 示例:修复后的完整流程 ```bash # 1. 修改 sysctl echo " kernel.shmmax = 17179869184 kernel.shmall = 4194304 vm.nr_hugepages = 0 " >> /etc/sysctl.conf sysctl -p # 2. 调整 /dev/shm mount -o remount,size=12g /dev/shm # 3. 修改 pfile,关闭 AMM cat > /data/oracle/product/11.2.0/db_1/dbs/initcatinfo.ora <<EOF catinfo.__db_cache_size=3221225472 catinfo.__shared_pool_size=1073741824 *.sga_max_size=4G *.sga_target=4G *.pga_aggregate_target=1G *.db_name='catinfo' # 添加其他必要参数... EOF # 4. 启动数据库 sqlplus / as sysdba SQL> startup pfile='/data/oracle/product/11.2.0/db_1/dbs/initcatinfo.ora'; ``` --- ## ❗常见误区 | 误解 | 正确理解 | |------|---------| | “磁盘满了” | 实际是内存/共享内存不足 | | “加 swap 就行” | swap 不解决共享内存问题 | | “重启就能好” | 若参数未改,还会复现 | ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值