NAME CHECKPOINT_CHANGE#
--------------------------------------------- ------------------
/u01/app/oracle/oradata/ora10g/system01.dbf 1306748
/u01/app/oracle/oradata/ora10g/undotbs01.dbf 1306748
/u01/app/oracle/oradata/ora10g/sysaux01.dbf 1306748
/u01/app/oracle/oradata/ora10g/users01.dbf 1306748
/u01/app/oracle/oradata/ora10g/example01.dbf 1306748
/u01/app/oracle/oradata/ora10g/zlm01.dbf 1319387
6 rows selected.
SCN也比其他文件的要大,因为相当于对6号文件单独进行存档了,只不过SCN还没有写进数据文件头,这个时候这个数据文件是废的,要保持一致性,必须要依靠归档来实现
--OS级别热备份6号数据文件
SQL> !cp $ORACLE_BASE/oradata/zlm01.dbf /u01/zlm01_bak.dbf
cp: cannot stat `/u01/app/oracle/oradata/zlm01.dbf': No such file or directory
SQL> !cp $ORACLE_BASE/oradata/ora10g/zlm01.dbf /u01/zlm01_bak.dbf
--关闭热备模式
SQL> alter tablespace zlm end backup;
Tablespace altered.
SQL> select * from v$backup;
FILE# STATUS CHANGE# TIME
---------- ------------------ ---------- ----------
1 NOT ACTIVE 0
2 NOT ACTIVE 0
3 NOT ACTIVE 0
4 NOT ACTIVE 0
5 NOT ACTIVE 0
6 NOT ACTIVE 1319387 2014-11-26
6 rows selected.
现在6号文件的状态又变回了NOT ACTIVE,说明热备结束了
SQL> select name,checkpoint_change# from v$datafile;
NAME CHECKPOINT_CHANGE#
--------------------------------------------- ------------------
/u01/app/oracle/oradata/ora10g/system01.dbf 1306748
/u01/app/oracle/oradata/ora10g/undotbs01.dbf 1306748
/u01/app/oracle/oradata/ora10g/sysaux01.dbf 1306748
/u01/app/oracle/oradata/ora10g/users01.dbf 1306748
/u01/app/oracle/oradata/ora10g/example01.dbf 1306748
/u01/app/oracle/oradata/ora10g/zlm01.dbf 1319387
6 rows selected.
数据文件的SCN依然是之前的,还没有变化
SQL> select header_block from dba_segments where segment_name='CORRUPT_TEST';
HEADER_BLOCK
------------
11
通过dba_segments视图,得知6号文件的段头块是11
--模拟出现坏块
SQL> !
[oracle@ora10g backupsets]$ dd of=/u01/app/oracle/oradata/ora10g/zlm01.dbf bs=8192 conv=notrunc seek=12 <<EOF
> corruption
> EOF
0+1 records in
0+1 records out
11 bytes (11 B) copied, 0.000168204 seconds, 65.4 kB/s
seek=12表示跳过12个block开始写入,因为我不想破坏段头块,只是在文件尾部写了废数据“corruption”,那么这个块就会标识为逻辑坏块
[oracle@ora10g backupsets]$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on 16 15:52:41 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn zlm/zlm
Connected.
SQL> select * from corrupt_test;
ID NAME
---------- ---------------
1 aaron8219
此时由于测试表corrupt_test里数据块中的行数据还在内存中,所以还是可以查询到行记录的
SQL> alter system flush buffer_cache;
System altered.