日期:2014-05-16 浏览次数:20468 次
Oracle10g在v$database视图中引入了current_scn,这个SCN来自底层表,代表当前的SCN,current_scn的查询会直接导致SCN的增进,而其他方式并不会。也就是说在这里的current_scn就像是一个Sequence一样,查询会导致增进。这也很好理解,v$database只能通过增进当前的SCN才能保证获得的SCN是Current的。可是如果不查询呢?这个值肯定是不会增长的。
而使用dbms_flashback.get_system_change_number方式查询并不会导致SCN的增进。
BYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1780068
BYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1780068
BYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1780069
BYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1780069
BYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1780069
BYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1780069
BYS@bys1>select current_scn from v$database;
CURRENT_SCN
-----------
1780089
BYS@bys1>select current_scn from v$database;
CURRENT_SCN
-----------
1780090
BYS@bys1>select current_scn from v$database;
CURRENT_SCN
-----------
1780091
scn计算方法:SCN=(SCN_WRP * 4294967296) + SCN_BAS
因为 kscnbas占4个byte,所以2的32(4*8)次方 = 4294967296,所以scn = (SCN_WRP * 4294967296) + SCN_BAS
而又因为kscnwrp占2个byte,所以scn最大值为ff.ffff=2的48(6*8)次方-1 = 281474976710655
BYS@bys1>conn / as sysdba ---需要使用SYS用户
Connected.
SYS@bys1>select * from (select time_mp,time_dp,scn_wrp,scn_bas from smon_scn_time order by time_mp desc) where rownum<2;
TIME_MP TIME_DP SCN_WRP SCN_BAS
---------- --------- ---------- ----------
1378949107 12-SEP-13 0 1781024
SYS@bys1>select (0*4294967296)+1781024 as scn from dual;
SCN
----------
1781024
SYS@bys1>select dbms_flashback.get_system_change_number current_scn from dual;
CURRENT_SCN
-----------
1781410 ----大致能对上哈哈。
作用:由smon收集scn和time映射关