CDB與PDB是Oracle 12C引入的新特性,在ORACLE 12C數(shù)據(jù)庫引入的多租用戶環(huán)境(Multitenant Environment)中,允許一個數(shù)據(jù)庫容器(CDB)承載多個可插拔數(shù)據(jù)庫(PDB)。CDB全稱為Container Database,中文翻譯為數(shù)據(jù)庫容器,PDB全稱為Pluggable Database,即可插拔數(shù)據(jù)庫。在ORACLE 12C之前,實例與數(shù)據(jù)庫是一對一或多對一關系(RAC):即一個實例只能與一個數(shù)據(jù)庫相關聯(lián),數(shù)據(jù)庫可以被多個實例所加載。而實例與數(shù)據(jù)庫不可能是一對多的關系。當進入ORACLE 12C后,實例與數(shù)據(jù)庫可以是一對多的關系。下面為CDB與PDB的關系圖:
汝南網(wǎng)站建設公司創(chuàng)新互聯(lián)建站,汝南網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為汝南上千余家提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設要多少錢,請找那個售后服務好的汝南做網(wǎng)站的公司定做!
一個CDB容器數(shù)據(jù)庫通常包含CDB$ROOT、PDB$SEED組件:
a. CDB$ROOT存儲著ORACLE提供的元數(shù)據(jù)和Common User,Common User 是指在每個容器中都存在的用戶,查看:
show con_name;
b.PDB$SEED是創(chuàng)建PDB數(shù)據(jù)庫的模板。一個CDB中有且只能有一個Seed,查看:
show pdbs
c.PDB可插拔數(shù)據(jù)庫,CDB中可以有一個或多個PDB,查看:
show pdbs
dbca在創(chuàng)建數(shù)據(jù)庫的時候,可以選擇是創(chuàng)建容器數(shù)據(jù)庫還是傳統(tǒng)的數(shù)據(jù)庫,如下圖選擇為創(chuàng)建CDB:
a.命令create pluggable database創(chuàng)建:
create pluggable database app1 admin user pdba identified by pdba123;
指定路徑創(chuàng)建pdb:
mkdir -p /u01/app/oracle/oradata/prod/data
create pluggable database app1 admin user pdba identified by pdba123 FILE_NAME_CONVERT=('/u01/app/oracle/oradata/prod/pdbseed','/u01/app/oracle/oradata/prod/data');
b.dbca創(chuàng)建pdb:
確認:
啟動pdb:
alter pluggable database APP1 open;
c. 克隆pdb數(shù)據(jù)庫:
alter system set db_create_file_dest='/u01/app/oracle/oradata/prod/';
create pluggable database app3 from app2;
先關閉對應的pdb,然后刪除pdb:
alter pluggable database app3 close immediate;
drop pluggable database app3 including datafiles;
只是刪除庫,不刪除文件:
drop pluggable database app3 keep datafiles;
alter pluggable database app3 unplug into '/home/oracle/app3.xml';
drop pluggable database app3 keep datafiles;
show pdbs
create pluggable database app5 using '/home/oracle/app3.xml' nocopy;
切換到app1 pdb下面:
alter session set container=app1;
切換到CDB容器
alter session set container=CDB$ROOT;???
查看當前屬于哪個容器:
show con_name
select sys_context('USERENV','CON_NAME') from dual;
a. 指定pdb進行關閉和啟動:
alter pluggable database app1 open;
startup pluggable database app1;
啟動到只讀模式,新建的pdb必須啟動一次后才可以設置為read only,否則報
ERROR at line 1:
ORA-65085: cannot open pluggable database in read-only mode:
可以從dba_pdbs視圖進行確認,對于NEW的pdb,需要先open:
SQL> col pdb_name for a10
SQL> select pdb_name,status from dba_pdbs;
PDB_NAME STATUS
---------- ----------
APP1 NORMAL
PDB$SEED NORMAL
APP2 NORMAL
APP3 NORMAL
APP4 NEW
新建一個app3 數(shù)據(jù)庫,然后執(zhí)行啟動到read only:
create pluggable database app3 from app2;
alter pluggable database app3 open read only;
alter pluggable database app3 open read only;
show pdbs;
alter pluggable database app1 close immediate;
b.切換到對應的pdb進行關閉啟動:
alter session set container= app1;?
startup;
alter session set container= app1;
shutdown immediate;
c.集中操作pdb:
開啟所有pdb:
alter pluggable database all open;?
關閉所有pdb:
alter pluggable database all close immediate;
pdb自動啟動:
oracle 12.1和oracle12.2版本,默認情況下PDB不會隨著CDB啟動而啟動,oracle 12.1只能通過觸發(fā)器實現(xiàn):
CREATE TRIGGER open_all_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END ;
/
刪除觸發(fā)器:
drop trigger open_all_pdbs;
oracle12.2之后可以使用save state來保存pdb數(shù)據(jù)庫的當前狀態(tài)。
show pdbs;
alter pluggable database app1 save state;
startup force;
show pdbs;
查看state狀態(tài):
col con_name for a10
select con_name, state from dba_pdb_saved_states;
刪除discard state狀態(tài):
alter pluggable database app1 discard state;
查看所有pdb:
show pdbs
col name for a20
select con_id,dbid,name,open_mode from v$pdbs;
select name,cause ,type,message,status from pdb_plug_in_violations;