pdb测试:创建、开关、删除
-----------------------
ORACLE12C中提出来CDB和PDB的概念
他们可以分别理解为容器和插件(PDB插入在CDB中)
CDB的管理和传统数据库区别不大
--确认当前cdb
SQL> select name,cdb from v$database;
NAME CDB
--------- ---
ZARADB YES
--查询当前pdb基本信息
col pdb_name for a30
select pdb_id,pdb_name,dbid,status,creation_scn from dba_pdbs;
select con_id,dbid,NAME,OPEN_MODE from v$pdbs;
PDB_ID PDB_NAME DBID STATUS CREATION_SCN
---------- ------------------------------ ---------- ------------- ------------
3 PDB1 3337485269 NORMAL 1909544
2 PDB$SEED 4072348290 NORMAL 1720741
SQL>
CON_ID DBID NAME OPEN_MODE
---------- ---------- ------------------------------ ----------
2 4072348290 PDB$SEED READ ONLY
3 3337485269 PDB1 READ WRITE
--创建pdb
--1直接创建
CREATE PLUGGABLE DATABASE pdb2
ADMIN USER pdb2dba IDENTIFIED BY anbaisheng
STORAGE (MAXSIZE 2G MAX_SHARED_TEMP_SIZE 100M)
DEFAULT TABLESPACE tbs_pdb2 DATAFILE '/opt/oracle/oradata/ZARADB/datafile/pdb2_001.dbf' SIZE 25M AUTOEXTEND ON;
--2以现有pdb为模板创建
--现有pdb必须在read only模式下才能被创建,否则报错
--以pdb1为模板创建pdb2
drop pluggable database pdb2 including datafiles;
alter pluggable database pdb1 close;
alter pluggable database pdb1 open read only;
create pluggable database pdb2
from pdb1
file_name_convert =('/opt/oracle/oradata/ZARADB/E98BEB85B1A80C56E0439A02A8C05841/datafile/','/opt/oracle/oradata/ZARADB/datafile/pdb2');
--打开关闭pdb
alter pluggable database pdb2 close;
alter pluggable database all close;
alter pluggable database pdb2 close immediate;
alter pluggable database pdb2 open;
alter pluggable database all open;
--删除pdb
--与删除表空间类似,可以级联删除数据文件
drop pluggable database pdb2;
drop pluggable database pdb2 including datafiles;
--unplug
--unplug后pdb只能mount不能open
alter pluggable database pdb2 unplug into '/tmp/pdb2.xml';
--unplug后删除pdb,再使用xml文件加回pdb
drop pluggable database pdb2;
create pluggable database pdb2 using '/tmp/pdb2.xml' nocopy;