Oracle 12C引入了CDB与PDB的新特性,在ORACLE 12C数据库引入的多租用户环境(Multitenant Environment)中,允许一个数据库容器(CDB)承载多个可插拔数据库(PDB)。CDB全称为Container Database,中文翻译为数据库容器,PDB全称为Pluggable Database,即可插拔数据库。在ORACLE 12C之前,实例与数据库是一对一或多对一关系(RAC):即一个实例只能与一个数据库相关联,数据库可以被多个实例所加载。而实例与数据库不可能是一对多的关系。当进入ORACLE 12C后,实例与数据库可以是一对多的关系。下面是官方文档关于CDB与PDB的关系图。
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.
PDBS
CDB中可以有一个或多个PDBS,PDBS向后兼容,可以像以前在数据库中那样操作PDBS,这里指大多数常规操作。
这些组件中的每一个都可以被称为一个容器。因此,ROOT(根)是一个容器,Seed(种子)是一个容器,每个PDB是一个容器。每个容器在CDB中都有一个独一无二的的ID和名称。
下面在12.2.0.1上做一些简单的CDB与PDB和维护管理示例
1、连接CDB数据库
还是使用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、查看数据库是否为CDB
SYS@testdb> select cdb from v$database; CDB --- YES
如果为YES则为CDB如果为NO则为非CDB
3、查看当前的容器
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
现在还没有创建PDB,所以只有一个PDB$SEED。
5、创建和删除PDB
使用CREATE PLUGGABLE DATABASE可以从SEED来创建一个PDB。当前的容器必须是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、启动和关闭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 --关闭 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
查看监听,了解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中创建表空间
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中只能创建全局用户(c##开头),会在cdb和所有的pdb中创建该用户(但是pdb中的全局用户需要另外授权才能够在pdb中访问)。在pdb中只能创建的用户为本地用户
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
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。