您好,登錄后才能下訂單哦!
CDB與PDB是Oracle 12C引入的新特性,在ORACLE 12C數據庫引入的多租用戶環境(Multitenant Environment)中,允許一個數據庫容器(CDB)承載多個可插拔數據庫(PDB)。CDB全稱為ContainerDatabase,中文翻譯為數據庫容器,PDB全稱為Pluggable Database,即可插拔數據庫。在ORACLE 12C之前,實例與數據庫是一對一或多對一關系(RAC):即一個實例只能與一個數據庫相關聯,數據庫可以被多個實例所加載。而實例與數據庫不可能是一對多的關系。當進入ORACLE 12C后,實例與數據庫可以是一對多的關系。
關于CDB與PDB的關系圖
其實大家如果對SQL SERVER比較熟悉的話,這種CDB與PDB是不是感覺和SQL SERVER的單實例多數據庫架構是一回事呢。像PDB$SEED可以看成是master、msdb等系統數據庫,PDBS可以看成用戶創建的數據庫。而可插拔的概念與SQL SERVER中的用戶數據庫的分離、附加其實就是那么一回事。
二、CDB組件(Components of a CDB)
一個CDB數據庫容器包含了下面一些組件:
-ROOT組件
ROOT又叫CDB$ROOT, 存儲著ORACLE提供的元數據和Common User,元數據的一個例子是ORACLE提供的PL/SQL包的源代碼,Common User 是指在每個容器中都存在的用戶。
-SEED組件
Seed又叫PDB$SEED,這個是你創建PDBS數據庫的模板,你不能在Seed中添加或修改一個對象。一個CDB中有且只能有一個Seed. 這個感念,個人感覺非常類似SQL SERVER中的model數據庫。
-PDBS
CDB中可以有一個或多個PDBS,PDBS向后兼容,可以像以前在數據庫中那樣操作PDBS,這里指大多數常規操作。
這些組件中的每一個都可以被稱為一個容器。因此,ROOT(根)是一個容器,Seed(種子)是一個容器,每個PDB是一個容器。每個容器在CDB中都有一個獨一無二的的ID和名稱。
三、具體操作
1.查看數據庫是否為CDB
sqlplus登錄數據庫
[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.查看當前容器
show con_name
SYS@orcl>show con_name; CON_NAME ------------------------------ CDB$ROOT
3.創建一個新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.查看所創建的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.啟動一個創建好的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.關閉PDB
SYS@orcl>alter pluggable database pdb2 close; 插接式數據庫已變更。 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使用傳統的startup和shutdown命令來啟動和關閉PDB
SYS@orcl>alter session set container=pdb2; 會話已更改。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 5 PDB2 MOUNTED SYS@orcl>startup; 插接式數據庫已打開。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 5 PDB2 READ WRITE NO SYS@orcl>shutdown immediate; 插接式數據庫已關閉。 SYS@orcl>show pdbs; CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 5 PDB2 MOUNTED SYS@orcl>alter session set container=CDB$ROOT;
會話已更改。
8.配置監聽文件
監聽文件目錄在$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) ) )
測試登錄
[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. 已使用的參數文件: /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. 上次成功登錄時間: 星期三 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中在啟動數據庫的時候,PDB并不會隨著CDB而啟動。不過我們可以通過創建一個觸發器讓PDB能夠隨CDB啟動。如下:
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; 觸發器已創建 SQL> SHUTDOWN IMMEDIATE 數據庫已經關閉。 已經卸載數據庫。 ORACLE 例程已經關閉。 SQL> STARTUP ORACLE 例程已經啟動。 Total System Global Area 754974720 bytes Fixed Size 2928968 bytes Variable Size 524291768 bytes Database Buffers 222298112 bytes Redo Buffers 5455872 bytes 數據庫裝載完畢。 數據庫已經打開。 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
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。