18.4、Restoring Datafiles and Archived Redo Logs

假定介质故障损坏的一个或多个数据文件,数据文件必须恢复损坏的文件之前恢复。

该位置是不是想恢复原来姿势。它必须表现出在控制文件中的数据文件的新位置。

件的过程和在文件系统上是同样的。

模拟1、在testtbs01中创建表,插入数据。然后切换日志,备份归档日志,testtbs01的某个数据文件被损坏,相应归档日志删除,还原和恢复

(1)在testtbs01中创建表并插入数据

SQL>

create table boss_new_test

( id number(5) constraint id_pk primary key,

lastname varchar2(10) constraint ln_nn not null,

firstname varchar2(10) not null unique,

userid varchar2(8) constraint ui_uq unique,

startdate date default sysdate,

user_type varchar2(4) constraint ut_ck check (user_type in('in','out'))

)

initrans 1 maxtrans 255

pctfree 20 pctused 50

storage(initial 64m next 8m pctincrease 0)

tablespace testtbs01;

SQL> insert into boss_new_test values(1,'aaa','a','00001',sysdate,'in');

SQL> commit;

(2)创建存储过程插入数据

(3)查看检查点

SQL> set linesize 120

SQL> col "文件名称" for a40

SQL>

select

  ts.name "表空间名"

  , df.file# "文件号"

  , df.checkpoint_change# "检查点"

  , df.name "文件名称"

from v$tablespace ts,v$datafile df

where ts.ts#=df.ts# and ts.name='TESTTBS01'

order by df.file#;

表空间名                           文件号     检查点 文件名称

------------------------------ ---------- ---------- ----------------------------------------

TESTTBS01                               6     566111 /oracle/oradata/boss/testtbs01_01.dbf

SQL> select dbid,name,log_mode,checkpoint_change# from v$database;

DBID NAME      LOG_MODE     CHECKPOINT_CHANGE#

---------- --------- ------------ ------------------

1375601832 BOSS      ARCHIVELOG               566111

SQL> select file#,name,status,CHECKPOINT_CHANGE#,recover from v$datafile_header where file#=6;

FILE# NAME                                     STATUS  CHECKPOINT_CHANGE# REC

---------- ---------------------------------------- ------- ------------------ ---

         6 /oracle/oradata/boss/testtbs01_01.dbf    ONLINE              566111 NO

SQL> select group#,members,sequence#,archived,status,first_change# from v$log;

GROUP#    MEMBERS  SEQUENCE# ARC STATUS           FIRST_CHANGE#

---------- ---------- ---------- --- ---------------- -------------

         1          1          5 YES INACTIVE                534657

         2          1          6 NO  CURRENT               563694

         3          1          4 YES INACTIVE                514244

(4)进行日志切换,数据文件头scn和数据库scn并未变化

SQL> alter system switch logfile;

SQL> select group#,members,sequence#,archived,status,first_change# from v$log;

GROUP#    MEMBERS  SEQUENCE# ARC STATUS           FIRST_CHANGE#

---------- ---------- ---------- --- ---------------- -------------

         1          1          5 YES INACTIVE                534657

         2          1          6 YES ACTIVE                  563694

         3          1          7 NO  CURRENT                 569439

SQL> select file#,name,status,CHECKPOINT_CHANGE#,recover from v$datafile_header where file#=6;

FILE# NAME                                     STATUS  CHECKPOINT_CHANGE# REC

---------- ---------------------------------------- ------- ------------------ ---

         6 /oracle/oradata/boss/testtbs01_01.dbf    ONLINE              566111 NO

SQL> select dbid,name,log_mode,checkpoint_change# from v$database;

DBID NAME                                     LOG_MODE     CHECKPOINT_CHANGE#

---------- ---------------------------------------- ------------ ------------------

1375601832 BOSS                                     ARCHIVELOG               566111

SQL> alter system checkpoint;

SQL> select group#,members,sequence#,archived,status,first_change# from v$log;

GROUP#    MEMBERS  SEQUENCE# ARC STATUS           FIRST_CHANGE#

---------- ---------- ---------- --- ---------------- -------------

         1          1          5 YES INACTIVE                534657

         2          1          6 YES INACTIVE                563694

         3          1          7 NO  CURRENT                 569439

(5)备份新的归档日志

# cp -rf o1_mf_1_6_9rx90qq2_.arc /oradata/bossbak/test_ar_rec

(6)删除testtbs01的某个数据文件,删除o1_mf_1_6_9rx90qq2_.arc归档

# rm -rf testtbs01_01.dbf

# pwd

/oracle/flash_recovery_area/BOSS/archivelog/2014_06_04

# rm -rf o1_mf_1_6_9rx90qq2_.arc

(7)

SQL> alter system flush buffer_cache;

SQL> select * from boss_new_test;

ID LASTNAME   FIRSTNAME  USERID   STARTDATE    USER

---------- ---------- ---------- -------- ------------ ----

         2 aa         a          00002    04-JUN-14    in

         3 bb         b          00003    04-JUN-14    in

         4 cc         c          00004    04-JUN-14    in

         5 dd         d          00005    04-JUN-14    in

         6 ff         f          00006    04-JUN-14    in

SQL> create table boss_new_test1

  2  ( id number(5) constraint id_pk primary key,

  3  lastname varchar2(10) constraint ln_nn not null,

  4  firstname varchar2(10) not null unique,

  5  userid varchar2(8) constraint ui_uq unique,

  6  startdate date default sysdate,

  7  user_type varchar2(4) constraint ut_ck check (user_type in('in','out'))

  8  )

  9  initrans 1 maxtrans 255

 10  pctfree 20 pctused 50

 11  storage(initial 64m next 8m pctincrease 0)

 12  tablespace testtbs01;

user_type varchar2(4) constraint ut_ck check (user_type in('in','out'))

                                              *

ERROR at line 7:

ORA-01565: error in identifying file '/oracle/oradata/boss/testtbs01_01.dbf'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

SQL> shutdown immediate;

SQL> startup open;

Database mounted.

ORA-01157: cannot identify/lock data file 6 - see DBWR trace file

ORA-01110: data file 6: '/oracle/oradata/boss/testtbs01_01.dbf'

# cd $ORACLE_BASE/admin/boss/bdump

(8)还原和恢复数据文件

SQL> set linesize 150

# mkdir -p /oracle/oradata/boss/others

# cp -rf /oradata/bossbak/testtbs01_01.dbf /oracle/oradata/boss/others

SQL> select

  2    ts.name "表空间名"

  3    , df.file# "文件号"

  4    , df.checkpoint_change# "检查点"

  5    , df.name "文件名称"

  6    , df.status "在线状态"

  7    , rf.error "恢复原因"

  8    , rf.change# "系统变更号"

  9    , rf.time

 10    from v$tablespace ts,v$datafile df,v$recover_file rf

 11  where ts.ts#=df.ts# and df.file#=rf.file#

 12  order by df.file#;

表空间名                           文件号     检查点 文件名称                                   在线状  恢复原因           系统变更号 TIME

------------------------------ ---------- ---------- ---------------------------------------- ------- ------------------ ---------- ------------

TESTTBS01                               6     570729 /oracle/oradata/boss/testtbs01_01.dbf    ONLINE  FILE NOT FOUND              0

##离线数据文件

SQL> alter database datafile '/oracle/oradata/boss/testtbs01_01.dbf' offline;

##还原数据文件

SQL> recover datafile '/oracle/oradata/boss/testtbs01_01.dbf';

ORA-00283: recovery session canceled due to errors

ORA-01110: data file 6: '/oracle/oradata/boss/testtbs01_01.dbf'

ORA-01157: cannot identify/lock data file 6 - see DBWR trace file

ORA-01110: data file 6: '/oracle/oradata/boss/testtbs01_01.dbf'

SQL> alter database rename file '/oracle/oradata/boss/testtbs01_01.dbf' to '/oracle/oradata/boss/others/testtbs01_01.dbf';

alter database rename file '/oracle/oradata/boss/testtbs01_01.dbf' to '/oracle/oradata/boss/others/testtbs01_01.dbf'

*

ERROR at line 1:

ORA-01511: error in renaming log/data files

ORA-01141: error renaming data file 6 - new file '/oracle/oradata/boss/others/testtbs01_01.dbf' not found

ORA-01110: data file 6: '/oracle/oradata/boss/testtbs01_01.dbf'

ORA-27041: unable to open file

Linux Error: 13: Permission denied

Additional information: 2

# chown -R oracle:oinstall /oracle

# chown -R oracle:oinstall /oradata

SQL> alter database rename file '/oracle/oradata/boss/testtbs01_01.dbf' to '/oracle/oradata/boss/others/testtbs01_01.dbf';

##重做日志恢复

SQL> recover datafile 6;

Media recovery complete.

SQL> alter database datafile '/oracle/oradata/boss/others/testtbs01_01.dbf' online;

SQL> alter database open;

SQL> select * from boss_new_test;

ID LASTNAME   FIRSTNAME  USERID   STARTDATE    USER

---------- ---------- ---------- -------- ------------ ----

         2 aa         a          00002    04-JUN-14    in

         3 bb         b          00003    04-JUN-14    in

         4 cc         c          00004    04-JUN-14    in

         5 dd         d          00005    04-JUN-14    in

         6 ff         f          00006    04-JUN-14    in

二次測试:

(1)导出表boss_new_test

$ exp \"sys/a as sysdba\" file=/oradata/bossbak/boss_new_test_20140604.dmp log=/oradata/bossbak/expboss_new_test.log tables=boss_new_test

(2)删除表boss_new_test

SQL> truncate table boss_new_test;

SQL> drop table boss_new_test;

SQL> purge table boss_new_test;

(3)SQL> drop tablespace testtbs01 including contents and datafiles;

(4)

SQL> select group#,members,sequence#,archived,status,first_change# from v$log;

GROUP#    MEMBERS  SEQUENCE# ARC STATUS           FIRST_CHANGE#

---------- ---------- ---------- --- ---------------- -------------

         1          1         11 YES INACTIVE                572850

         2          1         12 YES INACTIVE                572852

         3          1         13 NO  CURRENT                 572854

SQL>  alter system switch logfile;

SQL>  alter system switch logfile;

SQL>  alter system switch logfile;

 alter system switch logfile;

 alter system switch logfile;

 alter system switch logfile;

(5)备份新的归档日志

$ cp -rf *.arc /oradata/bossbak/test_ar_rec

$ ll

总用量 1724

-rw-r----- 1 oracle oinstall 1735168 6月   4 15:05 o1_mf_1_13_9rxk4vq9_.arc

-rw-r----- 1 oracle oinstall    1024 6月   4 15:05 o1_mf_1_14_9rxk4x7j_.arc

-rw-r----- 1 oracle oinstall    5632 6月   4 15:05 o1_mf_1_15_9rxk52tx_.arc

-rw-r----- 1 oracle oinstall    1024 6月   4 15:05 o1_mf_1_16_9rxk52wv_.arc

-rw-r----- 1 oracle oinstall    1024 6月   4 15:05 o1_mf_1_17_9rxk57y7_.arc

-rw-r----- 1 oracle oinstall    1024 6月   4 15:05 o1_mf_1_18_9rxk5818_.arc

(6)删除testtbs01的某个数据文件,删除全部归档

$ rm -rf testtbs01_01.dbf

$ cd /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04

$ rm -rf *

(7)

SQL> create table boss_new_test1

  2  ( id number(5) constraint id_pk primary key,

  3  lastname varchar2(10) constraint ln_nn not null,

  4  firstname varchar2(10) not null unique,

  5  userid varchar2(8) constraint ui_uq unique,

  6  startdate date default sysdate,

  7  user_type varchar2(4) constraint ut_ck check (user_type in('in','out'))

  8  )

  9  initrans 1 maxtrans 255

 10  pctfree 20 pctused 50

 11  storage(initial 64m next 8m pctincrease 0)

 12  tablespace testtbs01;

user_type varchar2(4) constraint ut_ck check (user_type in('in','out'))

                                              *

ERROR at line 7:

ORA-01565: error in identifying file '/oracle/oradata/boss/testtbs01_01.dbf'

ORA-27037: unable to obtain file status

Linux Error: 2: No such file or directory

Additional information: 3

SQL> select file#,name,status,CHECKPOINT_CHANGE#,recover from v$datafile_header where file#=6;

FILE# NAME                                     STATUS  CHECKPOINT_CHANGE# REC

---------- ---------------------------------------- ------- ------------------ ---

         6 /oracle/oradata/boss/testtbs01_01.dbf    ONLINE              575477 NO

SQL> alter system checkpoint;

SQL> select file#,name,status,CHECKPOINT_CHANGE#,recover from v$datafile_header where file#=6;

FILE# NAME                                     STATUS  CHECKPOINT_CHANGE# REC

---------- ---------------------------------------- ------- ------------------ ---

         6 /oracle/oradata/boss/testtbs01_01.dbf    ONLINE              575795 NO

SQL> shutdown immediate;

SQL> startup open;

Database mounted.

ORA-01157: cannot identify/lock data file 6 - see DBWR trace file

ORA-01110: data file 6: '/oracle/oradata/boss/testtbs01_01.dbf'

(8)

$ cp -rf /oradata/bossbak/testtbs01_01.dbf /oracle/oradata/boss/

SQL> select file#,name,status,CHECKPOINT_CHANGE#,recover from v$datafile_header where file#=6;

FILE# NAME                                     STATUS  CHECKPOINT_CHANGE# REC

---------- ---------------------------------------- ------- ------------------ ---

         6 /oracle/oradata/boss/testtbs01_01.dbf    OFFLINE             575015 YES

SQL> select dbid,name,log_mode,checkpoint_change# from v$database;

DBID NAME                                     LOG_MODE     CHECKPOINT_CHANGE#

---------- ---------------------------------------- ------------ ------------------

1375601832 BOSS                                     ARCHIVELOG               576285

SQL> select

  2    ts.name "表空间名"

  3    , df.file# "文件号"

  4    , df.checkpoint_change# "检查点"

  5    , df.name "文件名称"

  6  from v$tablespace ts,v$datafile df

  7  where ts.ts#=df.ts# and ts.name='TESTTBS01'

  8  order by df.file#;

表空间名                           文件号     检查点 文件名称

------------------------------ ---------- ---------- ----------------------------------------

TESTTBS01                               6     576285 /oracle/oradata/boss/testtbs01_01.dbf

##多次日志切换。仅仅能从归档日志恢复

SQL> recover datafile '/oracle/oradata/boss/testtbs01_01.dbf';

ORA-00279: change 575015 generated at 06/04/2014 14:55:59 needed for thread 1

ORA-00289: suggestion : /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_13_%u_.arc

ORA-00280: change 575015 for thread 1 is in sequence #13

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

##拷贝所需归档日志,输入auto

$ cp -rf /oradata/bossbak/test_ar_rec/*.arc /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04

SQL> recover datafile '/oracle/oradata/boss/testtbs01_01.dbf';

ORA-00279: change 575015 generated at 06/04/2014 14:55:59 needed for thread 1

ORA-00289: suggestion : /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_13_%u_.arc

ORA-00280: change 575015 for thread 1 is in sequence #13

Specify log: {<RET>=suggested | filename | AUTO | CANCEL}

auto 

ORA-00279: change 575465 generated at 06/04/2014 15:02:51 needed for thread 1

ORA-00289: suggestion : /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_14_%u_.arc

ORA-00280: change 575465 for thread 1 is in sequence #14

ORA-00278: log file '/oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_13_9rxk4vq9_.arc' no longer needed

for this recovery

ORA-00279: change 575467 generated at 06/04/2014 15:02:53 needed for thread 1

ORA-00289: suggestion : /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_15_%u_.arc

ORA-00280: change 575467 for thread 1 is in sequence #15

ORA-00278: log file '/oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_14_9rxk4x7j_.arc' no longer needed

for this recovery

ORA-00279: change 575470 generated at 06/04/2014 15:02:58 needed for thread 1

ORA-00289: suggestion : /oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_16_%u_.arc

ORA-00280: change 575470 for thread 1 is in sequence #16

ORA-00278: log file '/oracle/flash_recovery_area/BOSS/archivelog/2014_06_04/o1_mf_1_15_9rxk52tx_.arc' no longer needed

for this recovery

Log applied.

Media recovery complete.

SQL> alter database datafile '/oracle/oradata/boss/testtbs01_01.dbf' online;

SQL> alter database open;

SQL> select * from boss_new_test;

ID LASTNAME   FIRSTNAME  USERID   STARTDATE    USER

---------- ---------- ---------- -------- ------------ ----

         1 aaa        a          00001    04-JUN-14    in

         2 bbb        b          00002    04-JUN-14    in

         3 ccc        c          00003    04-JUN-14    in

         4 ddd        d          00004    04-JUN-14    in

         5 eee        e          00005    04-JUN-14    in

         6 fff        f          00006    04-JUN-14    in

总结:数据文件恢复成功后,数据库scn、数据文件scn是同样的,它们和数据文件头scn不一定是相同的。但数据文件头scn>=数据库scn

版权声明:本文博客原创文章,博客,未经同意,不得转载。

Performing User-Managed Database-18.4、Restoring Datafiles and Archived Redo Logs的更多相关文章

  1. Performing User-Managed Database-18.5、Restoring Control Files

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/offbeatmine/article/details/28429339 18.5.Restoring ...

  2. Performing a full database disaster recovery with RMAN

    Performing a full database disaster recovery with RMAN1. Make the RMAN backup set pieces available.2 ...

  3. MySQL5.7.18 备份、Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份,数据导入导出

    粗略介绍冷备,热备,温暖,及Mysqldump,mysqlpump,xtrabackup,innobackupex 全量,增量备份 --备份的目的 灾难恢复:意外情况下(如服务器宕机.磁盘损坏等)对损 ...

  4. MySQL安装卸载、idea中Database的使用、常用的sql语句

    MySQL安装卸载 MySQL安装 在下面的资源链接中下载MySQL软件压缩包(绿色版),这个版本是MySQL5.7.29的,本教程也只适用于这个绿色版的,如果下载的是安装包那就可能有些地方不一样了, ...

  5. leetcode 1.Two Sum 、167. Two Sum II - Input array is sorted 、15. 3Sum 、16. 3Sum Closest 、 18. 4Sum 、653. Two Sum IV - Input is a BST

    1.two sum 用hash来存储数值和对应的位置索引,通过target-当前值来获得需要的值,然后再hash中寻找 错误代码1: Input:[3,2,4]6Output:[0,0]Expecte ...

  6. .NET Core CSharp初级篇 1-8泛型、逆变与协变

    .NET Core CSharp初级篇 1-8 本节内容为泛型 为什么需要泛型 泛型是一个非常有趣的东西,他的出现对于减少代码复用率有了很大的帮助.比如说遇到两个模块的功能非常相似,只是一个是处理in ...

  7. 18 JSON、JSON字符串、反序列化

    JSON教程 : https://www.runoob.com/python/python-json.html 概念 JSON是一种轻量级的数据交换格式,它是一种数据格式! JSON易于阅读.易于解析 ...

  8. android学习笔记18——dpi、dp、sp、xp......

    参考:http://www.cnblogs.com/greatverve/archive/2011/12/28/android-dip-dp-sp-pt-px.html  http://www.360 ...

  9. [c/c++] programming之路(18)、动态分配内存malloc

    一.图解堆栈 #include<stdio.h> #include<stdlib.h> #include<Windows.h> void main0(){ **]; ...

随机推荐

  1. SQL Server高可用——日志传送(4-2)——部署

    原文:SQL Server高可用--日志传送(4-2)--部署 前文再续,书接上一回.本章演示一下日志传送的具体过程 准备工作: 由于时间关系,已经装好了3台虚拟机,且同在一个域里面: SQL01:主 ...

  2. FZU 1686 龙之谜 重复覆盖

    兑换0,1模型,如.注意,数据的范围 #include <stdio.h> #include <string.h> #include <iostream> #inc ...

  3. 打印到类阵列的给定序列的所有排列的n皇后问题

    题目例如以下:Given a collection of numbers, return all possible permutations. For example, [1,2,3] have th ...

  4. ContentProvider总结(Android)

    ContentProvider 1.适用场景 1) ContentProvider为存储和读取数据提供了统一的接口 2) 使用ContentProvider,应用程序能够实现数据共享 3) andro ...

  5. spring与mybatis集成和事务控制

    一个. 基本介绍 本文将使用spring整合mybatis, 并加入事务管理, 以此为记, 方便以后查阅. 二. 样例 1. 代码结构图: 2. 建表语句: DROP DATABASE test; C ...

  6. 获得mysql内容,生成xml文件,另外,为了webservice发送

    <xyt> <news id> <url></url> <title></title> </news> </x ...

  7. Centos7系统配置上的变化(一)

    原文 Centos7系统配置上的变化(一) 安装后,一开始有点儿无力吐槽的感觉,变化这么大? 一.Runlevel 首先一条,原来一直用的CentOS-6.5-x86_64-minimal.iso光盘 ...

  8. django 简易博客开发 1 安装、创建、配置、admin使用(转)

    Django 自称是“最适合开发有限期的完美WEB框架”.本文参考<Django web开发指南>,快速搭建一个blog 出来,在中间涉及诸多知识点,这里不会详细说明,如果你是第一次接触D ...

  9. Java新手如何学习Spring、Struts、Hibernate三大框架?(转)

    整理知乎大牛答案: 1.入门看文档(blog,书籍等等),深入理解配置文件的含义(Spring.Struts.Hibernate); 2.遇到问题,自己动手解决,如果解决了,为什么这样解决?(凡事总问 ...

  10. MOCK.JS 生成随机数据,拦截 Ajax 请求

    mock.js 的用处 前后端分离 :让前端攻城师独立于后端进行开发. 增加单元测试的真实性 :通过随机数据,模拟各种场景. 开发无侵入 :不需要修改既有代码,就可以拦截 Ajax 请求,返回模拟的响 ...