在很多情況下,數(shù)據(jù)庫只是某個數(shù)據(jù)文件的些許數(shù)據(jù)塊發(fā)生損壞。這種情況,我們當(dāng)然可是使用數(shù)據(jù)庫恢復(fù)或者數(shù)據(jù)文件恢復(fù)的方式來解決問題。但是有點(diǎn)高射炮打蚊子的感覺。幸好RMAN提供了塊級別的恢復(fù)。下面我們來演示一下。
創(chuàng)新互聯(lián)基于成都重慶香港及美國等地區(qū)分布式IDC機(jī)房數(shù)據(jù)中心構(gòu)建的電信大帶寬,聯(lián)通大帶寬,移動大帶寬,多線BGP大帶寬租用,是為眾多客戶提供專業(yè)服務(wù)器托管報(bào)價(jià),主機(jī)托管價(jià)格性價(jià)比高,為金融證券行業(yè)西云機(jī)房,ai人工智能服務(wù)器托管提供bgp線路100M獨(dú)享,G口帶寬及機(jī)柜租用的專業(yè)成都idc公司。
1. 創(chuàng)建一個表空間,大小小一點(diǎn)。
SQL> conn / as sysdba Connected. SQL> create tablespace tbs_blkerr datafile '/u01/app/oracle/oradata/devdb/blkerr01.dbf' size 128K; Tablespace created.
2. 在這個表空間上創(chuàng)建一個表,并且裝滿數(shù)據(jù)。
SQL> create table emp_blk tablespace tbs_blkerr as select * from scott.emp; Table created. SQL> insert into emp_blk select * from scott.emp; 14 rows created. SQL> / 14 rows created. 。。。。 SQL> insert into emp_blk select * from scott.emp; insert into emp_blk select * from scott.emp * ERROR at line 1: ORA-01653: unable to extend table SYS.EMP_BLK by 8 in tablespace TBS_BLKERR SQL> commit; Commit complete. SQL> select count(*) from emp_blk; COUNT(*) ---------- 686 SQL>
3. 備份該表空間或者數(shù)據(jù)文件。
RMAN> backup datafile '/u01/app/oracle/oradata/devdb/blkerr01.dbf'; Starting backup at 2015/07/09 10:30:11 using channel ORA_DISK_1 channel ORA_DISK_1: starting full datafile backup set channel ORA_DISK_1: specifying datafile(s) in backup set input datafile file number=00007 name=/u01/app/oracle/oradata/devdb/blkerr01.dbf channel ORA_DISK_1: starting piece 1 at 2015/07/09 10:30:11 channel ORA_DISK_1: finished piece 1 at 2015/07/09 10:30:12 piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T103011_bsvq5mw9_.bkp tag=TAG20150709T103011 comment=NONE channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01 Finished backup at 2015/07/09 10:30:12
4. 使用vi編輯數(shù)據(jù)文件blkerr01.dbf,對文件尾部做稍微的修改
SQL> shutdown immediate Database closed. Database dismounted. ORACLE instance shut down. SQL> startup ORACLE instance started. Total System Global Area 839282688 bytes Fixed Size 2233000 bytes Variable Size 553651544 bytes Database Buffers 281018368 bytes Redo Buffers 2379776 bytes Database mounted. ORA-01157: cannot identify/lock data file 7 - see DBWR trace file ORA-01110: data file 7: '/u01/app/oracle/oradata/devdb/blkerr01.dbf' RMAN> restore datafile 7; Starting restore at 2015/07/09 10:36:25 using target database control file instead of recovery catalog allocated channel: ORA_DISK_1 channel ORA_DISK_1: SID=20 device type=DISK channel ORA_DISK_1: starting datafile backup set restore channel ORA_DISK_1: specifying datafile(s) to restore from backup set channel ORA_DISK_1: restoring datafile 00007 to /u01/app/oracle/oradata/devdb/blkerr01.dbf channel ORA_DISK_1: reading from backup piece /u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T103011_bsvq5mw9_.bkp channel ORA_DISK_1: piece handle=/u01/app/oracle/fast_recovery_area/DEVDB/backupset/2015_07_09/o1_mf_nnndf_TAG20150709T103011_bsvq5mw9_.bkp tag=TAG20150709T103011 channel ORA_DISK_1: restored backup piece 1 channel ORA_DISK_1: restore complete, elapsed time: 00:00:01 Finished restore at 2015/07/09 10:36:27 RMAN> recover datafile 7; Starting recover at 2015/07/09 10:36:40 using channel ORA_DISK_1 starting media recovery media recovery complete, elapsed time: 00:00:00 Finished recover at 2015/07/09 10:36:41
此次修改破壞了文件的頭部,發(fā)生了意外。(也可能是編輯datafile時(shí),沒有關(guān)閉數(shù)據(jù)庫)我們先恢復(fù)數(shù)據(jù)文件。再次編輯文件。
此實(shí)驗(yàn)始終沒有做成功,后續(xù)有時(shí)間再研究。
恢復(fù)的方法如下:
RMAN TARGET / BLOCKRECOVER DATAFILE 12 BLOCK 12;