一、scn的作用
Scn的作用主要是保证数据库的一致性。它是Oracle的内部时钟机制。Scn是实施对oracle恢复非常重要的机制。
Scn在数据库中无处不在,一般在控制文件,数据文件头,日志文件,数据文件等都记录scn值。
system scn从视图v$database中获得,对应checkpoint_change#字段;
datafile scn、last scn(stop scn)分别对应视图v$datafile中的checkpoint_change#,last_change#,
start scn则从v$datafile_header中checkpoint_change#得到。
二、查看当前scn
control中有三种SCN分别为:system SCN、datafile SCN、last SCN(stop scn),
System scn
SQL> select checkpoint_change# from v$database;
CHECKPOINT_CHANGE#
------------------
451490
Datafile scn
SQL> select name,checkpoint_change# from v$datafile;
NAME
--------------------------------------------------------------------------------
CHECKPOINT_CHANGE#
------------------
/opt/app/oracle/oradata/wolf/system01.dbf
451490
/opt/app/oracle/oradata/wolf/undotbs01.dbf
451490
/opt/app/oracle/oradata/wolf/sysaux01.dbf
451490
NAME
--------------------------------------------------------------------------------
CHECKPOINT_CHANGE#
------------------
/opt/app/oracle/oradata/wolf/users01.dbf
451490
Last scn(stop scn,正常启动的时候stop scn无穷大, last_change#一定是NULL)
SQL> select name,last_change# from v$datafile;
NAME
--------------------------------------------------------------------------------
LAST_CHANGE#
------------
/opt/app/oracle/oradata/wolf/system01.dbf
/opt/app/oracle/oradata/wolf/undotbs01.dbf
/opt/app/oracle/oradata/wolf/sysaux01.dbf
NAME
--------------------------------------------------------------------------------
LAST_CHANGE#
------------
/opt/app/oracle/oradata/wolf/users01.dbf
数据文件头中有一种SCN :start SCN
SQL> select name,checkpoint_change# from v$datafile_header;
NAME
--------------------------------------------------------------------------------
CHECKPOINT_CHANGE#
------------------
/opt/app/oracle/oradata/wolf/system01.dbf
451490
/opt/app/oracle/oradata/wolf/undotbs01.dbf
451490
/opt/app/oracle/oradata/wolf/sysaux01.dbf
451490
NAME
--------------------------------------------------------------------------------
CHECKPOINT_CHANGE#
------------------
/opt/app/oracle/oradata/wolf/users01.dbf
451490