(Les16 执行数据库恢复)-表空间恢复

NOARCHIVELOG模式下丢失了数据文件

数据库处于NOARCHIVELOG模式时,如果丢失任何数据文件,执行以下步骤

1.如果实例尚未关闭,请关闭实例

2.从备份还原整个数据库,包括所有数据文件和控制文件

3.打开数据库

4.让用户重新输入自上次备份以来所做的所有更改

ARCHIVELOG模式下丢失了非关键性数据文件(SYSTEM,UNDO除外)

仅仅恢复当前数据文件不用整库恢复,不需要停机

1.数据文件离线

2.restore数据文件,介质恢复

3.recover事务

4.数据文件联机

ARCHIVELOG模式下丢失了关键性数据文件(SYSTEM,UNDO...)

数据库关键性数据文件丢失,需要停机恢复

1.实例可能会也可能不会自动关闭。如果未自动关闭,请使用SHUTDOWN ABORT关闭实例

2.装载数据库,MOUNT

3.还原并恢复缺失的数据文件,restore datafile/database

4.recover datafile/database

5.打开数据库

归档模式下恢复非关键表空间

set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;

创建一个非关键表空间进行测试

create tablespace redo_data  datafile ‘/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf‘ size 32M autoextend on next 32M maxsize 1024M;

SQL> create tablespace redo_data  datafile ‘/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf‘ size 32M autoextend on next 32M maxsize 1024M;

Tablespace created.

SQL> set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;

TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/xiocpt0/users01.dbf
UNDOTBS1             /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
SYSAUX               /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
SYSTEM               /u01/app/oracle/oradata/xiocpt0/system01.dbf
REDO_DATA            /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf

BACKUP AS COMPRESSED BACKUPSET DATABASE PLUS ARCHIVELOG;

对数据进行一次完全备份

RMAN> shutdown immediate
RMAN> startup mount
RMAN> run
{
allocate channel c1 device type disk format ‘/u01/backup/backup01_%U‘ ;
backup as compressed backupset database;
backup current controlfile;
alter database open;
}

RMAN> list backup;

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
7       Full    321.23M    DISK        00:00:38     22-MAY-18
        BP Key: 7   Status: AVAILABLE  Compressed: YES  Tag: TAG20180522T151208
        Piece Name: /u01/backup/backup01_08t3hoq8_1_1
  List of Datafiles in backup set 7
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/system01.dbf
  2       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
  3       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
  4       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/users01.dbf
  5       Full 1058982    22-MAY-18 /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
8       Full    1.05M      DISK        00:00:03     22-MAY-18
        BP Key: 8   Status: AVAILABLE  Compressed: YES  Tag: TAG20180522T151208
        Piece Name: /u01/backup/backup01_09t3horl_1_1
  SPFILE Included: Modification time: 22-MAY-18
  SPFILE db_unique_name: XIOCPT0
  Control File Included: Ckp SCN: 1058982      Ckp time: 22-MAY-18

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
9       Full    9.64M      DISK        00:00:01     22-MAY-18
        BP Key: 9   Status: AVAILABLE  Compressed: NO  Tag: TAG20180522T151257
        Piece Name: /u01/backup/backup01_0at3horp_1_1
  Control File Included: Ckp SCN: 1058982      Ckp time: 22-MAY-18

创建表并指定表空间

SQL> create table REDO_DATA(
  2  id number,
  3  name varchar2(20)
  4  )
  5  tablespace REDO_DATA;

Table created.

SQL> declare
v_count number;

begin
  for i in 1..1000 loop
  insert into redo_data values(i,‘name0‘||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> select count(*) from REDO_DATA;

  COUNT(*)
----------
      1000

恢复非关键表空间

sql ‘alter tablespace redo_data offline‘;---离线需恢复的表空间

restore tablespace redo_data;---还原表空间
recover tablespace redo_data;---恢复表空间,期间的事务进行应用

sql ‘alter tablespace redo_data online‘;---恢复完成,将表空间在线

删除数据文件
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf

SQL> select count(*) from REDO_DATA;

  COUNT(*)
----------
      1000

SQL> commit;

Commit complete.

SQL> declare
v_count number;

begin
  for i in 1..1000 loop
  insert into redo_data values(i,‘name0‘||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL>  select count(*) from REDO_DATA;

  COUNT(*)
----------
      2000

SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf: No such file or directory

SQL> select table_name ,tablespace_name from dba_tables where table_name=‘REDO_DATA‘;

TABLE_NAME                     TABLESPACE_NAME
------------------------------ --------------------
REDO_DATA                      REDO_DATA

SQL> alter system switch logfile;

System altered.

SQL>  alter system checkpoint;

System altered.

SQL> select count(*) from REDO_DATA;

  COUNT(*)
----------
      2000

SQL> declare
v_count number;

begin
  for i in 1..1000 loop
  insert into redo_data values(i,‘name0‘||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9

PL/SQL procedure successfully completed.

SQL> declare
v_count number;

begin
  for i in 1..1000 loop
  insert into redo_data values(i,‘name0‘||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9

PL/SQL procedure successfully completed.

SQL> declare
v_count number;

begin
  for i in 1..1000 loop
  insert into redo_data values(i,‘name0‘||i);
  end loop;
end;
/  2    3    4    5    6    7    8    9

PL/SQL procedure successfully completed.

SQL> commit;

Commit complete.

SQL> !ls -l /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
ls: cannot access /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf: No such file or directory

SQL> select count(*) from REDO_DATA;
select count(*) from REDO_DATA
                     *
ERROR at line 1:
ORA-00376: file 5 cannot be read at this time
ORA-01110: data file 5: ‘/u01/app/oracle/oradata/xiocpt0/redo_data01.dbf‘

开始执行还原/恢复操作

RMAN> sql ‘alter tablespace redo_data offline‘;

sql statement: alter tablespace redo_data offline

RMAN>
restore tablespace redo_data;
RMAN>

Starting restore at 22-MAY-18
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=19 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 00005 to /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/backup01_08t3hoq8_1_1
channel ORA_DISK_1: piece handle=/u01/backup/backup01_08t3hoq8_1_1 tag=TAG20180522T151208
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:01
Finished restore at 22-MAY-18

RMAN>   recover tablespace redo_data;

Starting recover at 22-MAY-18
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/arch_976375926_1_74.arc
archived log for thread 1 with sequence 75 is already on disk as file /u01/archive/arch_976375926_1_75.arc
archived log for thread 1 with sequence 76 is already on disk as file /u01/archive/arch_976375926_1_76.arc
archived log for thread 1 with sequence 77 is already on disk as file /u01/archive/arch_976375926_1_77.arc
archived log for thread 1 with sequence 78 is already on disk as file /u01/archive/arch_976375926_1_78.arc
archived log for thread 1 with sequence 79 is already on disk as file /u01/archive/arch_976375926_1_79.arc
archived log for thread 1 with sequence 80 is already on disk as file /u01/archive/arch_976375926_1_80.arc
archived log for thread 1 with sequence 81 is already on disk as file /u01/archive/arch_976375926_1_81.arc
archived log for thread 1 with sequence 82 is already on disk as file /u01/archive/arch_976375926_1_82.arc
archived log for thread 1 with sequence 83 is already on disk as file /u01/archive/arch_976375926_1_83.arc
archived log for thread 1 with sequence 84 is already on disk as file /u01/archive/arch_976375926_1_84.arc
archived log for thread 1 with sequence 85 is already on disk as file /u01/archive/arch_976375926_1_85.arc
archived log file name=/u01/archive/arch_976375926_1_74.arc thread=1 sequence=74
archived log file name=/u01/archive/arch_976375926_1_75.arc thread=1 sequence=75
archived log file name=/u01/archive/arch_976375926_1_76.arc thread=1 sequence=76
archived log file name=/u01/archive/arch_976375926_1_77.arc thread=1 sequence=77
archived log file name=/u01/archive/arch_976375926_1_78.arc thread=1 sequence=78
archived log file name=/u01/archive/arch_976375926_1_79.arc thread=1 sequence=79
archived log file name=/u01/archive/arch_976375926_1_80.arc thread=1 sequence=80
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-18

RMAN>   sql ‘alter tablespace redo_data online‘;

sql statement: alter tablespace redo_data online

SQL>  select count(*) from REDO_DATA;

  COUNT(*)
----------
      5000

归档模式下恢复关键表空间

数据库关键性数据文件丢失,需要停机恢复

1.实例可能会也可能不会自动关闭。如果未自动关闭,请使用SHUTDOWN ABORT关闭实例

2.装载数据库,MOUNT

3.还原并恢复缺失的数据文件,restore datafile/database

4.recover datafile/database

5.打开数据库

SQL> set linesize 300
set pagesize 600
col file_name format a50
col tablespace_name format a20
select tablespace_name,file_name from dba_data_files;SQL> SQL> SQL> SQL>

TABLESPACE_NAME      FILE_NAME
-------------------- --------------------------------------------------
USERS                /u01/app/oracle/oradata/xiocpt0/users01.dbf
UNDOTBS1             /u01/app/oracle/oradata/xiocpt0/undotbs01.dbf
SYSAUX               /u01/app/oracle/oradata/xiocpt0/sysaux01.dbf
SYSTEM               /u01/app/oracle/oradata/xiocpt0/system01.dbf
REDO_DATA            /u01/app/oracle/oradata/xiocpt0/redo_data01.dbf

SQL>
SQL> !rm -rf /u01/app/oracle/oradata/xiocpt0/system01.dbf

startup mount ---将数据库启动到mount
restore tablespace system;---指定关键表空间进行还原
recover tablespace system;---恢复表空间
sql ‘alter database open‘;---将数据库打开

[[email protected] ~]$ rman  target /

Recovery Manager: Release 11.2.0.4.0 - Production on Tue May 22 15:30:33 2018

Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

connected to target database (not started)

RMAN> startup mount

Oracle instance started
database mounted

Total System Global Area     409194496 bytes

Fixed Size                     2253744 bytes
Variable Size                322964560 bytes
Database Buffers              79691776 bytes
Redo Buffers                   4284416 bytes

RMAN> restore tablespace system;

Starting restore at 22-MAY-18
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=18 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 00001 to /u01/app/oracle/oradata/xiocpt0/system01.dbf
channel ORA_DISK_1: reading from backup piece /u01/backup/backup01_08t3hoq8_1_1
channel ORA_DISK_1: piece handle=/u01/backup/backup01_08t3hoq8_1_1 tag=TAG20180522T151208
channel ORA_DISK_1: restored backup piece 1
channel ORA_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 22-MAY-18

RMAN> recover tablespace system;

Starting recover at 22-MAY-18
using channel ORA_DISK_1

starting media recovery

archived log for thread 1 with sequence 74 is already on disk as file /u01/archive/arch_976375926_1_74.arc
archived log for thread 1 with sequence 75 is already on disk as file /u01/archive/arch_976375926_1_75.arc
archived log for thread 1 with sequence 76 is already on disk as file /u01/archive/arch_976375926_1_76.arc
archived log for thread 1 with sequence 77 is already on disk as file /u01/archive/arch_976375926_1_77.arc
archived log for thread 1 with sequence 78 is already on disk as file /u01/archive/arch_976375926_1_78.arc
archived log for thread 1 with sequence 79 is already on disk as file /u01/archive/arch_976375926_1_79.arc
archived log for thread 1 with sequence 80 is already on disk as file /u01/archive/arch_976375926_1_80.arc
archived log for thread 1 with sequence 81 is already on disk as file /u01/archive/arch_976375926_1_81.arc
archived log for thread 1 with sequence 82 is already on disk as file /u01/archive/arch_976375926_1_82.arc
archived log for thread 1 with sequence 83 is already on disk as file /u01/archive/arch_976375926_1_83.arc
archived log for thread 1 with sequence 84 is already on disk as file /u01/archive/arch_976375926_1_84.arc
archived log for thread 1 with sequence 85 is already on disk as file /u01/archive/arch_976375926_1_85.arc
archived log for thread 1 with sequence 86 is already on disk as file /u01/archive/arch_976375926_1_86.arc
archived log file name=/u01/archive/arch_976375926_1_74.arc thread=1 sequence=74
archived log file name=/u01/archive/arch_976375926_1_75.arc thread=1 sequence=75
archived log file name=/u01/archive/arch_976375926_1_76.arc thread=1 sequence=76
archived log file name=/u01/archive/arch_976375926_1_77.arc thread=1 sequence=77
archived log file name=/u01/archive/arch_976375926_1_78.arc thread=1 sequence=78
archived log file name=/u01/archive/arch_976375926_1_79.arc thread=1 sequence=79
archived log file name=/u01/archive/arch_976375926_1_80.arc thread=1 sequence=80
archived log file name=/u01/archive/arch_976375926_1_81.arc thread=1 sequence=81
media recovery complete, elapsed time: 00:00:00
Finished recover at 22-MAY-18

RMAN> sql ‘alter database open‘;

sql statement: alter database open

原文地址:https://www.cnblogs.com/also-brook/p/9072904.html

时间: 2024-12-13 08:51:16

(Les16 执行数据库恢复)-表空间恢复的相关文章

RMAN数据库恢复之恢复表空间和数据文件

执行表空间或数据文件恢复时,数据库既可以是MOUNT状态,也可以是OPEN状态.1.恢复表空间在执行恢复之前,如果被操作的表空间未处理OFFLINE状态,必须首先通过ALTER TABLESPACE…OFFLINE语句将其置为脱机.然后再RESTORE-->RECOVER--->ONLINE即可. RMAN> SQL 'ALTER TABLESPACE USERS OFFLINE IMMEDIATE'; 在恢复目录中注册的数据库的新原型 正在启动全部恢复目录的 resync 完成全部 r

如何用Dummy实例执行数据库的还原和恢复

今天实验了一下,如何在所有文件,包括数据文件,在线日志文件,控制文件都丢失的情况下,利用RMAN备份恢复和还原数据库.该实验的重点是用到了Dummy实例. 具体步骤如下: 备份数据库 [[email protected] ~]$ rman target / Recovery Manager: Release 11.2.0.4.0 - Production on Mon May 25 23:25:51 2015 Copyright (c) 1982, 2011, Oracle and/or its

ORACLE RMAN备份及还原 RMAN可以进行增量备份:数据库,表空间,数据文件

ORACLE RMAN备份及还原 RMAN可以进行增量备份:数据库,表空间,数据文件 只有使用过的block可以被备份成backup set 表空间与数据文件对应关系:dba_data_files / v$datafile_header 在noarchivelog模式下,可以使用RMAN备份read-only和offline的表空间 ORACLE RMAN停机备份: 备份 RMAN连接上ORACLE,WINDOWS下在命令模式下 RMAN TARGET / 连接本地数据库用的是本地认证模式.RM

数据库创建表空间、临时表空、用户、授权

备注:oracle版本Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 说明:创建临时表空间注意关键字和创建表空间有所差别,语句类似 关于创建语句解说请查看:http://blog.chinaunix.net/uid-20802110-id-2105656.html 所列语句都是经过测试实战! 1.创建表数据空间 说明:该版本数据库创建表空间执行logging时报错,不执行logging,默认也是logging create ta

在线扩大数据库UNDO表空间

用oracle账号登陆ORACLE数据库服务器 方法一: 查看表空间的名字及文件所在位置: select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space from dba_data_files order by tablespace_name; 修改数据库datafile文件到新的大小 alter database datafile '\oracle\oradata\undotab1.dbf'

Oracle数据库创建表空间

--Oracle数据库创建表空间 create tablespace new_taspace --表空间名 DATAFILE 'D:\NEWTABLESPACE.DBF'   --表空间关联的数据文件和位置 size 200M --文件初始大小 autoextend on next 20MB MAXSIZE 400MB; --文件大小可自动扩展,每次扩展20MB,最大400MB --创建表空间 create tablespace new_taspace1 --表空间关联的数据文件和位置 DATA

nagios监控oralce数据库的表空间大小

一.安装nrpe 本处使用直接解压的方式来安装的nrpe 二.配置nrpe服务 1.修改libexec文件夹中的check_oracle 在其中添加如下项 ORACLE_HOME=/oradata/Oracle/product/11.2.0 PATH=$PATH:/oradata/Oracle/product/11.2.0/bin 2.在nrpe.conf中添加如下项 command[check_oracle_tablespace]=/usr/local/nagios/libexec/check

Oracle数据库的表空间基本管理

一.概述 Oracle数据库是通过表空间来存储物理表的,一个数据库实例可以有N个表空间,一个表空间下可以有N张表. 有了数据库,就可以创建表空间. 表空间(tablespace)是数据库的逻辑划分,每个数据库至少有一个表空间(称作SYSTEM表空间).为了便于管理和提高运行效率,可以使用一些附加表空间来划分用户和应用程序.例如:USER表空间供一般用户使用,RBS表空间供回滚段使用.一个表空间只能属于一个数据库. 表空间是数据库中最大的逻辑单位, SYSTEM和SYSAUX表空间是在创建数据库时

表空间恢复数据库

第1章 故障背景 1.1 环境 硬件及软件环境: 联想服务器(IBM) 磁盘500G 没有raid centos 6.8 mysql 5.6.33 innodb引擎 独立表空间 备份没有,日志也没开 为什么没有备份和日志没有开? 因为是开发用户专用库(由开发人员自己维护) jira(bug追踪),confluence(内部知识库) 1.2 故障现象 因为是开发库,所以开发人员自己在维护,有一天,突然断电了,数据库起不来,开发人员处理了2天还没有处理好,最后就把这个问题丢给我了 我接手以后,已经是