码迷,mamicode.com
首页 > 数据库 > 详细

oracle 12c 多租户 pdb 恢复(单个pdb数据文件、非系统pdb表空间、整个pdb数据库)

时间:2017-05-12 01:40:33      阅读:302      评论:0      收藏:0      [点我收藏+]

标签:name   user   mount   auto   where   target   ati   files   app   

环境:数据库版本 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

实验准备:
1.-- 数据库归档模式
SQL> select name,log_mode from v$database;
NAME  LOG_MODE
--------- ------------
ANDYCDB   ARCHIVELOG   > 数据库归档模式

2.-- 登录 PDB 中创建实验表空间 与 用户
[oracle@12c ~]$ sqlplus sys/oracle@10.219.24.16:1521/pdb01 as sysdba
SQL> 
create tablespace bbb logging  datafile ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf‘ 
size 1m  autoextend on  next 1m maxsize 2m  extent management local;
Tablespace created.
SQL>alter tablespace bbb add  datafile ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb02.dbf‘size 1M  
autoextend on  next 1m maxsize 2m  ;
Tablespace altered.

create user andy identified by andy default tablespace users;
create user bbb identified by bbb default tablespace bbb;
grant dba to andy;
grant dba to bbb;

3.-- 备份整个CDB及其下面的所有PDB
[oracle@12c ~]$ mkdir /home/oracle/rmanback/
[oracle@12c01 ~]$ rman target /

run{
alter system archive log current;
allocate channel ch1 type disk;
allocate channel ch2 type disk;
backup incremental level 0 database plus archivelog delete input
format ‘/home/oracle/rmanback/db_%d_%U‘
tag=db_inc_0;
release channel ch1;
release channel ch2;
}
Finished backup at 12-MAY-17

一、  恢复 PDB 数据文件

数据库在open的时候,会对当前的数据的所有数据文件进行检查。 
对于system,sysaux和undo表空间的数据文件,如果有问题,数据库无法open。如果是PDB中某个普通的数据文件出现丢失,我们可以先用offline方式跳过,然后再打数据库,稍后再对数据文件做恢复: 
[oracle@12c ~]$ sqlplus sys/oracle@10.219.24.16:1521/pdb01 as sysdba
SQL> show con_name
CON_NAME
------------------------------
PDB01
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/andycdb/pdb01/system01.dbf
/home/oracle/app/oracle/oradata/andycdb/pdb01/sysaux01.dbf
/home/oracle/app/oracle/oradata/andycdb/pdb01/undotbs01.dbf
/home/oracle/app/oracle/oradata/andycdb/pdb01/users01.dbf
/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf
/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb02.dbf
6 rows selected.

摸拟pdb数据文件 user 删除
[oracle@12c01 ~]$ cd /home/oracle/app/oracle/oradata/andycdb/pdb01/
[oracle@12c01 ~]$ mv users01.dbf users01.dbf.bak
-- 模拟业务
C:\Users\andy>sqlplus andy/andy@10.219.24.16:1521/pdb01
SQL> create table andy as select * from all_objects;
create table andy as select * from all_objects                                  *
ERROR at line 1:
ORA-01116: error in opening database file 12
ORA-01110: data file 12:
‘/home/oracle/app/oracle/oradata/andycdb/pdb01/users01.dbf‘
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL> alter system checkpoint;
System altered.
-- alert_andycdb.log 日志查看报错:
ORA-01110: data file 12: ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/users01.dbf‘
ORA-01565: error in identifying file ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/users01.dbf‘
-- 进入 PDB 查看数据文件状态
SQL> 
col name for a60;
select file#,status,name from v$datafile;
     FILE# STATUS  NAME
---------- ------- ------------------------------------------------------------
9 SYSTEM  /home/oracle/app/oracle/oradata/andycdb/pdb01/system01.dbf
10 ONLINE  /home/oracle/app/oracle/oradata/andycdb/pdb01/sysaux01.dbf
11 ONLINE  /home/oracle/app/oracle/oradata/andycdb/pdb01/undotbs01.dbf
12 ONLINE  /home/oracle/app/oracle/oradata/andycdb/pdb01/users01.dbf
13 ONLINE  /home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf
14 ONLINE  /home/oracle/app/oracle/oradata/andycdb/pdb01/bbb02.dbf
6 rows selected.

说明: 12c r1版本,如果pdb数据文件损坏,会造成 cdb 一起宕机。 12c r2版本 pdb数据文件损坏,cdb 与 pdb 都没有宕机。
-- 使用 rman 恢复
[oracle@12c pdb01]$ rman target sys/oracle@10.219.24.16:1521/pdb01 
RMAN> recover datafile 12;
RMAN-06094: datafile 12 must be restored 
RMAN> alter database datafile 12 offline;
RMAN> alter database datafile 12 offline;
RMAN> restore datafile 12; 
RMAN> recover datafile 12; 
Finished recover at 12-MAY-17
然后对数据文件进行online处理 
RMAN> alter database datafile 12 online; 
Statement processed
-- 模拟业务   成功!
SQL> create table andy as select * from all_objects;
Table created.

二、 恢复 PDB 非系统表空间

实验: 模拟 PDB 非系统表空间 bbb 损坏。
[oracle@12c ~]$ sqlplus sys/oracle@10.219.24.16:1521/pdb01 as sysdba
--查询表空间情况
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME       STATUS
------------------------------ ---------
SYSTEM       ONLINE
SYSAUX       ONLINE
UNDOTBS1       ONLINE
TEMP       ONLINE
USERS       ONLINE
BBB       ONLINE
SQL>
col tablespace_name for a15
col file_name for a55
SELECT tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 0) total_space
FROM dba_data_files where tablespace_name=‘BBB‘ ORDER BY tablespace_name;
TABLESPACE_NAME    FILE_ID FILE_NAME                                               TOTAL_SPACE
--------------- ---------- ------------------------------------------------------- -----------
BBB                     13 /home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf             1
BBB                     14 /home/oracle/app/oracle/oradata/andycdb/pdb01/bbb02.dbf           1
--模拟表空间损坏
[oracle@12c pdb01]$ pwd
/home/oracle/app/oracle/oradata/andycdb/pdb01
[oracle@12c pdb01]$ ll bbb*
-rw-r-----. 1 oracle oinstall 1056768 May 12 06:42 bbb02.dbf
-rw-r-----. 1 oracle oinstall 1056768 May 12 06:42 bbb.dbf
[oracle@12c pdb01]$ rm -rf bbb*
--模拟业务
C:\Users\andy>sqlplus bbb/bbb@10.219.24.16:1521/pdb01
SQL> create table andy as select * from all_objects;
ERROR at line 1:
ORA-01116: error in opening database file 13
ORA-01110: data file 13:
‘/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf‘
ORA-27041: unable to open file
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
-- alert_andycdb.log 日志查看报错:
ORA-01110: data file 13: ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf‘
ORA-01565: error in identifying file ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf‘
ORA-27037: unable to obtain file status
ORA-01110: data file 14: ‘/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb02.dbf‘
SQL> alter system checkpoint;
System altered.
SQL> select tablespace_name,status from dba_tablespaces;
TABLESPACE_NAME                STATUS
------------------------------ ---------
SYSTEM                         ONLINE
SYSAUX                         ONLINE
UNDOTBS1                       ONLINE
TEMP                           ONLINE
USERS                          ONLINE
BBB                            ONLINE
-- 使用 rman 恢复
[oracle@12c pdb01]$ rman target sys/oracle@10.219.24.16:1521/pdb01
RMAN> alter tablespace bbb offline;
ORA-27041: unable to open file
RMAN> alter tablespace bbb offline immediate;
Statement processed
RMAN> recover tablespace bbb;
RMAN-06094: datafile 13 must be restored
RMAN> restore tablespace bbb;
Finished restore at 12-MAY-17
RMAN> recover tablespace bbb;
Finished recover at 12-MAY-17
RMAN> alter tablespace bbb online;
Statement processed
-- 模拟业务 成功!
SQL> create table andy as select * from all_objects where rownum>2;
Table created.

三、  单个PDB数据库恢复
恢复单个PDB的前提是CDB已经能够正常启动,在CDB启动的情况下在RMAN中采用restore pluggable database pdb名称指定单个PDB数据库进行恢复,如下
SQL> show con_name
CON_NAME
------------------------------
PDB01
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_system_dk5wmv0s_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_sysaux_dk5wmv11_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_users_dk6wky42_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_undo_1_dk5wmv13_.dbf
-- 模拟整个 pdb 损坏
[oracle@12c01 datafile]$ cd /home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598
[oracle@12c01 4ECF8621E3DA38EEE0531019640AA598]$ rm -rf datafile/
SQL> alter system checkpoint;
System altered.
SQL> show pdbs
    CON_ID CON_NAME  OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED  READ ONLY  NO
3 PDB01  MOUNTED
RMAN>restore pluggable database pdb01; 
Finished restore at 11-MAY-17
RMAN>recover pluggable database pdb01; 
Finished recover at 11-MAY-17
[oracle@12c01 ~]$ sqlplus / as sysdba
SQL> alter pluggable database pdb01 open;
Pluggable database altered.

oracle 12c 多租户 pdb 恢复(单个pdb数据文件、非系统pdb表空间、整个pdb数据库)

标签:name   user   mount   auto   where   target   ati   files   app   

原文地址:http://www.cnblogs.com/andy6/p/6843397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!