数据库

位置:IT落伍者 >> 数据库 >> 浏览文章

Oracle诊断案例2 -SGA与Swap


发布日期:2021年12月16日
 
Oracle诊断案例2 -SGA与Swap

案例描述:

这是一个大型生产系统

问题出现时系统累计大量用户进程

用户请求得不到及时响应新的进程不断尝试建立连接

连接数很快被用完

数据库版本:

操作系统:Solaris

检查alert文件

日志中记录如下错误信息说明磁盘异步IO出现问题:

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

Tue Aug ::

WARNING: aiowait timed out times

我们知道在SUN的某些版本上异步IO存在问题而异步IO缺省是打开的

代码:

SQL> show parameter disk_a

NAME TYPEVALUE

disk_asynch_io boolean TRUE

针对此问题我们停用了数据库的异步IO写入

共享内存问题

alert文件中还记录了以下错误信息:

Tue Aug ::

WARNING: EINVAL creating segment of size x

fix shm parameters in /etc/system or equivalent

该信息说明内核参数设置过小或者和SGA不匹配

我们检查system配置文件

$ cat /etc/system

set shmsys:shminfo_shmmax=

set shmsys:shminfo_shmmin=

set shmsys:shminfo_shmmni=

set shmsys:shminfo_shmseg=

set semsys:seminfo_semmap=

set semsys:seminfo_semmni=

set semsys:seminfo_semmns=

set semsys:seminfo_semmnu=

set semsys:seminfo_semume=

set semsys:seminfo_semmsl=

我们发现最大共享内存设置仅有G

检查SGA设置

SQL*Plus: Release Production on 星期二 ::

Copyright (c) Oracle Corporation All rights reserved

Connected to:

Oraclei Enterprise Edition Release bit Production

With the Partitioning OLAP and Oracle Data Mining options

JServer Release Production

SQL> show sga

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

我们发现SGA设置接近G这也就是步骤中错误提示出现的原因

交换区问题

我们用top工具检查系统运行状况

代码:

# /usr/local/bin/top

last pid: ;load averages: ::

processes: sleeping running on cpu

CPU states: % idle% user% kernel % iowait% swap

Memory: M real M free G swap in use G swap free

PID USERNAME THR PRI NICESIZE RES STATETIMECPU COMMAND

oracle M M sleep:% oracle

oracle M M sleep:% oracle

root K K sleep:% picld

oracle M M sleep:% oracle

root K K cpu/:% top

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

Memory: M real M free G swap in use G swap free

我们发现系统仅有G RAM物理内存仅有M可用现在SWAP区使用了G

我们初步作出以下判断:

SGA设置过大(将近G)导致运行时产生大量交换

大量SWAP交换进而引发磁盘问题这也就应该是我们第一步看到

WARNING: aiowait timed out times的原因

大量交换导致数据库性能急剧下降进而导致用户请求得不到快速响应堵塞累积直至数据库失去响应

解决方案

此问题主要是由于SGA设置不当引起我们马上缩小了SGA设置:

SQL> show sga

Total System Global Area bytes

Fixed Size bytes

Variable Size bytes

Database Buffers bytes

Redo Buffers bytes

此时数据库减少了交换达到了稳定运行用户请求可以得到快速响应

问题解决完成

系统状态

调整后系统运行状况:

代码:

$ top

last pid: ;load averages: ::

processes: sleeping on cpu

CPU states: % idle% user% kernel% iowait% swap

Memory: M real M free M swap in use G swap free

PID USERNAME THR PRI NICESIZE RES STATETIMECPU COMMAND

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

root K K sleep:% picld

oracle M M sleep:% oracle

oracle K K cpu/:% top

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M M sleep:% oracle

oracle M K sleep:% tnslsnr

oracle M M sleep:% oracle

oracle M M sleep:% oracle

该系统调整完以后一直稳定运行至今

一点总结:

这个案例和前面我提到的另外一个极其相似同样都是SGA设置不当引起的数据库问题

本身并不复杂

这一类问题应该在数据库规划和建设阶段就避免掉

其时该问题对我更像是个心理测试当所有老板都站在你背后的时候你能否冷静快速的找到并解决问题

关于SUN上的aiowait timed out 有很多总情况及诱因

上一篇:如何通过触发器实现数据库的即时同步

下一篇:Case-BasedReasoningTool