环境:数据库版本 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
实验准备:
1.-- 数据库归档模式
SQL> select name,log_mode from vdatabase;NAMELOGMODE−−−−−−−−−−−−−−−−−−−−−ANDYCDBARCHIVELOG>数据库归档模式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 ~]sqlplussys/oracle@10.219.24.16:1521/pdb01assysdbaSQL>showconnameCONNAME−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−PDB01SQL>selectnamefromvdatafile;
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 vdatafile; 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 ~]sqlplussys/oracle@10.219.24.16:1521/pdb01assysdba−−查询表空间情况SQL>selecttablespacename,statusfromdbatablespaces;TABLESPACENAMESTATUS−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−SYSTEMONLINESYSAUXONLINEUNDOTBS1ONLINETEMPONLINEUSERSONLINEBBBONLINESQL>coltablespacenamefora15colfilenamefora55SELECTtablespacename,fileid,filename,round(bytes/(1024∗1024),0)totalspaceFROMdbadatafileswheretablespacename=′BBB′ORDERBYtablespacename;TABLESPACENAMEFILEIDFILENAMETOTALSPACE−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−BBB13/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb.dbf1BBB14/home/oracle/app/oracle/oradata/andycdb/pdb01/bbb02.dbf1−−模拟表空间损坏[oracle@12cpdb01] pwd
/home/oracle/app/oracle/oradata/andycdb/pdb01
[oracle@12c pdb01]llbbb∗−rw−r−−−−−.1oracleoinstall1056768May1206:42bbb02.dbf−rw−r−−−−−.1oracleoinstall1056768May1206:42bbb.dbf[oracle@12cpdb01] 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]rmantargetsys/oracle@10.219.24.16:1521/pdb01RMAN>altertablespacebbboffline;ORA−27041:unabletoopenfileRMAN>altertablespacebbbofflineimmediate;StatementprocessedRMAN>recovertablespacebbb;RMAN−06094:datafile13mustberestoredRMAN>restoretablespacebbb;Finishedrestoreat12−MAY−17RMAN>recovertablespacebbb;Finishedrecoverat12−MAY−17RMAN>altertablespacebbbonline;Statementprocessed−−模拟业务成功!SQL>createtableandyasselect∗fromallobjectswhererownum>2;Tablecreated.三、单个PDB数据库恢复恢复单个PDB的前提是CDB已经能够正常启动,在CDB启动的情况下在RMAN中采用restorepluggabledatabasepdb名称指定单个PDB数据库进行恢复,如下SQL>showconnameCONNAME−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−PDB01SQL>selectnamefromvdatafile;
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@12c014ECF8621E3DA38EEE0531019640AA598] rm -rf datafile/
SQL> alter system checkpoint;
System altered.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDBSEEDREADONLYNO3PDB01MOUNTEDRMAN>restorepluggabledatabasepdb01;Finishedrestoreat11−MAY−17RMAN>recoverpluggabledatabasepdb01;Finishedrecoverat11−MAY−17[oracle@12c01 ] sqlplus / as sysdba
SQL> alter pluggable database pdb01 open;
Pluggable database altered.