实验环境:
SQL> select * from v$version;
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production 0
PL/SQL Release 12.2.0.1.0 - Production 0
CORE 12.2.0.1.0 Production
TNS for Linux: Version 12.2.0.1.0 - Production 0
NLSRTL Version 12.2.0.1.0 - Production 0
一、 手工创建 PDB
SQL>SELECT NAME,CDBFROM V$DATABASE;
SQL>show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB01 READ WRITE NO
SQL> alter session set container=pdb$seed;
SQL>
set lin 400;
col name for a60;
select * from v$dbfile;
FILE# NAME CON_ID
---------- ------------------------------------------------------------ ----------
5 /home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_syste 2
m_djsz1z31_.dbf
6 /home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_sysau 2
x_djsz1z2x_.dbf
8 /home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_undot 2
bs1_djsz1z34_.dbf
SQL> create pluggable database pdb02 admin user pdb02 identified by pdb02
file_name_convert=('pdbseed','pdb02');
ORA-65005: missing or invalid file name pattern for file -
/home/oracle/app/oracle/oradata/ANDYCDB/datafile/o1_mf_system_djsz1z31_.dbf
SQL> alter session set db_create_file_dest='/home/oracle/app/oracle/oradata/';
SQL> create pluggable database pdb02 admin user pdb02 identified by pdb02;
Pluggable database created.
说明:使用了OMF格式的文件名,目标库无法使用convert转换,只能配置db_create_file_dest同样对于该PDB使用OMF。
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB01 READ WRITE NO
4 PDB02 MOUNTED
SQL> alter pluggable database pdb02 open;
Pluggable database altered.
二、手工删除 PDB
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB01 READ WRITE NO
4 PDB02 READ WRITE NO
SQL> alter session set container=pdb02;
Session altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/ANDYCDB/ANDYCDB/4F21240B3F45400BE0531019640A46FB
/datafile/o1_mf_system_dk4oy9tr_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/ANDYCDB/4F21240B3F45400BE0531019640A46FB
/datafile/o1_mf_sysaux_dk4oy9xy_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/ANDYCDB/4F21240B3F45400BE0531019640A46FB
/datafile/o1_mf_undotbs1_dk4oy9y1_.dbf
SQL> alter session set container=cdb$root;
Session altered.
drop pdb 方式一:including DATAFILES
SQL> drop pluggable database pdb02 including datafiles;
ERROR at line 1: > 报错说明删除pdb,这个pdb要在 close 状态。
ORA-65025: Pluggable database PDB02 is not closed on all instances.
SQL> alter pluggable database pdb02 close immediate;
Pluggable database altered.
SQL> drop pluggable database pdb02 including datafiles;
Pluggable database dropped.
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB01 READ WRITE NO
[oracle@12c01 ~]cd /home/oracle/app/oracle/oradata/ANDYCDB/ANDYCDB/4F21240B3F45400BE0531019640A46FB/datafile
[oracle@12c01 datafile]$ ll
total 0 > 操作系统层对应的文件也一并删除了
drop pdb 方式二:keep DATAFILES
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 PDB01 READ WRITE NO
SQL> alter session set container=pdb01;
Session altered.
SQL> select name from v$datafile;
NAME
--------------------------------------------------------------------------------
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_system_djszmxhq_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_sysaux_djszmxkb_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_users_djszpsmt_.dbf
/home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafil
e/o1_mf_undo_1_djz4jq1z_.dbf
NAME
--------------------------------------------------------------------------------
SQL> alter session set container=cdb$root;
Session altered.
SQL> alter pluggable database pdb01 close immediate;
Pluggable database altered.
SQL>alter pluggable database pdb01 unplug into '/home/oracle/pdb01.xml';
Pluggable database altered.
SQL> drop pluggable database pdb01 keep datafiles;
Pluggable database dropped.
[oracle@12c01 ~]cd /home/oracle/app/oracle/oradata/ANDYCDB/4ECF8621E3DA38EEE0531019640AA598/datafile
[oracle@12c01 datafile]$ ll
total 775720
-rw-r-----. 1 oracle oinstall 408952832 May 10 18:02 o1_mf_sysaux_djszmxkb_.dbf
-rw-r-----. 1 oracle oinstall 272637952 May 10 18:02 o1_mf_system_djszmxhq_.dbf
-rw-r-----. 1 oracle oinstall 104865792 May 10 18:02 o1_mf_undo_1_djz4jq1z_.dbf > 操作系统层对应的文件没有被删除
-rw-r-----. 1 oracle oinstall 7872512 May 10 18:02 o1_mf_users_djszpsmt_.dbf
说明:在drop PDB的时候,有2种方式 keep DATAFILES 和 including DATAFILES,默认是KEEP