1.查询系统当前SCN两条命令
SQL> select current_scn from v$database;SQL> select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1781893
另一个查SCN的方法,稍有延迟是因为执行命令的间隔,其实也是实时的了
SCNSYS@ bys3>oradebug dumpvar sga kcsgacn_
ORA-00079: variable kcsgacn_ not foundSYS@ bys3>oradebug dumpvar sga kcsgscn_
kcslf kcsgscn_ [2000EFC0, 2000EFE0) = 00000000 001976D2 000001E9 00000000 00000000 00000000 00000000 2000EDCC
SYS@ bys3>select to_number('1976D2','xxxxxxxxxxxx') a from dual;
A
----------
1668818
SYS@ bys3>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1668853
再一个通过内部表查询SCN的:
SYS@ bys3>select max(ktuxescnw*power(2,32)+ktuxescnb) from x$ktuxe;MAX(KTUXESCNW*POWER(2,32)+KTUXESCNB)
------------------------------------
1669208
SYS@ bys3>select dbms_flashback.get_system_change_number from dual;
GET_SYSTEM_CHANGE_NUMBER
------------------------
1669219
2.数据库全局-检查点 SCN,在控制文件中。
SYS@bys1> select dbid,checkpoint_change# from v$database;DBID CHECKPOINT_CHANGE#
---------- ------------------
3957527513 1753478
3.当前数据文件检查点SCN。在控制文件中、数据文件头中。即checkpoint scn,表示该数据文件最近一次执行检查点操作时的SCN
SQL> select name,checkpoint_change# from v$datafile;NAME CHECKPOINT_CHANGE#
-------------------------------------------------- ------------------
/u01/oradata/bys1/system01.dbf 1753478
/u01/oradata/bys1/sysaux01.dbf 1753478
SQL> select file#,name,checkpoint_change#,to_char(checkpoint_time,'yyyy-mm-dd hh24:mi:ss') cptime from v$datafile;
FILE# NAME CHECKPOINT_CHANGE# CPTIME
---------- -------------------------------------------------- ------------------ -------------------
1 /u01/oradata/bys1/system01.dbf 1753478 2013-09-11 23:00:52
2 /u01/oradata/bys1/sysaux01.dbf 1753478 2013-09-11 23:00:52
4.查询数据文件头SCN,在控制文件中、数据文件头
SQL> select name,checkpoint_change# from v$datafile_header;NAME CHECKPOINT_CHANGE#
---------------------------------------- ------------------
/u01/app/oracle/oradata/bys001/system01.dbf 1198546
5.数据文件结束SCN,在数据文件头,控制文件中。
LAST_CHANGE#,如果数据库非正常关闭值为NULL。正常关闭是关闭时的SCN。实例恢复就是在打开数据库时检查此参数确定是否需要恢复。
数据库OPEN时LAST_CHANGE#也为NULL,因为不确定SCN多少时关闭。
SQL> select name,last_change# from v$datafile;
NAME LAST_CHANGE#
---------------------------------------- ------------
/u01/app/oracle/oradata/bys001/system01.dbf
6.日志中所含SCN范围
BYS@ bys3>select GROUP#,sequence#,STATUS,FIRST_CHANGE#,to_char(FIRST_TIME,'yyyy/mm/dd:hh24:mi:ss') firsttime,NEXT_CHANGE#,to_char(NEXT_TIME,'yyyy/mm/dd:hh24:mi:ss') nexttime from V$log;GROUP# SEQUENCE# STATUS FIRST_CHANGE# FIRSTTIME NEXT_CHANGE# NEXTTIME
---------- ---------- ---------------- ------------- ------------------- ------------ -------------------
1 145 CURRENT 2910938 2013/12/15:10:06:41 2.8147E+14 ------当前REDO日志,所以下一次切换的SCN是无穷大,切换时间为空。
2 143 INACTIVE 2865685 2013/12/14:20:36:08 2883589 2013/12/15:02:00:55
3 144 INACTIVE 2883589 2013/12/15:02:00:55 2910938 2013/12/15:10:06:41