我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Oracle手工不完全恢复(一):使用当前控制文件

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Oracle手工不完全恢复(一):使用当前控制文件

实验环境

操作系统:CentOS 7.1

数据库:Oracle 11.2.0.4


目录

示例一:基于SCN或时间点的恢复----恢复过去某个时间误删除的表

示例二:当前日志组损坏,造成数据库崩溃

示例三:归档日志丢失或损坏



示例一:基于SCN或时间点的恢复----恢复过去某个时间误删除的表


环境:

(1)提前对数据库做一次全库冷备份;

(2)在seiang用户下有一张test1表隶属于seiang表空间;


定位错误操作发生的时间或SCN:logminer

恢复原理: 

1.冷备份的数据文件*.dbf比现在要旧,那么数据文件的scn肯定就比现在的小;  

2.使用日志挖掘方法,在日志中找出删表时的scn或时间戳;  

3.在数据库shutdown的状态下,用冷备份的数据文件*.dbf,覆盖现在的*.dbf文件;保证数据文件完整性;

4.启动数据库到mount下,恢复到日志挖掘的SCN或时间点(利用日志对数据文件重做一次)  

5.以resetlogs方式打开数据库,以前的日志就被覆盖了;


示例二:当前日志组损坏,造成数据库崩溃


环境:

(1)提前对数据库做一次全库冷备份;

(2)在seiang用户下有一张test1表隶属于seiang表空间;


示例三:归档日志丢失或损坏


环境:

(1)提前有一套完成的数据文件的冷备份;

(2)在seiang用户下有一张test1表隶属于seiang表空间;

  1. SYS@seiang11g>select owner,table_name,tablespace_name from dba_tables where owner='SEIANG';

  2. OWNER TABLE_NAME TABLESPACE_NAME
  3. ------------------------------ ------------------------------ ------------------------------
  4. SEIANG TEST1 SEIANG
  5. SEIANG TEST2 WJQ
  6. SEIANG TEST3 WJQBEST

  7. SYS@seiang11g>select * from seiang.test1;

  8.         ID NAME AGE
  9. ---------- ------------------------------ ----------
  10.          1 wjq 23
  11.          2 seiang 24
  12.          3 wjqdood 25
  13.          4 wjqbest 30

  14. --查看当前日志序号为2
  15. SYS@seiang11g>select group#,sequence#,status from v$log;

  16.     GROUP# SEQUENCE# STATUS
  17. ---------- ---------- ----------------
  18.          1 1 INACTIVE
  19.          2 2 CURRENT
  20.          3 0 UNUSED


  21. --修改数据并提交(sequence号2)
  22. SYS@seiang11g>update seiang.test1 set age=100 where id=1;
  23. 1 row updated.

  24. SYS@seiang11g>commit;
  25. Commit complete.

  26. SYS@seiang11g>alter system switch logfile;
  27. System altered.

  28. --修改数据并提交(sequence号3)
  29. SYS@seiang11g>update seiang.test1 set age=200 where id=1;
  30. 1 row updated.

  31. SYS@seiang11g>commit;
  32. Commit complete.

  33. SYS@seiang11g>alter system switch logfile;
  34. System altered.

  35. --修改数据并提交(sequence号4)
  36. SYS@seiang11g>update seiang.test1 set age=300 where id=1;
  37. 1 row updated.

  38. SYS@seiang11g>commit;
  39. Commit complete.

  40. SYS@seiang11g>alter system switch logfile;
  41. System altered.

  42. --修改数据并提交(sequence号5)
  43. SYS@seiang11g>update seiang.test1 set age=400 where id=1;
  44. 1 row updated.

  45. SYS@seiang11g>commit;
  46. Commit complete.

  47. SYS@seiang11g>alter system switch logfile;
  48. System altered.

  49. --修改数据并提交(sequence号6)
  50. SYS@seiang11g>update seiang.test1 set age=500 where id=1;
  51. 1 row updated.

  52. SYS@seiang11g>commit;
  53. Commit complete.

  54. SYS@seiang11g>alter system switch logfile;
  55. System altered.

  56. --修改数据并提交(sequence号7)
  57. SYS@seiang11g>update seiang.test1 set age=600 where id=1;
  58. 1 row updated.

  59. SYS@seiang11g>commit;
  60. Commit complete.

  61. SYS@seiang11g>alter system switch logfile;
  62. System altered.

  63. --当前联机日志序号为8
  64. SYS@seiang11g>select group#,sequence#,status from v$log;

  65.     GROUP# SEQUENCE# STATUS
  66. ---------- ---------- ----------------
  67.          1 7 ACTIVE
  68.          2 8 CURRENT
  69.          3 6 ACTIVE

  70. --查看相应的归档日志
  71. SYS@seiang11g>select name from v$archived_log;

  72. NAME
  73. ------------------------------------------------------
  74. /u01/app/oracle/arch/arch_1_950962051_1.log
  75. /u01/app/oracle/arch/arch_1_950962051_2.log
  76. /u01/app/oracle/arch/arch_1_950971495_1.log
  77. /u01/app/oracle/arch/arch_1_950971495_2.log
  78. /u01/app/oracle/arch/arch_1_950972396_1.log
  79. /u01/app/oracle/arch/arch_1_950972396_2.log
  80. /u01/app/oracle/arch/arch_1_950972396_3.log
  81. /u01/app/oracle/arch/arch_1_950972396_4.log
  82. /u01/app/oracle/arch/arch_1_950972396_5.log
  83. /u01/app/oracle/arch/arch_1_950972396_6.log
  84. /u01/app/oracle/arch/arch_1_950972396_7.log

  85. --关闭数据库
  86. SYS@seiang11g >shutdown immediate
  87. Database closed.
  88. Database dismounted.
  89. ORACLE instance shut down.

  90. --模拟数据文件seiang损坏
  91. SYS@seiang11g>host rm /u01/app/oracle/oradata/OraDB11g/seiang01.dbf


  92. --重新打开数据库 ,由于数据文件的丢死,数据库无法open
  93. SYS@seiang11g>startup
  94. ORACLE instance started.

  95. Total System Global Area 1252663296 bytes
  96. Fixed Size 2252824 bytes
  97. Variable Size 788533224 bytes
  98. Database Buffers 452984832 bytes
  99. Redo Buffers 8892416 bytes
  100. Database mounted.
  101. ORA-01157: cannot identify/lock data file 7 - see DBWR trace file
  102. ORA-01110: data file 7: '/u01/app/oracle/oradata/OraDB11g/seiang01.dbf'


  103. SYS@seiang11g>select * from v$recover_file;

  104.      FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
  105. ---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
  106.          7 ONLINE ONLINE FILE NOT FOUND 0

  107. --还原备份的数据文件
  108. SYS@seiang11g>host cp /u01/app/oracle/UMAN_Backup/seiang01.dbf /u01/app/oracle/oradata/OraDB11g/
  109.     
  110. SYS@seiang11g>select * from v$recover_file;

  111.      FILE# ONLINE ONLINE_ ERROR CHANGE# TIME
  112. ---------- ------- ------- ----------------------------------------------------------------- ---------- ---------
  113.          7 ONLINE ONLINE UNKNOWN ERROR 1913765 02-AUG-17


  114. --查看一下归档日志的详细信息
  115. SYS@seiang11g>select sequence#, name, first_change#, next_change# from v$archived_log;

  116.  SEQUENCE# NAME FIRST_CHANGE# NEXT_CHANGE#
  117. ---------- -------------------------------------------------- ------------- ------------
  118.         1 /u01/app/oracle/arch/arch_1_950962051_1.log 1914744 1921854
  119.          2 /u01/app/oracle/arch/arch_1_950962051_2.log 1921854 1921883
  120.          1 /u01/app/oracle/arch/arch_1_950971495_1.log 1913766 1914386
  121.          2 /u01/app/oracle/arch/arch_1_950971495_2.log 1914386 1914401
  122.          1 /u01/app/oracle/arch/arch_1_950972396_1.log 1914402 1936446
  123.          2 /u01/app/oracle/arch/arch_1_950972396_2.log 1936446 1937042
  124.          3 /u01/app/oracle/arch/arch_1_950972396_3.log 1937042 1937100
  125.          4 /u01/app/oracle/arch/arch_1_950972396_4.log 1937100 1937110
  126.          5 /u01/app/oracle/arch/arch_1_950972396_5.log 1937110 1937123
  127.          6 /u01/app/oracle/arch/arch_1_950972396_6.log 1937123 1937139
  128.          7 /u01/app/oracle/arch/arch_1_950972396_7.log 1937139 1937148


  129. --模拟归档日志5丢失或者损坏
  130. SYS@seiang11g>host rm /u01/app/oracle/arch/arch_1_950972396_5.log

  131. [oracle@seiang11g OraDB11g]$ ll /u01/app/oracle/arch/arch_1_950972396_5.log
  132. ls: cannot access /u01/app/oracle/arch/arch_1_950972396_5.log: No such file or directory


  133. --执行恢复操作,当在需要归档日志5的时候出现错误
  134. SYS@seiang11g>recover datafile 7;
  135. ORA-00279: change 1913766 generated at 08/02/2017 11:12:22 needed for thread 1
  136. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950971495_1.log
  137. ORA-00280: change 1913766 for thread 1 is in sequence #1

  138. Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
  139. auto
  140. ORA-00279: change 1914386 generated at 08/02/2017 14:48:59 needed for thread 1
  141. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950971495_2.log
  142. ORA-00280: change 1914386 for thread 1 is in sequence #2

  143. ORA-00279: change 1914402 generated at 08/02/2017 14:59:56 needed for thread 1
  144. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_1.log
  145. ORA-00280: change 1914402 for thread 1 is in sequence #1

  146. ORA-00279: change 1936446 generated at 08/02/2017 15:39:52 needed for thread 1
  147. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_2.log
  148. ORA-00280: change 1936446 for thread 1 is in sequence #2

  149. ORA-00279: change 1937042 generated at 08/02/2017 15:49:42 needed for thread 1
  150. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_3.log
  151. ORA-00280: change 1937042 for thread 1 is in sequence #3

  152. ORA-00279: change 1937100 generated at 08/02/2017 15:51:34 needed for thread 1
  153. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_4.log
  154. ORA-00280: change 1937100 for thread 1 is in sequence #4

  155. ORA-00279: change 1937110 generated at 08/02/2017 15:51:54 needed for thread 1
  156. ORA-00289: suggestion : /u01/app/oracle/arch/arch_1_950972396_5.log
  157. ORA-00280: change 1937110 for thread 1 is in sequence #5

  158. ORA-00308: cannot open archived log '/u01/app/oracle/arch/arch_1_950972396_5.log'
  159. ORA-27037: unable to obtain file status
  160. Linux-x86_64 Error: 2: No such file or directory
  161. Additional information: 3
  162.     
  163. --查看数据文件头,发现检查点不一致
  164. SYS@seiang11g>select file#,name,checkpoint_change# from v$datafile_header;

  165.      FILE# NAME CHECKPOINT_CHANGE#
  166. ---------- -------------------------------------------------- ------------------
  167.          1 /u01/app/oracle/oradata/OraDB11g/system01.dbf 1937617
  168.          2 /u01/app/oracle/oradata/OraDB11g/sysaux01.dbf 1937617
  169.          3 /u01/app/oracle/oradata/OraDB11g/undotbs01.dbf 1937617
  170.          4 /u01/app/oracle/oradata/OraDB11g/users01.dbf 1937617
  171.          5 /u01/app/oracle/oradata/OraDB11g/example01.dbf 1937617
  172.          6 /u01/app/oracle/oradata/OraDB11g/rman01.dbf 1937617
  173.          7 /u01/app/oracle/oradata/OraDB11g/seiang01.dbf 1937110
  174.          8 /u01/app/oracle/oradata/OraDB11g/wjq01.dbf 1937617
  175.          9 /u01/app/oracle/oradata/OraDB11g/wjqbest01.dbf 1937617

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Oracle手工不完全恢复(一):使用当前控制文件

下载Word文档到电脑,方便收藏和打印~

下载Word文档

编程热搜

目录