非歸檔模式 無法用備份修復新建的表

huyi_tony發表於2014-07-31
非歸檔模式下,做一個冷備份。 

點選(此處)摺疊或開啟

  1. RMAN> shutdown immediate;

  2. database closed
  3. database dismounted
  4. Oracle instance shut down

  5. RMAN> startup mount;

  6. connected to target database (not started)
  7. Oracle instance started
  8. database mounted

  9. Total System Global Area 1068937216 bytes

  10. Fixed Size 2235208 bytes
  11. Variable Size 616563896 bytes
  12. Database Buffers 444596224 bytes
  13. Redo Buffers 5541888 bytes

  14. RMAN> backup database;

  15. Starting backup at 31-JUL-14
  16. allocated channel: ORA_DISK_1
  17. channel ORA_DISK_1: SID=133 device type=DISK
  18. channel ORA_DISK_1: starting full datafile backup set
  19. channel ORA_DISK_1: specifying datafile(s) in backup set
  20. input datafile file number=00004 name=/u02/oradata/proddb/users01.dbf
  21. input datafile file number=00006 name=/u02/oradata/proddb/myundo01.dbf
  22. input datafile file number=00001 name=/u02/oradata/proddb/system01.dbf
  23. input datafile file number=00002 name=/u02/oradata/proddb/sysaux01.dbf
  24. input datafile file number=00008 name=/u02/oradata/proddb/ts_small01.dbf
  25. input datafile file number=00003 name=/u02/oradata/proddb/newts01.dbf
  26. input datafile file number=00009 name=/u02/oradata/proddb/ts_small02.dbf
  27. channel ORA_DISK_1: starting piece 1 at 31-JUL-14
  28. channel ORA_DISK_1: finished piece 1 at 31-JUL-14
  29. piece handle=/u02/backup/prod/PRODDB/backupset/2014_07_31/o1_mf_nnndf_TAG20140731T054048_9xn3s13c_.bkp tag=TAG20140731T054048 comment=NONE
  30. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
  31. channel ORA_DISK_1: starting full datafile backup set
  32. channel ORA_DISK_1: specifying datafile(s) in backup set
  33. including current control file in backup set
  34. including current SPFILE in backup set
  35. channel ORA_DISK_1: starting piece 1 at 31-JUL-14
  36. channel ORA_DISK_1: finished piece 1 at 31-JUL-14
  37. piece handle=/u02/backup/prod/PRODDB/backupset/2014_07_31/o1_mf_ncsnf_TAG20140731T054048_9xn3skmq_.bkp tag=TAG20140731T054048 comment=NONE
  38. channel ORA_DISK_1: backup set complete, elapsed time: 00:00:01
  39. Finished backup at 31-JUL-14

  40. RMAN> open database;

  41. database opened
然後建立一個新表。

點選(此處)摺疊或開啟

  1. scott@PRODDB>create table test
  2.   2 tablespace newts
  3.   3 as select * from emp;

  4. Table created.

  5. scott@PRODDB>select empno, rowid, dbms_rowid.rowid_relative_fno(rowid) file#, dbms_rowid.rowid_block_number(rowid) block#, dbms_rowid.rowid_row_number(rowid) row#
  6.   2 from test;                                                              -- 該表的資料都在 檔案3 的第 131塊中

  7.      EMPNO ROWID FILE# BLOCK# ROW#
  8. ---------- ------------------ ---------- ---------- ----------
  9.       7369 AAADaKAADAAAACDAAA 3 131 0
  10.       7499 AAADaKAADAAAACDAAB 3 131 1
  11.       7521 AAADaKAADAAAACDAAC 3 131 2
  12.       7566 AAADaKAADAAAACDAAD 3 131 3
  13.       7654 AAADaKAADAAAACDAAE 3 131 4
  14.       7698 AAADaKAADAAAACDAAF 3 131 5
  15.       7782 AAADaKAADAAAACDAAG 3 131 6
  16.       7788 AAADaKAADAAAACDAAH 3 131 7
  17.       7839 AAADaKAADAAAACDAAI 3 131 8
  18.       7844 AAADaKAADAAAACDAAJ 3 131 9
  19.       7876 AAADaKAADAAAACDAAK 3 131 10
  20.       7900 AAADaKAADAAAACDAAL 3 131 11
  21.       7902 AAADaKAADAAAACDAAM 3 131 12
  22.       7934 AAADaKAADAAAACDAAN 3 131 13

  23. 14 rows selected.

刪除該表所在的資料檔案,然後用備份來修復


點選(此處)摺疊或開啟

  1. [oracle@Redhat55 ~]$ rm /u02/oradata/proddb/newts01.dbf

  2. RMAN> restore datafile 3;

  3. Starting restore at 31-JUL-14
  4. allocated channel: ORA_DISK_1
  5. channel ORA_DISK_1: SID=133 device type=DISK

  6. channel ORA_DISK_1: starting datafile backup set restore
  7. channel ORA_DISK_1: specifying datafile(s) to restore from backup set
  8. channel ORA_DISK_1: restoring datafile 00003 to /u02/oradata/proddb/newts01.dbf
  9. channel ORA_DISK_1: reading from backup piece /u02/backup/prod/PRODDB/backupset/2014_07_31/o1_mf_nnndf_TAG20140731T054048_9xn3s13c_.bkp
  10. channel ORA_DISK_1: piece handle=/u02/backup/prod/PRODDB/backupset/2014_07_31/o1_mf_nnndf_TAG20140731T054048_9xn3s13c_.bkp tag=TAG20140731T054048
  11. channel ORA_DISK_1: restored backup piece 1
  12. channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
  13. Finished restore at 31-JUL-14

  14. RMAN> recover datafile 3;

  15. Starting recover at 31-JUL-14
  16. using channel ORA_DISK_1

  17. starting media recovery
  18. media recovery complete, elapsed time: 00:00:00

  19. Finished recover at 31-JUL-14

修復完後,該表依舊無法訪問


點選(此處)摺疊或開啟

  1. scott@PRODDB>select * from test;                                      -- 提示 該表的 資料塊 ( 檔案3 第131塊) 損壞
  2. select * from test
  3.               *
  4. ERROR at line 1:
  5. ORA-01578: ORACLE data block corrupted (file # 3, block # 131)
  6. ORA-01110: data file 3: \'/u02/oradata/proddb/newts01.dbf\'
  7. ORA-26040: Data block was loaded using the NOLOGGING option

alert日誌裡的錯誤資訊


點選(此處)摺疊或開啟

  1. Thu Jul 31 05:55:02 2014
  2. Errors in file /u01/app/oracle/diag/rdbms/proddb/Prod/trace/Prod_ora_7161.trc (incident=44604):
  3. ORA-01578: ORACLE data block corrupted (file # 3, block # 131)
  4. ORA-01110: data file 3: \



處理方法,用 dbms_repair 來跳過該壞塊


點選(此處)摺疊或開啟

  1. sys@PRODDB>BEGIN                                            --  建立修復的表  放在USERS表空間下
  2.   2 DBMS_REPAIR.ADMIN_TABLES (
  3.   3 TABLE_NAME => \'REPAIR_TABLE\',
  4.   4 TABLE_TYPE => dbms_repair.repair_table,
  5.   5 ACTION => dbms_repair.create_action,
  6.   6 TABLESPACE => \'USERS\');
  7.   7 END;
  8.   8 /

  9. PL/SQL procedure successfully completed.

檢查有壞塊的物件


點選(此處)摺疊或開啟

  1. sys@PRODDB>DECLARE num_corrupt INT;
  2.   2 BEGIN
  3.   3 num_corrupt := 0;
  4.   4 DBMS_REPAIR.CHECK_OBJECT (
  5.   5 SCHEMA_NAME => \'SCOTT\',
  6.   6 OBJECT_NAME => \'TEST\',
  7.   7 REPAIR_TABLE_NAME => \'REPAIR_TABLE\',
  8.   8 corrupt_count => num_corrupt);
  9.   9 DBMS_OUTPUT.PUT_LINE(\'number corrupt: \' || TO_CHAR (num_corrupt));
  10.  10 END;
  11.  11 /
  12. sys@PRODDB>COL CORRUPT_DESCRIPTION FOR A20
  13. sys@PRODDB>select BLOCK_ID, CORRUPT_TYPE, CORRUPT_DESCRIPTION from REPAIR_TABLE;           -- 檢視壞塊的塊號

  14. BLOCK_ID CORRUPT_TYPE CORRUPT_DESCRIPTION
  15. ---------- ------------ --------------------
  16.        131         6148

跳過該壞塊

點選(此處)摺疊或開啟

  1. sys@PRODDB>DECLARE num_fix INT;
  2.   2 BEGIN
  3.   3 num_fix := 0;
  4.   4 DBMS_REPAIR.FIX_CORRUPT_BLOCKS (
  5.   5 SCHEMA_NAME => \'SCOTT\',
  6.   6 OBJECT_NAME=> \'TEST\',
  7.   7 OBJECT_TYPE => dbms_repair.table_object,
  8.   8 REPAIR_TABLE_NAME => \'REPAIR_TABLE\',
  9.   9 FIX_COUNT=> num_fix);
  10.  10 DBMS_OUTPUT.PUT_LINE(\'num fix: \' || to_char(num_fix));
  11.  11 END;
  12.  12 /

  13. PL/SQL procedure successfully completed.

  14. sys@PRODDB>BEGIN
  15.   2 DBMS_REPAIR.SKIP_CORRUPT_BLOCKS (
  16.   3 SCHEMA_NAME => \'SCOTT\',
  17.   4 OBJECT_NAME => \'TEST\',
  18.   5 OBJECT_TYPE => dbms_repair.table_object,
  19.   6 FLAGS => dbms_repair.SKIP_FLAG);
  20.   7 END;
  21.   8 /

  22. PL/SQL procedure successfully completed.

現在,test表可以使用了,不過 131塊上的資料沒有了。


點選(此處)摺疊或開啟

  1. sys@PRODDB>select * from scott.test;

  2. no rows selected

  3. sys@PRODDB>set linesize 100
  4. sys@PRODDB>desc scott.test
  5.  Name Null? Type
  6.  ----------------------------------------------------- -------- ------------------------------------
  7.  EMPNO NUMBER(4)
  8.  ENAME VARCHAR2(10)
  9.  JOB VARCHAR2(9)
  10.  MGR NUMBER(4)
  11.  HIREDATE DATE
  12.  SAL NUMBER(7,2)
  13.  COMM NUMBER(7,2)
  14.  DEPTNO NUMBER(2)












來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12238525/viewspace-1243391/,如需轉載,請註明出處,否則將追究法律責任。

相關文章