您好,登錄后才能下訂單哦!
CDB與PDB是Oracle 12C引入的新特性,在ORACLE 12C數據庫引入的多租用戶環境(Multitenant Environment)中,允許一個數據庫容器(CDB)承載多個可插拔數據庫(PDB)。CDB全稱為Container Database,中文翻譯為數據庫容器,PDB全稱為Pluggable Database,即可插拔數據庫。在ORACLE 12C之前,實例與數據庫是一對一或多對一關系(RAC):即一個實例只能與一個數據庫相關聯,數據庫可以被多個實例所加載。而實例與數據庫不可能是一對多的關系。當進入ORACLE 12C后,實例與數據庫可以是一對多的關系。下面為CDB與PDB的關系圖:
一個CDB容器數據庫通常包含CDB$ROOT、PDB$SEED組件:
a. CDB$ROOT存儲著ORACLE提供的元數據和Common User,Common User 是指在每個容器中都存在的用戶,查看:
show con_name;
b.PDB$SEED是創建PDB數據庫的模板。一個CDB中有且只能有一個Seed,查看:
show pdbs
c.PDB可插拔數據庫,CDB中可以有一個或多個PDB,查看:
show pdbs
dbca在創建數據庫的時候,可以選擇是創建容器數據庫還是傳統的數據庫,如下圖選擇為創建CDB:
a.命令create pluggable database創建:
create pluggable database app1 admin user pdba identified by pdba123;
指定路徑創建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創建pdb:
確認:
啟動pdb:
alter pluggable database APP1 open;
c. 克隆pdb數據庫:
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 數據庫,然后執行啟動到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只能通過觸發器實現:
CREATE TRIGGER open_all_pdbs
AFTER STARTUP ON DATABASE
BEGIN
EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN';
END ;
/
刪除觸發器:
drop trigger open_all_pdbs;
oracle12.2之后可以使用save state來保存pdb數據庫的當前狀態。
show pdbs;
alter pluggable database app1 save state;
startup force;
show pdbs;
查看state狀態:
col con_name for a10
select con_name, state from dba_pdb_saved_states;
刪除discard state狀態:
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;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。