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

♣          题目         部分

在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文件中,可以直接查看:

 1create cluster smon_scn_to_time_aux (
 2  thread number                         /* thread, compatibility */
 3) tablespace SYSAUX
 4/
 5create index smon_scn_to_time_aux_idx on cluster smon_scn_to_time_aux
 6/
 7create table smon_scn_time (
 8  thread number,                         /* thread, compatibility */
 9  time_mp number,                        /* time this recent scn represents */
10  time_dp date,                          /* time as date, compatibility */
11  scn_wrp number,                        /* scn.wrp, compatibility */
12  scn_bas number,                        /* scn.bas, compatibility */
13  num_mappings number,
14  tim_scn_map raw(1200),
15  scn number default 0,                  /* scn */
16  orig_thread number default 0           /* for downgrade */
17) cluster smon_scn_to_time_aux (thread)
18/
19create unique index smon_scn_time_tim_idx on smon_scn_time(time_mp) 
20  tablespace SYSAUX
21/
22create unique index smon_scn_time_scn_idx on smon_scn_time(scn)
23  tablespace SYSAUX
24/
     

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

1delete from smon_scn_time
2 where thread = 0
3   and time_mp = (select min(time_mp) from smon_scn_time where thread = 0);
     

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

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