温故而知新 SMON功能(一)

SMON(system monitor process)系统监控后台进程,有时候也被叫做system cleanup process,这么叫的原因是它负责完成很多清理(cleanup)任务。但凡学习过Oracle基础知识的技术人员都会或多或少对该background process的功能有所了解。

曾几何时对SMON功能的了解程度可以作为评判一位DBA理论知识的重要因素,至今仍有很多公司在DBA面试中会问到SMON有哪些功能这样的问题。首先这是一道开放式的题目,并不会奢求面试者能够答全(答全几乎是不可能的,即便是在你阅读本篇文章之后),答出多少可以作为知识广度的评判依据(如果面试人特意为这题准备过,那么也很好,说明他已经能系统地考虑问题了),接着还可以就具体的某一个功能说开去,来了解面试者的知识深度,当然这扯远了。

我们所熟知的SMON是个兢兢业业的家伙,它负责完成一些列系统级别的任务。与PMON(Process Monitor)后台进程不同的是,SMON负责完成更多和整体系统相关的工作,这导致它会去做一些不知名的”累活”,当系统频繁产生这些”垃圾任务”,则SMON可能忙不过来。因此在10g中SMON变得有一点懒惰了,如果它在短期内接收到过多的工作通知(SMON: system monitor process posted),那么它可能选择消极怠工以便让自己不要过于繁忙(SMON: Posted too frequently, trans recovery disabled),之后会详细介绍。

SMON的主要作用包括:

1.清理临时段(SMON cleanup temporary segments)

触发场景

很多人错误地理解了这里所说的临时段temporary segments,认为temporary segments是指temporary tablespace临时表空间上的排序临时段(sort segment)。事实上这里的临时段主要指的是永久表空间(permanent tablespace)上的临时段,当然临时表空间上的temporary segments也是由SMON来清理(cleanup)的,但这种清理仅发生在数据库实例启动时(instance startup)。

永久表空间上同样存在临时段,譬如当我们在某个永久表空间上使用create table/index等DDL命令创建某个表/索引时,服务进程一开始会在指定的永久表空间上分配足够多的区间(Extents),这些区间在命令结束之前都是临时的(Temporary Extents),直到表/索引完全建成才将该temporary segment转换为permanent segment。另外当使用drop命令删除某个段时,也会先将该段率先转换为temporary segment,之后再来清理该temporary segment(DROP object converts the segment to temporary and then cleans up the temporary segment)。 常规情况下清理工作遵循谁创建temporary segment,谁负责清理的原则。换句话说,因服务进程rebuild index所产生的temporary segment在rebuild完成后应由服务进程自行负责清理。一旦服务进程在成功清理temporary segment之前就意外终止了,亦或者服务进程在工作过程中遇到了某些ORA-错误导致语句失败,那么SMON都会被要求(posted)负责完成temporary segment的清理工作。

对于永久表空间上的temporary segment,SMON会三分钟清理一次(前提是接到post),如果SMON过于繁忙那么可能temporary segment长期不被清理。temporary segment长期不被清理可能造成一个典型的问题是:在rebuild index online失败后,后续执行的rebuild index命令要求之前产生的temporary segment已被cleanup,如果cleanup没有完成那么就需要一直等下去。在10gR2中我们可以使用dbms_repair.online_index_clean来手动清理online index rebuild的遗留问题:

The dbms_repair.online_index_clean function has been created to cleanup online index rebuilds.
Use the dbms_repair.online_index_clean function to resolve the issue.
Please note if you are unable to run the dbms_repair.online_index_clean function it is due to the fact
that you have not installed the patch for Bug or are not running on a release that includes this fix.
The fix for this bug is a new function in the dbms_repair package called dbms_repair.online_index_clean,
which has been created to cleanup online index [[sub]partition] [re]builds. New functionality is not allowed in patchsets;
therefore, this is not available in a patchset but is available in 10gR2. Check your patch list to verify the database is patched for Bug
using the following command and patch for the bug if it is not listed: opatch lsinventory -detail Cleanup after a failed online index [re]build can be slow to occurpreventing subsequent such operations
until the cleanup has occured.

接着我们通过实践来看一下smon是如何清理永久表空间上的temporary segment的:

设置10500事件以跟踪smon进程,这个诊断事件后面会介绍

SQL> alter system set events '10500 trace name context forever,level 10';
System altered. 在第一个会话中执行create table命令,这将产生一定量的Temorary Extents SQL> create table smon as select * from ymon; 在另一个会话中执行对DBA_EXTENTS视图的查询,可以发现产生了多少临时区间 SQL> SELECT COUNT(*) FROM DBA_EXTENTS WHERE SEGMENT_TYPE='TEMPORARY'; COUNT(*)
---------- 终止以上create table的session,等待一段时间后观察smon后台进程的trc可以发现以下信息: *** -- ::39.817
SMON: system monitor process posted msgflag:0x0200 (-/-/-/-/TMPSDROP/-/-) *** -- ::39.818
SMON: Posted, but not for trans recovery, so skip it. *** -- ::39.818
SMON: clean up temp segments in slave SQL> SELECT COUNT(*) FROM DBA_EXTENTS WHERE SEGMENT_TYPE='TEMPORARY'; COUNT(*)
---------- 可以看到smon通过slave进程完成了对temporary segment的清理

与永久表空间上的临时段不同,出于性能的考虑临时表空间上的Extents并不在操作(operations)完成后立即被释放和归还。相反,这些Temporary Extents会被标记为可用,以便用于下一次的排序操作。SMON仍会清理这些Temporary segments,但这种清理仅发生在实例启动时(instance startup):

For performance issues, extents in TEMPORARY tablespaces are not released ordeallocated
once the operation is complete.Instead, the extent is simply marked as available for the next sort operation.
SMON cleans up the segments at startup. A sort segment is created by the first statement that used a TEMPORARY tablespacefor sorting, after startup.
A sort segment created in a TEMPOARY tablespace is only released at shutdown.
The large number of EXTENTS is caused when the STORAGE clause has been incorrectly calculated

现象

可以通过以下查询了解数据库中Temporary Extent的总数,在一定时间内比较其总数,若有所减少那么说明SMON正在清理Temporary segment

SELECT COUNT(*) FROM DBA_EXTENTS WHERE SEGMENT_TYPE='TEMPORARY';

也可以通过v$sysstat视图中的”SMON posted for dropping temp segment”事件统计信息来了解SMON收到清理要求的情况:

SQL> select name,value from v$sysstat where name like '%SMON%';

NAME                                                                  VALUE
---------------------------------------------------------------- ----------
total number of times SMON posted
SMON posted for undo segment recovery
SMON posted for txn recovery for other instances
SMON posted for instance recovery
SMON posted for undo segment shrink
SMON posted for dropping temp segment

另外在清理过程中SMON会长期持有Space Transacton(ST)队列锁,其他会话可能因为得不到ST锁而等待超时出现ORA-01575错误:

警告日志:
, , "timeout waiting for space management resource"
// *Cause: failed to acquire necessary resource to do space management.
// *Action: Retry the operation.

如何禁止SMON清理临时段

可以通过设置诊断事件event=’10061 trace name context forever, level 10′禁用SMON清理临时段(disable SMON from cleaning temp segments)。

alter system set events '10061 trace name context forever, level 10';

相关诊断事件

除去10061事件外还可以用10500事件来跟踪smon的post信息,具体的事件设置方法见EVENT: 10500 "turn on traces for SMON"

Error:  ORA
Text: turn on traces for SMON
-------------------------------------------------------------------------------
Cause:
Action:
Level: <= trace instance recovery
> trace posting of SMON To set event : For the instance:
a. Shutdown database
b. Edit the initialisation parameter file and add:
event="10500 trace name context forever, level <value>"
c. restart the database For the SMON session:
Post the SMON process using oradbx (Oracle ) or oradebug (Oracle ).
For oradebug from server manager issue: oradebug setospid <OS PID>
oradebug event trace name context forever, level <value> For further information about oradebug Note 29786.1
oradbx Note 28863.1 <value> is 'Level' as per above

转自大刘的blog

http://www.oracledatabase12g.com/archives/smon-cleanup-temporary-segment.html

SMON功能(一):清理临时段的更多相关文章

  1. SMON功能-SMON_SCN_TIME字典基表

    SMON后台进程的作用还包括维护SMON_SCN_TIME基表. SMON_SCN_TIME基表用于记录过去时间段中SCN(system change number)与具体的时间戳(timestamp ...

  2. SMON功能(二):合并空闲区间

    SMON的作用还包括合并空闲区间(coalesces free extent) 触发场景 早期Oracle采用DMT字典管理表空间,不同于今时今日的LMT本地管理方式,DMT下通过对FET$和UET$ ...

  3. Oracle alter index rebuild 与 ORA-08104 说明

    在ITPUB 论坛上看到的一个帖子,很不错.根据论坛的帖子重做整理了一下. 原文链接如下: alter index rebuild online引发的血案 http://www.itpub.net/t ...

  4. Oracle 后台进程(五)SMON进程

    转载自:刘相兵 Maclean Liu 文章 你所不知道的后台进程 SMON 功能   SMON(system monitor process)系统监控后台进程,有时候也被叫做 system clea ...

  5. 请列出你在从事IT生涯中,最难以忘怀的一次误操作

    IT系统最怕什么,我觉得就两点: 1.不可靠的软硬件. 2.误操作. 第一点就不用解释了,第二点是该文的内容,主要摘选自ITPUB的精华贴——[精华] 请列出你在从事DBA生涯中,最难以忘怀的一次误操 ...

  6. Oracle_高级功能(7) 数据字典视图和动态性能视图

    oracle数据字典 1.概念数据字典是oracle数据库用来存储数据库结构信息的地方.数据字典是用来描述数据库数据的组织方式的,由表和视图组成.数据字典基表是在任何 Oracle 数据库中创建的第一 ...

  7. SMON: Parallel transaction recovery tried 引发的问题--转载

    SMON: Parallel transaction recovery tried 这个一般是在具有在跑大数据量的 transaction的时候kill掉了进程而导致 smon 去清理 回滚段时导致的 ...

  8. SMON进程、PMON进程、LGWR/ARCH

    SMON 进程:system monitor instance monitor 系统监控.实例监控进程 说明及作用:在实例关闭时,会清理临时段,整理空闲空间free space; 实例非正常关闭后,启 ...

  9. 【工具】清理Windows Installer冗余文件(支持64位NT6.x系统)

    样子: 支持系统: Windows NT 5.x/6.x 32及64位所有系统.需.net framework 2.0运行环境 功能: 清理上述系统中冗余的Windows Installer补丁文件. ...

随机推荐

  1. [Linux]服务管理:rpm包, 源码包

    --------------------------------------------------------------------------------------------------- ...

  2. 《深入理解Spark:核心思想与源码分析》一书正式出版上市

    自己牺牲了7个月的周末和下班空闲时间,通过研究Spark源码和原理,总结整理的<深入理解Spark:核心思想与源码分析>一书现在已经正式出版上市,目前亚马逊.京东.当当.天猫等网站均有销售 ...

  3. 如何在命令行里运行python脚本

    python是一款应用非常广泛的脚本程序语言,谷歌公司的网页就是用python编写.python在生物信息.统计.网页制作.计算等多个领域都体现出了强大的功能.python和其他脚本语言如java.R ...

  4. php Memcache/Memcached操作手册

    php Memcache/Memcached使用教程 Memcache和Memcached 其实是一个东西,只是php中要是用的扩展不一样, 2009年左右有人丰富memcache的用法和性能,编写了 ...

  5. SXT_项目

    30. svn服务器运行方式: svnserve:自己做实验的时候用. svn&apache结合起来用.[常用的] 29. EXTJs not Jquery[根据项目组需求] 28. tags ...

  6. 第三天:JS事件详解-事件流

    学习来源: F:\新建文件夹 (2)\HTML5开发\HTML5开发\04.JavaScript基础\6.JavaScript事件详解 学习内容:  1)基础概念 2)举例说明: 代码如上,如果用事件 ...

  7. 关于SQL Server 2008添加用户映射问题 解决办法

    同事一直需要用触发器 但是之前的数据库没有dbo映射 无法添加 查阅了很多资料 不适合自己的问题 所以自己动手丰衣足食 特留下笔记 希望能给遇到相同问题的朋友一个解决的思路

  8. C#结合LumiSoft.Net.dll读取Outlook邮件(.eml格式邮件)

    如果直接从Outlook(或者微软的其它邮件客户端如:Outlook Express.Windows Live Mail)的邮件文件(.eml格式)中提取各种电子邮件内容,使用LumiSoft.Net ...

  9. Windows 8.1 应用开发后台任务概述(Windows XAML)

    说到后台任务,这是在和许多 Android 开发者聊天的时候,经常被提起的话题之一, Windows 移动平台的后台任务的形式有别与 Android 的后台 service,简单的说在 Windows ...

  10. 自己动手做Web框架—MVC+Front Controller

    在我前面一篇博文<逃脱Asp.Net MVC框架的枷锁,使用Razor视图引擎>发表之后,很多人关心,脱离了之后怎么办?那么这可以说是它的续篇了. 同时,这也是eLiteWeb开源软件的一 ...