Oracle 12C引入了CDB與PDB的新特性,在ORACLE 12C數(shù)據(jù)庫引入的多租用戶環(huán)境(Multitenant Environment)中,允許一個(gè)數(shù)據(jù)庫容器(CDB)承載多個(gè)可插拔數(shù)據(jù)庫(PDB)。CDB全稱為Container Database,中文翻譯為數(shù)據(jù)庫容器,PDB全稱為Pluggable Database,即可插拔數(shù)據(jù)庫。在ORACLE 12C之前,實(shí)例與數(shù)據(jù)庫是一對一或多對一關(guān)系(RAC):即一個(gè)實(shí)例只能與一個(gè)數(shù)據(jù)庫相關(guān)聯(lián),數(shù)據(jù)庫可以被多個(gè)實(shí)例所加載。而實(shí)例與數(shù)據(jù)庫不可能是一對多的關(guān)系。當(dāng)進(jìn)入ORACLE 12C后,實(shí)例與數(shù)據(jù)庫可以是一對多的關(guān)系。下面是官方文檔關(guān)于CDB與PDB的關(guān)系圖。
在大新等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站制作、網(wǎng)站建設(shè) 網(wǎng)站設(shè)計(jì)制作定制網(wǎng)站制作,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),營銷型網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè)公司,大新網(wǎng)站建設(shè)費(fèi)用合理。
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è)對象。一個(gè)CDB中有且只能有一個(gè)Seed.
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和名稱。
下面在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
此時(shí)連接的是root所以顯示為CDB$ROOT,如果連接PDB則顯示的是PDB的實(shí)例名
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,所以只有一個(gè)PDB$SEED。
5、創(chuàng)建和刪除PDB
使用CREATE PLUGGABLE DATABASE可以從SEED來創(chuàng)建一個(gè)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、啟動(dòng)和關(guān)閉PDB
--啟動(dòng) 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 MOUNTED
7、容器間的切換
SYS@testdb> alter session set container=test_pdb; Session altered. SYS@testdb> show con_name CON_NAME ------------------------------ TEST_PDB
8、使用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 USERS
10、用戶管理
在cdb中只能創(chuàng)建全局用戶(c##開頭),會(huì)在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