Oracle 12C引入了CDB與PDB的新特性,在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ù)庫是一對一或多對一關(guān)系(RAC):即一個實例只能與一個數(shù)據(jù)庫相關(guān)聯(lián),數(shù)據(jù)庫可以被多個實例所加載。而實例與數(shù)據(jù)庫不可能是一對多的關(guān)系。當(dāng)進(jìn)入ORACLE 12C后,實例與數(shù)據(jù)庫可以是一對多的關(guān)系。下面是官方文檔關(guān)于CDB與PDB的關(guān)系圖。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:申請域名、網(wǎng)頁空間、營銷軟件、網(wǎng)站建設(shè)、耿馬網(wǎng)站維護(hù)、網(wǎng)站推廣。CDB組件(Components of a CDB)
一個CDB數(shù)據(jù)庫容器包含了下面一些組件:
ROOT組件
ROOT又叫CDB$ROOT,存儲著ORACLE提供的元數(shù)據(jù)和Common User,元數(shù)據(jù)的一個例子是ORACLE提供的PL/SQL包的源代碼,Common User是指在每個容器中都存在的用戶。
SEED組件
Seed又叫PDB$SEED,這個是你創(chuàng)建PDBS數(shù)據(jù)庫的模板,你不能在Seed中添加或修改一個對象。一個CDB中有且只能有一個Seed.
PDBS
CDB中可以有一個或多個PDBS,PDBS向后兼容,可以像以前在數(shù)據(jù)庫中那樣操作PDBS,這里指大多數(shù)常規(guī)操作。
這些組件中的每一個都可以被稱為一個容器。因此,ROOT(根)是一個容器,Seed(種子)是一個容器,每個PDB是一個容器。每個容器在CDB中都有一個獨一無二的的ID和名稱。
下面在12.2.0.1上做一些簡單的CDB與PDB和維護(hù)管理示例
1、連接CDB數(shù)據(jù)庫
還是使用sqlplus / as sysdba來連接,中之前的版本一樣
[oracle@t13s admin]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Wed Mar 15 10:39:52 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SYS@testdb>2、查看數(shù)據(jù)庫是否為CDB
SYS@testdb> select cdb from v$database; CDB --- YES如果為YES則為CDB如果為NO則為非CDB
3、查看當(dāng)前的容器
SYS@testdb> show con_name CON_NAME ------------------------------ CDB$ROOT此時連接的是root所以顯示為CDB$ROOT,如果連接PDB則顯示的是PDB的實例名
4、查看PDB的信息
--1 SYS@testdb> select con_id,dbid,guid,name,open_mode from v$pdbs; CON_ID DBID GUID NAME OPEN_MODE ---------- ---------- -------------------------------- -------------------------------------------------- ---------- 2 172801168 4AAD025C72A1F4B0E05358E8FF0AAC40 PDB$SEED READ ONLY --2 SYS@testdb> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO現(xiàn)在還沒有創(chuàng)建PDB,所以只有一個PDB$SEED。
5、創(chuàng)建和刪除PDB
使用CREATE PLUGGABLE DATABASE可以從SEED來創(chuàng)建一個PDB。當(dāng)前的容器必須是CDB root。
SYS@testdb> show con_name CON_NAME ------------------------------ CDB$ROOT SYS@testdb> CREATE PLUGGABLE DATABASE test_pdb ADMIN USER testadm IDENTIFIED BY "rF" ROLES=(CONNECT) file_name_convert=('/data/oradata/testdb/pdbseed','/data/oradata/testdb/test_pdb') path_prefix='/data/oradata/testdb/test_pdb'; Pluggable database created. SYS@testdb> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 TEST_PDB MOUNTED使用DROP PLUGGABLE DATABASE來刪除PDB
drop pluggable database test_pdb including datafiles;6、啟動和關(guān)閉PDB
--啟動 SYS@testdb> alter pluggable database test_pdb open; Pluggable database altered. SYS@testdb> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 TEST_PDB READ WRITE NO --關(guān)閉 SYS@testdb> alter pluggable database test_pdb close; Pluggable database altered. SYS@testdb> show pdbs CON_ID CON_NAME OPEN MODE RESTRICTED ---------- ------------------------------ ---------- ---------- 2 PDB$SEED READ ONLY NO 3 TEST_PDB MOUNTED7、容器間的切換
SYS@testdb> alter session set container=test_pdb; Session altered. SYS@testdb> show con_name CON_NAME ------------------------------ TEST_PDB8、使用sql*plus直接連接PDB
查看監(jiān)聽,了解PDB是如何注冊的
[oracle@t13s admin]$ lsnrctl status LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 15-MAR-2017 11:23:01 Copyright (c) 1991, 2016, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=bossett13s)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production Start Date 15-MAR-2017 09:35:52 Uptime 0 days 1 hr. 47 min. 10 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /oracle/app/oracle/product/12.2/db/network/admin/listener.ora Listener Log File /oracle/app/oracle/diag/tnslsnr/bossett13s/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=bossett13s)(PORT=1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) Services Summary... Service "4abd62d724202b74e05358e8ff0a94fe" has 1 instance(s). Instance "testdb", status READY, has 1 handler(s) for this service... Service "test_pdb" has 1 instance(s). Instance "testdb", status READY, has 1 handler(s) for this service... Service "testdb" has 1 instance(s). Instance "testdb", status READY, has 1 handler(s) for this service... Service "testdbXDB" has 1 instance(s). Instance "testdb", status READY, has 1 handler(s) for this service... The command completed successfully需要配置tns
test_pdb = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.255.232.88)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = test_pdb) ) )連接
[oracle@t13s admin]$ sqlplus testadm/rF@test_pdb SQL*Plus: Release 12.2.0.1.0 Production on Wed Mar 15 11:30:21 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production TESTADM@test_pdb>9、PDB中創(chuàng)建表空間
SYS@testdb> alter session set container=test_pdb Session altered. SYS@testdb> create tablespace users datafile '/data/oradata/testdb/test_pdb/users01.dbf' size 200m; Tablespace created. SYS@testdb> select name from v$tablespace; NAME ------------------------------ SYSTEM SYSAUX UNDOTBS1 TEMP USERS10、用戶管理
在cdb中只能創(chuàng)建全局用戶(c##開頭),會在cdb和所有的pdb中創(chuàng)建該用戶(但是pdb中的全局用戶需要另外授權(quán)才能夠在pdb中訪問)。在pdb中只能創(chuàng)建的用戶為本地用戶
SYS@testdb> show con_name CON_NAME ------------------------------ CDB$ROOT SYS@testdb> create user test identified by "abcd"; create user test identified by "abcd" * ERROR at line 1: ORA-65096: invalid common user or role name SYS@testdb> create user c##test identified by "abcd"; User created. SYS@testdb> alter session set container=test_pdb; Session altered. SYS@testdb> create user test identified by "abcd"; User created.參考:http://www.xifenfei.com/2013/05/oracle-12c-pdb-%E7%AE%A1%E7%90%86%E4%BB%8B%E7%BB%8D1.html
http://www.cnblogs.com/kerrycode/p/3386917.html
官方文檔:http://docs.oracle.com/database/122/ADMIN/overview-of-managing-a-multitenant-environment.htm#ADMIN13507
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。