设为首页 收藏本站
查看: 748|回复: 0

[经验分享] oracle 在线重做日志恢复

[复制链接]

尚未签到

发表于 2018-9-13 09:44:42 | 显示全部楼层 |阅读模式
  回顾一下:在线重做日志的状态
  1.unused -- 未使用状态
  2.current -- 当前状态
  3.active -- 活动状态
  4.inactive -- 非活动状态
  1.unused & inactive 状态的日志丢失
  如果是inactive状态,那么说明:
  该日志记录的数据库的变化,都已经同步到数据文件;
  实例恢复也不需要这个日志文件存在。
  那么,这样的日志文件损坏,于数据无影响;
  将日志文件本身修复即可;
  SYS@orcl11g> startup mount;
  ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
  ORACLE instance started.
  Total System Global Area  422670336 bytes
  Fixed Size                  1345380 bytes
  Variable Size             322963612 bytes
  Database Buffers           92274688 bytes
  Redo Buffers                6086656 bytes
  Database mounted.
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 INACTIVE
  3 UNUSED
  2 CURRENT
  --破坏inactive & unused状态的日志文件
  [oracle@db253 trace]$ cd /u01/app/oracle/oradata/orcl11g
  [oracle@db253 orcl11g]$ cp /etc/passwd redo01.log
  [oracle@db253 orcl11g]$ cp /etc/passwd redo03.log
  SYS@orcl11g> alter database open;
  alter database open
  *
  ERROR at line 1:
  ORA-03113: end-of-file on communication channel
  Process ID: 10685
  Session ID: 125 Serial number: 5
  SYS@orcl11g> conn / as sysdba
  Connected to an idle instance.
  SYS@orcl11g> startup mount;
  ORACLE instance started.
  Total System Global Area  835104768 bytes
  Fixed Size      2232960 bytes
  Variable Size    520097152 bytes
  Database Buffers   306184192 bytes
  Redo Buffers      6590464 bytes
  Database mounted.
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 INACTIVE
  3 INACTIVE
  2 CURRENT
  --清理日志组即可,oracle会自动创建新的日志文件出来,状态为unused
  SYS@orcl11g> alter database clear logfile group 1;
  SYS@orcl11g> alter database clear logfile group 3;
  --清理之后的日志状态
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 UNUSED
  3 UNUSED
  2 CURRENT
  --正常打开数据库
  SYS@orcl11g> alter database open;
  2.active状态的日志文件损坏
  --数据更新
  SYS@orcl11g> update hr.employees set salary=salary+1;
  SYS@orcl11g> commit;
  --切换日志,更新操作保留在active状态的日志中
  SYS@orcl11g> alter system switch logfile;
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 CURRENT
  2 ACTIVE
  3 UNUSED
  --查看当前的归档状态
  SYS@orcl11g> archive log list;
  Database log mode              Archive Mode
  Automatic archival             Enabled
  Archive destination            /u01/app/oracle/arch
  Oldest online log sequence     2
  Next log sequence to archive   3
  Current log sequence           3
  --为了保留active状态,只能shutdown abort
  SYS@orcl11g> shutdown abort;
  ORACLE instance shut down.
  --启动到mount
  SYS@orcl11g> startup mount;
  ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
  ORACLE instance started.
  Total System Global Area  422670336 bytes
  Fixed Size                  1345380 bytes
  Variable Size             322963612 bytes
  Database Buffers           92274688 bytes
  Redo Buffers                6086656 bytes
  Database mounted.
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 CURRENT
  3 UNUSED
  2 ACTIVE
  -- 破坏2号日志组日志文件
  SYS@orcl11g> host cp /etc/passwd /u01/app/oracle/oradata/orcl11g/redo02.log
  --打开数据库
  SYS@orcl11g> alter database open;
  alter database open
  *
  ERROR at line 1:
  ORA-00313: open failed for members of log group 2 of thread 1
  ORA-00312: online log 2 thread 1: '/u01/app/oracle/oradata/orcl11g/redo02.log'
  ORA-27048: skgfifi: file header information is invalid
  Additional information: 14
  --因为,存在归档,所以,可以直接恢复数据库
  SYS@orcl11g> select sequence#,group#,status from v$log;
  SEQUENCE#     GROUP# STATUS
  ---------- ---------- ----------------
  75          1 CURRENT
  73          3 INACTIVE
  74          2 ACTIVE
  SYS@orcl11g> recover database until cancel;
  ORA-00279: change 1763218 generated at 06/24/2013 12:02:00 needed for thread 1
  ORA-00289: suggestion : /u01/app/oracle/arch/1_74_816622368.dbf
  ORA-00280: change 1763218 for thread 1 is in sequence #74
  Specify log: {=suggested | filename | AUTO | CANCEL}
  /u01/app/oracle/arch/1_74_816622368.dbf
  ORA-00279: change 1769094 generated at 06/24/2013 13:34:43 needed for thread 1
  ORA-00289: suggestion : /u01/app/oracle/arch/1_75_816622368.dbf
  ORA-00280: change 1769094 for thread 1 is in sequence #75
  ORA-00278: log file '/u01/app/oracle/arch/1_74_816622368.dbf' no longer needed
  for this recovery
  Specify log: {=suggested | filename | AUTO | CANCEL}
  /u01/app/oracle/oradata/orcl11g/redo01.log
  Log applied.
  Media recovery complete.
  SYS@orcl11g> alter database open resetlogs;
  Database altered.
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 CURRENT
  2 UNUSED
  3 UNUSED
  --查看一下数据情况
  --数据不会有丢失的情况,因为所有的日志都被recover了;
  3.current状态的日志损坏
  SYS@orcl11g> update hr.employees set salary=salary+1;
  SYS@orcl11g> commit;
  SYS@orcl11g> alter system switch logfile;
  SYS@orcl11g> select salary from hr.employees where employee_id=100;
  SALARY
  ----------
  31948
  SYS@orcl11g> update hr.employees set salary=salary+1;
  SYS@orcl11g> commit;
  SYS@orcl11g> select salary from hr.employees where employee_id=100;
  SALARY
  ----------
  31949
  --日志状态
  SYS@orcl11g> select group#,sequence#,status from v$log;
  GROUP#  SEQUENCE# STATUS
  ---------- ---------- ----------------
  1          1 INACTIVE
  2          2 ACTIVE
  3          3 CURRENT
  --模拟实例崩溃,current状态的日志文件损坏
  SYS@orcl11g> shutdown abort;
  ORACLE instance shut down.
  SYS@orcl11g> startup mount;
  ORA-32004: obsolete or deprecated parameter(s) specified for RDBMS instance
  ORACLE instance started.
  Total System Global Area  422670336 bytes
  Fixed Size                  1345380 bytes
  Variable Size             322963612 bytes
  Database Buffers           92274688 bytes
  Redo Buffers                6086656 bytes
  Database mounted.
  SYS@orcl11g> select group#,status from v$log;
  GROUP# STATUS
  ---------- ----------------
  1 INACTIVE
  3 CURRENT
  2 ACTIVE
  SYS@orcl11g> host cp /etc/passwd /u01/app/oracle/oradata/orcl11g/redo03.log
  --open database打开数据库
  SYS@orcl11g> alter database open;
  alter database open
  *
  ERROR at line 1:
  ORA-00313: open failed for members of log group 3 of thread 1
  ORA-00312: online log 3 thread 1: '/u01/app/oracle/oradata/orcl11g/redo03.log'
  ORA-27048: skgfifi: file header information is invalid
  Additional information: 14
  --查看隐藏参数
  SYS@orcl11g> show parameter "_allow_resetlogs_corruption";
  NAME                                 TYPE        VALUE
  ------------------------------------ ----------- ------------------------------
  _allow_resetlogs_corruption          boolean     TRUE
  --如果这个参数为false,修改为true
  --alter system set "_allow_resetlogs_corruption"=true scope=spfile;
  --shutdown abort;
  --startup mount;
  --修复数据库
  SYS@orcl11g> recover database until cancel;
  ORA-00279: change 1789650 generated at 06/24/2013 13:40:21 needed for thread 1
  ORA-00289: suggestion : /u01/app/oracle/arch/1_2_818948248.dbf
  ORA-00280: change 1789650 for thread 1 is in sequence #2
  Specify log: {=suggested | filename | AUTO | CANCEL}
  /u01/app/oracle/arch/1_2_818948248.dbf
  ORA-00279: change 1789904 generated at 06/24/2013 13:41:02 needed for thread 1
  ORA-00289: suggestion : /u01/app/oracle/arch/1_3_818948248.dbf
  ORA-00280: change 1789904 for thread 1 is in sequence #3
  ORA-00278: log file '/u01/app/oracle/arch/1_2_818948248.dbf' no longer needed
  for this recovery
  Specify log: {=suggested | filename | AUTO | CANCEL}
  cancel
  ORA-01547: warning: RECOVER succeeded but OPEN RESETLOGS would get error below
  ORA-01194: file 1 needs more recovery to be consistent
  ORA-01110: data file 1: '/u01/app/oracle/oradata/orcl11g/system01.dbf'
  ORA-01112: media recovery not started
  SYS@orcl11g> alter database open resetlogs;
  Database altered.
  --查看数据情况
  SYS@orcl11g> select salary from hr.employees where employee_id=100;
  SALARY
  ----------
  31948


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-577447-1-1.html 上篇帖子: oracle 无备份恢复数据文件 下篇帖子: ORACLE 嵌套游标
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表