Oracle 12C引入了CDB與PDB的新特性,在ORACLE 12C數(shù)據(jù)庫(kù)引入的多租用戶(hù)環(huán)境(Multitenant Environment)中,允許一個(gè)數(shù)據(jù)庫(kù)容器(CDB)承載多個(gè)可插拔數(shù)據(jù)庫(kù)(PDB)。CDB全稱(chēng)為Container Database,中文翻譯為數(shù)據(jù)庫(kù)容器,PDB全稱(chēng)為Pluggable Database,即可插拔數(shù)據(jù)庫(kù)。在ORACLE 12C之前,實(shí)例與數(shù)據(jù)庫(kù)是一對(duì)一或多對(duì)一關(guān)系(RAC):即一個(gè)實(shí)例只能與一個(gè)數(shù)據(jù)庫(kù)相關(guān)聯(lián),數(shù)據(jù)庫(kù)可以被多個(gè)實(shí)例所加載。而實(shí)例與數(shù)據(jù)庫(kù)不可能是一對(duì)多的關(guān)系。當(dāng)進(jìn)入ORACLE 12C后,實(shí)例與數(shù)據(jù)庫(kù)可以是一對(duì)多的關(guān)系。下面是官方文檔關(guān)于CDB與PDB的關(guān)系圖。
其實(shí)大家如果對(duì)SQL SERVER比較熟悉的話(huà),這種CDB與PDB是不是感覺(jué)和SQL SERVER的單實(shí)例多數(shù)據(jù)庫(kù)架構(gòu)是一回事呢。像PDB$SEED可以看成是master、msdb等系統(tǒng)數(shù)據(jù)庫(kù),PDBS可以看成用戶(hù)創(chuàng)建的數(shù)據(jù)庫(kù)。而可插拔的概念與SQL SERVER中的用戶(hù)數(shù)據(jù)庫(kù)的分離、附加其實(shí)就是那么一回事。看來(lái)ORACLE也“抄襲”了一把SQL SERVER的概念,只是改頭換面的包裝了一番。
CDB組件(Components of a CDB)
一個(gè)CDB數(shù)據(jù)庫(kù)容器包含了下面一些組件:
ROOT組件
ROOT又叫CDB$ROOT, 存儲(chǔ)著ORACLE提供的元數(shù)據(jù)和Common User,元數(shù)據(jù)的一個(gè)例子是ORACLE提供的PL/SQL包的源代碼,Common User 是指在每個(gè)容器中都存在的用戶(hù)。
SEED組件
Seed又叫PDB$SEED,這個(gè)是你創(chuàng)建PDBS數(shù)據(jù)庫(kù)的模板,你不能在Seed中添加或修改一個(gè)對(duì)象。一個(gè)CDB中有且只能有一個(gè)Seed. 這個(gè)感念,個(gè)人感覺(jué)非常類(lèi)似SQL SERVER中的model數(shù)據(jù)庫(kù)。
PDBS
CDB中可以有一個(gè)或多個(gè)PDBS,PDBS向后兼容,可以像以前在數(shù)據(jù)庫(kù)中那樣操作PDBS,這里指大多數(shù)常規(guī)操作。
這些組件中的每一個(gè)都可以被稱(chēng)為一個(gè)容器。因此,ROOT(根)是一個(gè)容器,Seed(種子)是一個(gè)容器,每個(gè)PDB是一個(gè)容器。每個(gè)容器在CDB中都有一個(gè)獨(dú)一無(wú)二的的ID和名稱(chēng)。
1)連接到CDB數(shù)據(jù)庫(kù)
連接到CDB數(shù)據(jù)庫(kù)容器非常簡(jiǎn)單,跟以前連接數(shù)據(jù)庫(kù)是一樣的
[oracle@get-orasvr02 ~]$ sqlplus / as sysdba SQL*Plus: Release 12.1.0.1.0 Production on Sun Oct 20 23:41:36 2013 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL> [oracle@get-orasvr02 ~]$ sqlplus sys/password as sysdba SQL*Plus: Release 12.1.0.1.0 Production on Sun Oct 20 23:43:17 2013 Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL>
2)查看數(shù)據(jù)庫(kù)是否為CDB
SQL> select name, decode(cdb, 'YES', 'Multitenant Option enabled', 'Regular 12c Database: ') "Multitenant Option" , open_mode, con_id from v$database; NAME Multitenant Option OPEN_MODE CON_ID --------- ----------------------------- -------------------- ---------- EPPS Multitenant Option enabled READ WRITE 0
YES表示該數(shù)據(jù)庫(kù)是CDB,如果是NO表示是NO-CDB(普通數(shù)據(jù)庫(kù))
3)查看當(dāng)前容器(Container)
3.1
SQL> show con_name CON_NAME ------------------------------ CDB$ROOT SQL> 3.2 SQL> select sys_context('userenv', 'con_name') "Container DB" from dual; Container DB ---------------------------------------------------- CDB$ROOT SQL>
4)查看CDB容器中的PDBS信息
查看CDB中有多少個(gè)pluggable database
SQL> select con_id, dbid, guid, name , open_mode from v$pdbs; CON_ID DBID GUID NAME OPEN_MODE ---------- ---------- -------------------------------- ------------------------------ ---------- 2 4071321146 E89E8DA2866E3157E043DE07A8C09238 PDB$SEED READ ONLY 3 1930201447 E89E9418B882350CE043DE07A8C092B6 PDBEPPS MOUNTED SQL>
5)啟動(dòng)PDB數(shù)據(jù)庫(kù)
方式1:
SQL> alter pluggable database PDBEPPS open; Pluggable database altered. SQL> select con_id, dbid, guid, name , open_mode from v$pdbs; CON_ID DBID GUID NAME OPEN_MODE ---------- ---------- -------------------------------- ------------------------------ ---------- 2 4071321146 E89E8DA2866E3157E043DE07A8C09238 PDB$SEED READ ONLY 3 1930201447 E89E9418B882350CE043DE07A8C092B6 PDBEPPS READ WRITE
方式2:
SQL> alter session set container=PDBEPPS; Session altered. SQL> startup Pluggable Database opened. SQL>
6)關(guān)閉PDB數(shù)據(jù)庫(kù)
SQL> alter pluggable database PDBEPPS close;
Pluggable database altered.
SQL> select con_id, dbid, guid, name , open_mode from v$pdbs;
CON_ID DBID GUID NAME OPEN_MODE
---------- ---------- -------------------------------- ------------------------------ ----------
2 4071321146 E89E8DA2866E3157E043DE07A8C09238 PDB$SEED READ ONLY
3 1930201447 E89E9418B882350CE043DE07A8C092B6 PDBEPPS MOUNTED
SQL>
7)在容器間切換
SQL> alter session set container=PDBEPPS;
Session altered.
SQL> show con_name;
CON_NAME
------------------------------
PDBEPPS
SQL>
SQL> alter session set container=CDB$ROOT;
Session altered.
SQL> show con_name;
CON_NAME
------------------------------
CDB$ROOT
SQL>