eygle.com   eygle.com
eygle.com eygle
eygle.com  
 

« A Gift:Oracle DW/BI 2006 Calendar | Blog首页 | My answer for-9个动态性能视图 »

what is SMON_SCN_TIME ?

SMON_SCN_TIME是Oracle数据库的系统表,用以进行辅助恢复等功能。
在Oracle9iR2中,SMON_SCN_TIME每5分钟被更新一次。

[oracle@jumper oracle]$ sqlplus "/ as sysdba"
SQL*Plus: Release 9.2.0.4.0 - Production on Mon Dec 19 18:19:27 2005
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.
SQL> select * from smon_scn_time where rownum <10;
    THREAD    TIME_MP TIME_DP                SCN_WRP    SCN_BAS
---------- ---------- ------------------- ---------- ----------
         1 1134916635 2005-12-18 22:37:15         25      65931
         1 1134916648 2005-12-18 22:37:28         25      65979
         1 1134917029 2005-12-18 22:43:49         25      66224
         1 1134917336 2005-12-18 22:48:57         25      66325
         1 1134917643 2005-12-18 22:54:04         25      66426
         1 1134917950 2005-12-18 22:59:11         25      66527
         1 1134918257 2005-12-18 23:04:18         25      66628
         1 1134918564 2005-12-18 23:09:25         25      66733
         1 1134918871 2005-12-18 23:14:33         25      66836
9 rows selected.

SMON_SCN_TIME记录5天的数据,也就是1440 ((5d x 24h x 12m = 1440) 条记录。
所以在Oracle9iR2中,表属性修改时间和flashback时间差至少应为5分钟。否则就会出现ORA-01466错误。

[oracle@jumper oracle]$ sqlplus eygle/eygle
SQL*Plus: Release 9.2.0.4.0 - Production on Mon Dec 19 19:34:53 2005
Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

Connected to:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production
With the Partitioning option
JServer Release 9.2.0.4.0 - Production
19:34:58 SQL> col myscn for 9999999999999999
19:34:58 SQL> variable myscn number;
19:34:58 SQL> create table eygle (c1 number);
Table created.
19:35:00 SQL> exec :myscn := dbms_flashback.get_system_change_number();
PL/SQL procedure successfully completed.
19:35:00 SQL> print myscn;
            MYSCN
-----------------
     107374274756
19:35:00 SQL> insert into eygle values(1);
1 row created.
19:35:00 SQL> commit;
Commit complete.
19:35:00 SQL> exec :myscn := dbms_flashback.get_system_change_number();
PL/SQL procedure successfully completed.
19:35:00 SQL> print myscn;
            MYSCN
-----------------
     107374274777
19:35:00 SQL> select * from eygle as of scn(:myscn);
select * from eygle as of scn(:myscn)
              *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed
19:41:10 SQL> select * from eygle as of scn(:myscn);
select * from eygle as of scn(:myscn)
              *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed
19:43:03 SQL> select dbms_flashback.get_system_change_number myscn from dual;
            MYSCN
-----------------
     107374274944
19:43:15 SQL> select * from eygle as of scn 107374274944;
        C1
----------
         1

此时SMON_SCN_TIME中的信息如下: 

19:45:11 SQL> select * from (select * from smon_scn_time order by time_dp desc) where rownum <5;
    THREAD    TIME_MP TIME_DP                SCN_WRP    SCN_BAS
---------- ---------- ------------------- ---------- ----------
         1 1134992658 2005-12-19 19:44:18         25      92565
         1 1134992351 2005-12-19 19:39:11         25      92463
         1 1134992042 2005-12-19 19:34:04         25      92256
         1 1134991731 2005-12-19 19:28:53         25      92149

在Oracle10g中,SMON_SCN_TIME表每6秒被更新一次。所以这个Flashback时间被缩小为6秒。

[oracle@danaly ~]$ sqlplus eygle/eygle
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Dec 19 19:37:19 2005
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options
19:37:22 SQL> col myscn for 9999999999999999
19:37:22 SQL> variable myscn number;
19:37:22 SQL> create table eygle (c1 number);
Table created.
19:37:22 SQL> exec :myscn := dbms_flashback.get_system_change_number();
PL/SQL procedure successfully completed.
19:37:22 SQL> print myscn;
            MYSCN
-----------------
      16011230122
19:37:22 SQL> insert into eygle values(1);
1 row created.
19:37:22 SQL> commit;
Commit complete.
19:37:22 SQL> exec :myscn := dbms_flashback.get_system_change_number();
PL/SQL procedure successfully completed.
19:37:22 SQL> print myscn;
            MYSCN
-----------------
      16011230124
19:37:22 SQL> select * from eygle as of scn(:myscn);
select * from eygle as of scn(:myscn)
              *
ERROR at line 1:
ORA-01466: unable to read data - table definition has changed

19:37:22 SQL> select scn_to_timestamp(16011230124) from dual;
SCN_TO_TIMESTAMP(16011230124)
---------------------------------------------------------------------------
19-DEC-05 07.37.21.000000000 PM
 
19:38:50 SQL> select timestamp_to_scn('19-DEC-05 07.37.27.000000000 PM') MYSCN from dual;
            MYSCN
-----------------
      16011230125
19:39:02 SQL> select * from eygle as of scn 16011230125;
        C1
----------
         1


历史上的今天...
    >> 2011-12-27文章:
    >> 2008-12-27文章:
    >> 2007-12-27文章:
    >> 2006-12-27文章:

无觅

By eygle on 2005-12-27 20:19 | Comments (3) | Internal | 602 |

3 Comments

所以在Oracle9iR2中,表属性修改时间和flashback时间差至少应为5分钟。否则就会出现ORA-01466错误
---------------------------------------------
Hi, eygle,你说的表属性修改时间是指什么时间呢?LAST_DDL_TIME吗?下面是我在9205下的试验,修改了表的属性后立刻flashback query,但没有报错:
SQL> alter table TEST20 add name varchar2(20);

Table altered.

SQL> exec :myscn := dbms_flashback.get_system_change_number();

PL/SQL procedure successfully completed.

SQL> print myscn;

MYSCN
-----------------
8174383932257

SQL> select * from test20 as of scn(:myscn);

ID NAME
---------- --------------------
1

SQL> insert into test20 values(1,'abcd');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from test20 as of scn(:myscn);

ID NAME
---------- --------------------
1

不知道eygle大师是基于什么版本的测试,我在10.1.0.2下测试和楼上的那位兄弟一样。。咋好像没有时间限制,都可以恢复。

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options

SQL> show parameters comp
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
compatible string 10.2.0.3

SQL> alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss';
Session altered.

SQL> select * from (select TIME_DP from smon_scn_time order by time_dp desc) where rownum select * from (select TIME_DP from smon_scn_time order by time_dp desc) where rownum select * from (select TIME_DP from smon_scn_time order by time_dp desc) where rownum select * from (select TIME_DP from smon_scn_time order by time_dp desc) where rownum <5;

TIME_DP
-------------------
2009-01-07 22:52:44
2009-01-07 22:47:41
2009-01-07 22:42:56
2009-01-07 22:37:53

这个表并没有每6秒钟更新一下。不过SCN_TO_TIMESTAMP 确可以定位到3秒左右的时间。
http://www.adp-gmbh.ch/ora/sql/scn_to_timestamp.html


CopyRight © 2004~2020 云和恩墨,成就未来!, All rights reserved.
数据恢复·紧急救援·性能优化 云和恩墨 24x7 热线电话:400-600-8755 业务咨询:010-59007017-7040 or 7037 业务合作: marketing@enmotech.com