您好,登錄后才能下訂單哦!
CDB與PDB是Oracle 12C引入的新特性,在ORACLE 12C數(shù)據(jù)庫引入的多租用戶環(huán)境(Multitenant Environment)中,允許一個(gè)數(shù)據(jù)庫容器(CDB)承載多個(gè)可插拔數(shù)據(jù)庫(PDB)。CDB全稱為ContainerDatabase,中文翻譯為數(shù)據(jù)庫容器,PDB全稱為Pluggable Database,即可插拔數(shù)據(jù)庫。在ORACLE 12C之前,實(shí)例與數(shù)據(jù)庫是一對(duì)一或多對(duì)一關(guān)系(RAC):即一個(gè)實(shí)例只能與一個(gè)數(shù)據(jù)庫相關(guān)聯(lián),數(shù)據(jù)庫可以被多個(gè)實(shí)例所加載。而實(shí)例與數(shù)據(jù)庫不可能是一對(duì)多的關(guān)系。當(dāng)進(jìn)入ORACLE 12C后,實(shí)例與數(shù)據(jù)庫可以是一對(duì)多的關(guān)系。
關(guān)于CDB與PDB的關(guān)系圖
其實(shí)大家如果對(duì)SQL SERVER比較熟悉的話,這種CDB與PDB是不是感覺和SQL SERVER的單實(shí)例多數(shù)據(jù)庫架構(gòu)是一回事呢。像PDB$SEED可以看成是master、msdb等系統(tǒng)數(shù)據(jù)庫,PDBS可以看成用戶創(chuàng)建的數(shù)據(jù)庫。而可插拔的概念與SQL SERVER中的用戶數(shù)據(jù)庫的分離、附加其實(shí)就是那么一回事。
二、CDB組件(Components of a CDB)
一個(gè)CDB數(shù)據(jù)庫容器包含了下面一些組件:
-ROOT組件
ROOT又叫CDB$ROOT, 存儲(chǔ)著ORACLE提供的元數(shù)據(jù)和Common User,元數(shù)據(jù)的一個(gè)例子是ORACLE提供的PL/SQL包的源代碼,Common User 是指在每個(gè)容器中都存在的用戶。
-SEED組件
Seed又叫PDB$SEED,這個(gè)是你創(chuàng)建PDBS數(shù)據(jù)庫的模板,你不能在Seed中添加或修改一個(gè)對(duì)象。一個(gè)CDB中有且只能有一個(gè)Seed. 這個(gè)感念,個(gè)人感覺非常類似SQL SERVER中的model數(shù)據(jù)庫。
-PDBS
CDB中可以有一個(gè)或多個(gè)PDBS,PDBS向后兼容,可以像以前在數(shù)據(jù)庫中那樣操作PDBS,這里指大多數(shù)常規(guī)操作。
這些組件中的每一個(gè)都可以被稱為一個(gè)容器。因此,ROOT(根)是一個(gè)容器,Seed(種子)是一個(gè)容器,每個(gè)PDB是一個(gè)容器。每個(gè)容器在CDB中都有一個(gè)獨(dú)一無二的的ID和名稱。
三、具體操作
1.查看數(shù)據(jù)庫是否為CDB
sqlplus登錄數(shù)據(jù)庫
[oracle@oracle12C-R2 ~]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on 星期三 6月 14 15:37:13 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. 連接到: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production select name,cdb,open_mode,con_id from v$database; SYSTEM@ORCL>select name,cdb,open_mode,con_id from v$database; NAME CDB OPEN_MODE CON_ID --------- --- -------------------- ---------- ORCL YES READ WRITE 0
2.查看當(dāng)前容器
show con_name
SYS@orcl>show con_name; CON_NAME ------------------------------ CDB$ROOT
3.創(chuàng)建一個(gè)新PDB
create pluggable database pdb1 admin user pdb1 identified by pdb1 file_name_convert=('/u01/app/oracle/oradata/orcl/pdbseed/','/u01/app/oracle/oradata/orcl/pdb1/');
4.查看所創(chuàng)建的PDB;
show pdbs;
SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB MOUNTED 4 PDB1 MOUNTED 5 PDB2 MOUNTED
5.啟動(dòng)一個(gè)創(chuàng)建好的PDB
alter pluggable database pdb1 open;
再次查看
SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB MOUNTED 4 PDB1 READ WRITE NO 5 PDB2 READ WRITE NO
6.關(guān)閉PDB
SYS@orcl>alter pluggable database pdb2 close; 插接式數(shù)據(jù)庫已變更。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB MOUNTED 4 PDB1 READ WRITE NO 5 PDB2 MOUNTED
7.也可以通過sqlplus使用傳統(tǒng)的startup和shutdown命令來啟動(dòng)和關(guān)閉PDB
SYS@orcl>alter session set container=pdb2; 會(huì)話已更改。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 5 PDB2 MOUNTED SYS@orcl>startup; 插接式數(shù)據(jù)庫已打開。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 5 PDB2 READ WRITE NO SYS@orcl>shutdown immediate; 插接式數(shù)據(jù)庫已關(guān)閉。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 5 PDB2 MOUNTED SYS@orcl>alter session set container=CDB$ROOT;
會(huì)話已更改。
8.配置監(jiān)聽文件
監(jiān)聽文件目錄在$ORACLE_HOME/network/admin
[oracle@oracle12C-R2 admin]$ cat listener.ora # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC= (GLOBAL_DBNAME = ORCL) (SID_NAME = ORCL) ) (SID_DESC= (GLOBAL_DBNAME = PDB1) (SID_NAME = PDB1) ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.221.165)(PORT = 1521)) (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) ) ) [oracle@oracle12C-R2 admin]$ cat tnsnames.ora # tnsnames.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. LISTENER_ORCL = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.221.165)(PORT = 1521)) ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.221.165)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) ) PDB1 = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.221.165)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = PDB1) ) )
測(cè)試登錄
[oracle@oracle12C-R2 admin]$ tnsping pdb1 TNS Ping Utility for Linux: Version 12.2.0.1.0 - Production on 14-6月 -2017 16:02:05 Copyright (c) 1997, 2016, Oracle. All rights reserved. 已使用的參數(shù)文件: /u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora 已使用 TNSNAMES 適配器來解析別名 嘗試連接 (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.221.165)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = PDB1))) OK (10 毫秒) [oracle@oracle12C-R2 admin]$ sqlplus pdb1/pdb1@pdb1 SQL*Plus: Release 12.2.0.1.0 Production on 星期三 6月 14 16:02:28 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. 上次成功登錄時(shí)間: 星期三 6月 14 2017 15:51:38 +08:00 連接到: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production PDB1@pdb1> select name from v$datafile where con_id=4 ; NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/orcl/pdb1/system01.dbf /u01/app/oracle/oradata/orcl/pdb1/sysaux01.dbf /u01/app/oracle/oradata/orcl/pdb1/undotbs01.dbf PDB1@pdb1>
9.oracle12C中在啟動(dòng)數(shù)據(jù)庫的時(shí)候,PDB并不會(huì)隨著CDB而啟動(dòng)。不過我們可以通過創(chuàng)建一個(gè)觸發(fā)器讓PDB能夠隨CDB啟動(dòng)。如下:
SQL> SHOW CON_NAME CON_NAME ------------------------------ CDB$ROOT SQL> CREATE OR REPLACE TRIGGER open_pdbs AFTER STARTUP ON DATABASE BEGIN EXECUTE IMMEDIATE 'ALTER PLUGGABLE DATABASE ALL OPEN'; END open_pdbs; 觸發(fā)器已創(chuàng)建 SQL> SHUTDOWN IMMEDIATE 數(shù)據(jù)庫已經(jīng)關(guān)閉。 已經(jīng)卸載數(shù)據(jù)庫。 ORACLE 例程已經(jīng)關(guān)閉。 SQL> STARTUP ORACLE 例程已經(jīng)啟動(dòng)。 Total System Global Area 754974720 bytes Fixed Size 2928968 bytes Variable Size 524291768 bytes Database Buffers 222298112 bytes Redo Buffers 5455872 bytes 數(shù)據(jù)庫裝載完畢。 數(shù)據(jù)庫已經(jīng)打開。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 ORCLPDB READ WRITE NO 4 PDB1 READ WRITE NO 5 PDB2 READ WRITE NO
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。