oracle 12c 多租户 pdb 恢复(单个pdb数据文件非系统pdb表空间整个pdb数据库)
Posted 张冲andy
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle 12c 多租户 pdb 恢复(单个pdb数据文件非系统pdb表空间整个pdb数据库)相关的知识,希望对你有一定的参考价值。
环境:数据库版本 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 中创建实验表空间 与 用户
[[email protected] ~]$ sqlplus sys/[email protected]: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
[[email protected] ~]$ mkdir /home/oracle/rmanback/
[[email protected] ~]$ 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方式跳过,然后再打数据库,稍后再对数据文件做恢复:
[[email protected] ~]$ sqlplus sys/[email protected]: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 删除
[[email protected] ~]$ cd /home/oracle/app/oracle/oradata/andycdb/pdb01/
[[email protected] ~]$ mv users01.dbf users01.dbf.bak
-- 模拟业务
C:\Users\andy>sqlplus andy/[email protected]: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 恢复
[[email protected] pdb01]$ rman target sys/[email protected]: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 损坏。
[[email protected] ~]$ sqlplus sys/[email protected]: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
--模拟表空间损坏
[[email protected] pdb01]$ pwd
/home/oracle/app/oracle/oradata/andycdb/pdb01
[[email protected] 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
[[email protected] pdb01]$ rm -rf bbb*
--模拟业务
C:\Users\andy>sqlplus bbb/[email protected]: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 恢复
[[email protected] pdb01]$ rman target sys/[email protected]: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 损坏
[[email protected] datafile]$ cd /home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598
[[email protected] 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
[[email protected] ~]$ sqlplus / as sysdba
SQL> alter pluggable database pdb01 open;
Pluggable database altered.
以上是关于oracle 12c 多租户 pdb 恢复(单个pdb数据文件非系统pdb表空间整个pdb数据库)的主要内容,如果未能解决你的问题,请参考以下文章
Oracle12c多租户如何连接到CDB或PDBCDB与PDB容器切换
Oracle 12c 多租户家族(12c 18c 19c)如何在 PDB 中添加 HR 模式