前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【DB笔试面试779】在Oracle中,SYS.SMON_SCN_TIME基表的作用是什么?

【DB笔试面试779】在Oracle中,SYS.SMON_SCN_TIME基表的作用是什么?

作者头像
AiDBA宝典
发布2020-05-07 15:25:55
5970
发布2020-05-07 15:25:55
举报
文章被收录于专栏:小麦苗的DB宝专栏

题目部分

在Oracle中,SYS.SMON_SCN_TIME基表的作用是什么?

答案部分

SYS.SMON_SCN_TIME基表用于记录过去时间段中SCN与具体的时间戳(timestamp)之间的映射关系,因为是采样记录这种映射关系,所以SMON_SCN_TIME可以较为粗糙地定位某个SCN的时间信息。实际的SMON_SCN_TIME是一张cluster table簇表。SMON_SCN_TIME基表的数据是由SMON后台进程来维护的。

在Oracle 11g中,该表的创建SQL在$ORACLE_HOME/rdbms/admin/dtxnspc.bsq文件中,可以直接查看:

代码语言:javascript
复制
create cluster smon_scn_to_time_aux (
  thread number                         /* thread, compatibility */
) tablespace SYSAUX
/
create index smon_scn_to_time_aux_idx on cluster smon_scn_to_time_aux
/
create table smon_scn_time (
  thread number,                         /* thread, compatibility */
  time_mp number,                        /* time this recent scn represents */
  time_dp date,                          /* time as date, compatibility */
  scn_wrp number,                        /* scn.wrp, compatibility */
  scn_bas number,                        /* scn.bas, compatibility */
  num_mappings number,
  tim_scn_map raw(1200),
  scn number default 0,                  /* scn */
  orig_thread number default 0           /* for downgrade */
) cluster smon_scn_to_time_aux (thread)
/
create unique index smon_scn_time_tim_idx on smon_scn_time(time_mp) 
  tablespace SYSAUX
/
create unique index smon_scn_time_scn_idx on smon_scn_time(scn)
  tablespace SYSAUX
/

从Oracle 10g开始,SMON会定时清理SMON_SCN_TIME中的记录。SMON后台进程会每5分钟被唤醒一次,检查SMON_SCN_TIME在磁盘上的映射记录总数,若总数超过144000条,则会使用以下语句删除最老的一条记录(TIME_MP列最小):

代码语言:javascript
复制
delete from smon_scn_time
 where thread = 0
   and time_mp = (select min(time_mp) from smon_scn_time where thread = 0);

若仅仅删除一条记录不足以获得足够的空间,则SMON会反复多次执行以上DELETE语句。可以设置12500事件停止SMON进程对SMON_SCN_TIME。

代码语言:javascript
复制
alter system set events '12500 trace name context forever, level 10';

& 说明:

有关SCN的更多内容可以参考我的BLOG:http://blog.itpub.net/26736162/viewspace-2126407/、http://blog.itpub.net/26736162/viewspace-2148359/

本文选自《Oracle程序员面试笔试宝典》,作者:小麦苗

About Me:小麦苗

● 本文作者:小麦苗,只专注于数据库的技术,更注重技术的运用

● 作者博客地址:http://blog.itpub.net/26736162/abstract/1/

● 本系列题目来源于作者的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

● QQ:646634621 QQ群:618766405

● 提供OCP、OCM和高可用部分最实用的技能培训

● 题目解答若有不当之处,还望各位朋友批评指正,共同进步

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-04-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DB宝 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档