PDB大致功能描述:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
创建: 用create pluggable database的命令, 用file_name_convert的方式拷贝seed pdb的文件到对应的新pdb的路径下。拷贝的是最基本system和sysaux表空间, 将新建的pdb从mount的状态打开到read write的状态。 建立pdb用户的默认表空间。 拔出: a)用dbca进行拔出有2种生成结果,一种是生成打包文件,一种是生成.xml文件和.DFB文件。 a .1)打包方式: 操作的时候,先close pdb,然后在$ORACLE_HOME\assistants\dbca\templates\<pdb_name>,生成一个xml文件描述pdb原来文件的路径和scn等信息; 将pdb的数据文件复制到$ORACLE_HOME\assistants\dbca\templates\<pdb_name>路径下; 生成一个pdb_info.txt描述本次pdb unplug的相关文件。 将上述3种类型的文件打包成一个gz包。 在cdb中,以drop pluggable database的方式,删除pdb的信息和在物理上删除pdb的数据文件。 a.2)生成.xml和.DFB文件的方式 也是类似,只是不打包成一个gz包,且pdb的多个数据文件也被整合在一个.DFB文件中。最后也删除cdb中关于此pdb的信息。 插入: 如果用dbca,原来打包成gz包的来做plug就非常方便,只要选中gz包,直接plug即可。如果原来是分开文件的方式,也只需根据xml文件和.DFB文件,先restore数据文件,再create pluggable database using xml文件。 克隆: 将pdb至于read only模式,然后利用create pluggable database xxx from xxx...命令进行可克隆。注该方法需要将原pdb至于read only模式。可以常用在测试环境用克隆另外一个类似的环境。 |
PDB手工操作:
a)创建
1 2 3 4 5 6 7 8 9 10 11 |
SQL> CREATE PLUGGABLE DATABASE mypdb1 ADMIN USER pdbadmin IDENTIFIED BY Orac1e_1981 ROLES=(CONNECT) 2 file_name_convert=('E:\ORA12C\APP\ORACLEUSER\ORADATA\ORA12C\PDBSEED','E:\ORA12C\APP\ORACLEUSER\ORADATA\ORA12C\mypdb1'); Pluggable database created. SQL> SQL> alter pluggable database mypdb1 open; Pluggable database altered. SQL> |
b)拔出:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
SQL> ALTER PLUGGABLE DATABASE mypdb1 CLOSE; Pluggable database altered. SQL> SQL> alter pluggable database MYPDB1 unplug into 'E:\ora12c\app\oracleuser\product\12.1.0\dbhome_1\assistants\dbca\templates\ora12c_MYPDB1.xml'; Pluggable database altered. SQL> SQL> host cp -R E:\ora12c\app\oracleuser\oradata\ora12c\mypdb1 E:\ora12c\app\oracleuser\oradata\ora12c\mypdb1_bak SQL> DROP PLUGGABLE DATABASE mypdb1 including datafiles; Pluggable database dropped. SQL> |
c)插入:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SQL> --注:不需要拷贝回去temp tablespace的文件。不然在下一个create pluggable database的时候会报错ORA-01119。 SQL> host cp E:\ora12c\app\oracleuser\oradata\ora12c\mypdb1_bak\*.DBF E:\ora12c\app\oracleuser\oradata\ora12c\mypdb1 SQL> SQL> create pluggable database b_pdb1 using 'E:\ora12c\app\oracleuser\product\12.1.0\dbhome_1\assistants\dbca\templates\ora12c_MYPDB1.xml' nocopy; Pluggable database created. SQL> SQL> alter pluggable database b_pdb1 open; Pluggable database altered. SQL> |
d)克隆:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
SQL> select dbid,name,open_mode from v$pdbs; DBID NAME OPEN_MODE ---------- ------------------------------ ---------- 4039091088 PDB$SEED READ ONLY 2213957720 B_PDB1 READ WRITE 4261134367 MYPDB2 READ WRITE SQL> SQL> SQL> SQL> alter pluggable database mypdb2 close; Pluggable database altered. SQL> alter pluggable database mypdb2 open read only; Pluggable database altered. SQL> create pluggable database b_pdb2 2 from MYPDB2 3 file_name_convert =('E:\ora12c\app\oracleuser\oradata\ora12c\mypdb2','E:\ora12c\app\oracleuser\oradata\ora12c\b_pdb2'); Pluggable database created. SQL> select dbid,name,open_mode from v$pdbs; DBID NAME OPEN_MODE ---------- ------------------------------ ---------- 4039091088 PDB$SEED READ ONLY 2213957720 B_PDB1 READ WRITE 4261134367 MYPDB2 READ ONLY 2540280635 B_PDB2 MOUNTED SQL> alter pluggable database B_PDB2 open; Pluggable database altered. SQL> |
常用检查语句:
1 2 3 4 5 6 7 |
SQL> SELECT sys_context('userenv','con_name') MY_CONTAINER FROM dual; MY_CONTAINER -------------------- CDB$ROOT SQL> |
1 2 3 4 5 6 |
SQL> SHOW con_name CON_NAME ------------------------------ CDB$ROOT SQL> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
SQL> SELECT 2 'DB_NAME: ' ||sys_context('userenv', 'db_name')|| 3 ' / CDB?: ' ||(select cdb from v$database)|| 4 ' / AUTH_ID: ' ||sys_context('userenv', 'authenticated_identity')|| 5 ' / USER: ' ||sys_context('userenv', 'current_user')|| 6 ' / CONTAINER: '||nvl(sys_Context('userenv', 'con_Name'), 'NON-CDB') 7 as "DB DETAILS" 8 FROM DUAL; DB DETAILS ---------------------------------------------------------------------------------------------------- DB_NAME: ora12c / CDB?: YES / AUTH_ID: HE-PC\jijihe / USER: SYS / CONTAINER: CDB$ROOT SQL> SQL> alter session set container=MYPDB2; Session altered. SQL> SELECT 2 'DB_NAME: ' ||sys_context('userenv', 'db_name')|| 3 ' / CDB?: ' ||(select cdb from v$database)|| 4 ' / AUTH_ID: ' ||sys_context('userenv', 'authenticated_identity')|| 5 ' / USER: ' ||sys_context('userenv', 'current_user')|| 6 ' / CONTAINER: '||nvl(sys_Context('userenv', 'con_Name'), 'NON-CDB') 7 as "DB DETAILS" 8 FROM DUAL; DB DETAILS ------------------------------------------------------------------------------------------------ DB_NAME: ora12c / CDB?: YES / AUTH_ID: HE-PC\jijihe / USER: SYS / CONTAINER: MYPDB2 SQL> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
SQL> select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status 2 from v$PDBs v inner join dba_pdbs d 3 using (GUID) 4 order by v.create_scn 5 / NAME OPEN_MODE RESTRICTED STATUS ------------------------------ ---------- --------------- ------------- PDB$SEED READ ONLY NO NORMAL MYPDB1 READ WRITE NO NORMAL MYPDB2 READ WRITE NO NORMAL SQL> alter pluggable database mypdb1 close; Pluggable database altered. SQL> select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status 2 from v$PDBs v inner join dba_pdbs d 3 using (GUID) 4 order by v.create_scn 5 / NAME OPEN_MODE RESTRICTED STATUS ------------------------------ ---------- --------------- ------------- PDB$SEED READ ONLY NO NORMAL MYPDB1 MOUNTED n/a NORMAL MYPDB2 READ WRITE NO NORMAL SQL> alter pluggable database mypdb1 open restricted; Pluggable database altered. SQL> select v.name, v.open_mode, nvl(v.restricted, 'n/a') "RESTRICTED", d.status 2 from v$PDBs v inner join dba_pdbs d 3 using (GUID) 4 order by v.create_scn 5 / NAME OPEN_MODE RESTRICTED STATUS ------------------------------ ---------- --------------- ------------- PDB$SEED READ ONLY NO NORMAL MYPDB1 READ WRITE YES NORMAL MYPDB2 READ WRITE NO NORMAL SQL> |
评:感觉PDB不像什么革命性的技术,只是将数据库至于mount模式后,拷贝数据文件,做成一个备份,然后将此备份plug和unplug。这样的技术,感觉跨平台的迁移不太理想。
另外,由于一个cdb中可以挂多个pdb,资源的分配使用就变得非常重要了,在12c中,估计原来几乎不常用的Resource Manager plan会逐步用起来。
关于redo,由于redo是可以多个pdb共享,因此cdb的管理者可以通过logmnr的方式去挖对应pdb的日志,从dump出来的redo log来看,redo log中含有container id(CON_ID,0为cdb,1为cdb$root, 2为pdb seed,3以上为pdb),pdbid和pxid,至少这些信息可以用于区分不同pdb中的事务。
2条评论
–注:不需要拷贝回去temp tablespace的文件。这个 具体指的什么?
re wangliang: 手工操作是把原来的文件拷贝回去,这时不需要拷贝原来的temp tablespace的文件,只需datafile就可以了。