oracle 12c pdb 恢復

備份數據庫

[oracle@12cr2 ~]$ rman target /

RMAN> backup database;

RMAN> list backup summary;

  1. 數據庫open狀態,系統表空間損壞 -----故障模擬

[oracle@12cr2 ~]$ sqlplus / as sysdba

SQL> alter session set container=PDB4;

SQL> select file_name from dba_data_files;

FILE_NAME

/u01/app/oracle/oradata/zylong/pdb4/pdb4/system01.dbf

/u01/app/oracle/oradata/zylong/pdb4/pdb4/sysaux01.dbf

/u01/app/oracle/oradata/zylong/pdb4/pdb4/undotbs01.dbf

[oracle@12cr2 ~]$ rm /u01/app/oracle/oradata/zylong/pdb4/pdb4/system01.dbf

[oracle@12cr2 ~]$ rm /u01/app/oracle/oradata/zylong/pdb4/pdb4/sysaux01.dbf

[oracle@12cr2 ~]$ sqlplus / as sysdba

ERROR:

ORA-09817: Write to audit file failed.

ORA-01075: you are currently logged on

故障現象

[root@12cr2 opt]# su - oracle

[oracle@12cr2 ~]$ sqlplus / as sysdba

SQL> alter session set container=PDB4;

SQL> select file_name from dba_data_files;

FILE_NAME

/u01/app/oracle/oradata/zylong/pdb4/pdb4/system01.dbf

/u01/app/oracle/oradata/zylong/pdb4/pdb4/sysaux01.dbf

/u01/app/oracle/oradata/zylong/pdb4/pdb4/undotbs01.dbf

SQL> create user test identified by oracle;

create user test identified by oracle

ERROR at line 1:

ORA-00604: error occurred at recursive SQL level 1

ORA-01116: error in opening database file 38

ORA-01110: data file 38:

'/u01/app/oracle/oradata/zylong/pdb4/pdb4/system01.dbf'

ORA-27041: unable to open file

SQL> conn / as sysdba

SQL> alter pluggable database pdb4 close;

Pluggable database altered.

SQL> alter pluggable database pdb4 open;

alter pluggable database pdb4 open

ERROR at line 1:

ORA-01113: file 40 needs media recovery

ORA-01110: data file 40:

'/u01/app/oracle/oradata/zylong/pdb4/pdb4/undotbs01.dbf'

恢復

[oracle@12cr2 ~]$ rman target /

----可以在下一層指定PDB來進行相關操作,也可以在當前指定PDB進行連接:rman target sys/password@hostname:1521/pdb_name,此時恢復跟11G沒多大區別,直接可以restore datafile n,recover datafile n,restore tablespace n,recover tablepace n等等操作。

RMAN> restore tablespace pdb4:system;

RMAN> restore tablespace pdb4:sysaux;

RMAN> recover tablespace pdb4:system;

RMAN> recover tablespace pdb4:sysaux;

RMAN> alter pluggable database pdb4 open;

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of sql statement command at 06/11/2017 21:00:12

ORA-01113: file 40 needs media recovery

ORA-01110: data file 40: '/u01/app/oracle/oradata/zylong/pdb4/pdb4/undotbs01.dbf'

RMAN> recover tablespace pdb4:UNDOTBS1;

RMAN> alter pluggable database pdb4 open;

  1. 數據庫關閉狀態,普通表空間損壞
    模擬故障

SQL> alter pluggable database pdb4 close;

[oracle@12cr2 ~]$ rm /u01/app/oracle/oradata/zylong/pdb4/pdb4/users01.dbf

SQL> alter pluggable database pdb4 open;

alter pluggable database pdb4 open

ERROR at line 1:

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

ORA-01110: data file 41: '/u01/app/oracle/oradata/zylong/pdb4/pdb4/users01.dbf'

恢復

[oracle@12cr2 ~]$ rman target /

RMAN> restore tablespace pdb4:users;

RMAN> alter pluggable database pdb4 open;

RMAN> recover tablespace pdb4:users;

RMAN> alter pluggable database pdb4 open;

  1. 數據庫open狀態,未備份的數據文件恢復
    模擬故障

SQL> create tablespace users datafile '/u01/app/oracle/oradata/zylong/pdb4/pdb4/users01.dbf' size 20M;

SQL> create user test identified by oracle default tablespace users;

SQL> grant dba to test;

SQL> conn test/[email protected]:1521/pdb4

SQL> create table test as select * from all_objects where rownum<100;

SQL> commit;

SQL> !rm /u01/app/oracle/oradata/zylong/pdb4/pdb4/users01.dbf

故障後的現象

SQL> select count(*) from test;

SQL> insert into test select * from test;

SQL> commit;

SQL> insert into test select * from test;

SQL> commit;

SQL> alter system checkpoint;

ERROR at line 1:

ORA-03113: end-of-file on communication channel

SQL> insert into test select * from test;

ORA-03114: not connected to ORACLE

SQL> conn test/[email protected]:1521/pdb4

ORA-01033: ORACLE initialization or shutdown in progress

SQL> conn / as sysdba

SQL> show pdbs;

SQL> alter pluggable database PDB4 open;

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

ORA-01110: data file 41: '/u01/app/oracle/oradata/zylong/pdb4/pdb4/users01.dbf'

恢復

[oracle@12cr2 ~]$ rman target /

RMAN> restore tablespace pdb4:users;

RMAN> recover tablespace pdb4:users;

RMAN> alter pluggable database pdb4 open;

RMAN-00571: ===========================================================

RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============

RMAN-00571: ===========================================================

RMAN-03002: failure of sql statement command at 06/11/2017 21:35:30

ORA-01113: file 40 needs media recovery

ORA-01110: data file 40: '/u01/app/oracle/oradata/zylong/pdb4/pdb4/undotbs01.dbf'

RMAN> recover tablespace pdb4:UNDOTBS1;

RMAN> alter pluggable database pdb4 open;

ORA-01113: file 39 needs media recovery

ORA-01110: data file 39: '/u01/app/oracle/oradata/zylong/pdb4/pdb4/sysaux01.dbf'

RMAN> recover tablespace pdb4:sysaux;

RMAN> alter pluggable database pdb4 open;

ORA-01113: file 38 needs media recovery

ORA-01110: data file 38: '/u01/app/oracle/oradata/zylong/pdb4/pdb4/system01.dbf'

RMAN> recover tablespace pdb4:system;

如果PDB4沒有關閉,可以restore tablespace pdb4:users可能會報錯,可以嘗試執行以下命令在restore:

SQL > alter tablespace users offline immediate;

recover之後online

SQL > alter tablespace users online;

4 單個pdb 數據文件修復

[oracle@12c pdb01]$ rman target sys/password@hostname:1521/pdb_name
RMAN> recover datafile 12;
RMAN-06094: datafile 12 must be restored
RMAN> alter database datafile 12 offline;
RMAN> restore datafile 12;
RMAN> recover datafile 12;
RMAN> alter database datafile 12 online;

5 單個PDB數據庫恢復

-----set until time "TO_DATE('2018-06-03 15:00:00','yyyy-mm-dd hh24:mi:ss')";
-----set until SCN = 180000;
RMAN>restore pluggable database pdb01;
RMAN>recover pluggable database pdb01;
[oracle@12c01 ~]$ sqlplus / as sysdba
SQL> alter pluggable database pdb01 open;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章