Oracle Database 12C 学习之多租户(连载四)
使用克隆現(xiàn)存PDB的方式創(chuàng)建新的PDB:這里有兩種情況,一種為使用本地PDB,另外一種為使用遠程PDB。二者并無太大差異。只是第二種需要使用DBLINK而已。
克隆本地方式:
SYS@ora12g> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORA12C_PDB1 READ WRITE YES4 ORACDB_PDB2 READ WRITE NOSYS@ora12g> alter pluggable database ORA12C_PDB1 close;Pluggable database altered.SYS@ora12g> alter pluggable database ORA12C_PDB1 open read only;Pluggable database altered.SYS@ora12g> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORA12C_PDB1 READ ONLY NO4 ORACDB_PDB2 READ WRITE NO
--我們這里克隆ORA12C_PDB1來創(chuàng)建新的PDB,需要先將其置于read only模式。
SYS@ora12c> alter session set container=ORA12C_PDB1;Session altered.SYS@ora12c> select file_name from dba_data_files;FILE_NAME--------------------------------------------------------------------------------/u01/oracle/oradata/ora12c/ora12c_pdb1/system01.dbf/u01/oracle/oradata/ora12c/ora12c_pdb1/sysaux01.dbf/u01/oracle/oradata/ora12c/ora12c_pdb1/SAMPLE_SCHEMA_users01.dbf/u01/oracle/oradata/ora12c/ora12c_pdb1/example01.dbfSYS@ora12c> create pluggable database ORA12C_PDB2from ORA12c_PDB1file_name_convert = ('/u01/oracle/oradata/ora12c/ora12c_pdb1','/u01/oracle/oradata/ora12c/ora12c_pdb2')storage (MAXSIZE 4G MAX_SHARED_TEMP_SIZE 100M); 2 3 4 5create pluggable database ORA12C_PDB2*ERROR at line 1:ORA-65040: operation not allowed from within a pluggable database
--不能在PDB中復制PDB。
SYS@ora12c> alter session set container=CDB$ROOT;Session altered.SYS@ora12c> create pluggable database ORA12C_PDB2from ORA12C_PDB1file_name_convert = ('/u01/oracle/oradata/ora12c/ora12c_pdb1','/u01/oracle/oradata/ora12c/ora12c_pdb2')storage (MAXSIZE 4G MAX_SHARED_TEMP_SIZE 100M);2 3 4 5Pluggable database created.
--目標PDB的數(shù)據(jù)文件存儲目錄也可以不用事先創(chuàng)建,oracle會自動創(chuàng)建。
--可以在創(chuàng)建PDB的同時指定該PDB的空間使用限額。
SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORA12C_PDB1 READ ONLY NO4 ORACDB_PDB2 READ WRITE NO5 ORA12C_PDB2 MOUNTED
使用遠程PDB創(chuàng)建:
SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORA12C_PDB1 READ ONLY NO4 ORACDB_PDB2 READ WRITE NO5 ORA12C_PDB2 MOUNTEDSYS@ora12c> conn sys/oracle@ORACDB_PDB2 as sysdbaConnected.SYS@ORACDB_PDB2> shutdown immediate;Pluggable Database closed.SYS@ORACDB_PDB2> startup;Pluggable Database opened.SYS@ORACDB_PDB2> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------4 ORACDB_PDB2 READ WRITE NOSYS@ORACDB_PDB2> create user remote_pdb identified by remote;User created.SYS@ORACDB_PDB2> grant create pluggable database to remote_pdb;Grant succeeded.
--在源PDB中創(chuàng)建擁有create PDB權限的用戶。
SYS@ORACDB_PDB2> conn / as sysdbaConnected.SYS@ora12g> create database link dbl_pdb connect to remote_pdb identified by remote using 'ORACDB_PDB2';Database link created.
--我們這里以ORACDB_PDB2作為遠程數(shù)據(jù)庫,也就是創(chuàng)建PDB的源PDB。
--利用前面創(chuàng)建的用戶創(chuàng)建db link。
SYS@ora12c> alter pluggable database ORACDB_PDB2 open read only force;Pluggable database altered.SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORA12C_PDB1 READ ONLY NO4 ORACDB_PDB2 READ ONLY NO5 ORA12C_PDB2 MOUNTED
--同樣將其置于read only狀態(tài)。
SYS@ora12c> create pluggable database ORACDB_PDB_NEWfrom ORACDB_PDB2@dbl_pdbfile_name_convert = ('/u01/oracle/oradata/ora12c/cdb/pdb2','/u01/oracle/oradata/ora12c/cdb/pdb2_new'); 2 3 4Pluggable database created.SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 ORA12G_PDB1 READ ONLY NO4 ORACDB_PDB2 READ ONLY NO5 ORA12C_PDB2 MOUNTED6 ORACDB_PDB_NEW MOUNTED
克隆非CDB的數(shù)據(jù)庫來創(chuàng)建PDB。
這里有三種方法:
1,使用DBMS_PDB包生成源數(shù)據(jù)庫的元數(shù)據(jù),然后再利用create pluggable database語句創(chuàng)建;
2,使用數(shù)據(jù)泵(可傳輸表空間);
3,使用OGG。
使用數(shù)據(jù)泵方式,請參考官方文檔Oracle? Database Utilities 12c?Release 1 (12.1)
使用OGG方式,請參閱OGG相關文檔。
我們這里測試下第一種方式。
1,先創(chuàng)建一個新的非CDB數(shù)據(jù)庫。我們這里用DBCA創(chuàng)建。這步我就不多寫了。各位一路next下去就好。記得別勾選create as a container database即可。
另外需要注意的是,數(shù)據(jù)庫版本必須得是12c或者更高版本。
2,將該數(shù)據(jù)庫以read only模式打開
[oracle@ora12 ~]$ sqlplus / as sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Fri Dec 18 09:56:43 2015Copyright (c) 1982, 2014, Oracle. All rights reserved.Connected to:Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit ProductionWith the Partitioning, OLAP, Advanced Analytics and Real Application Testing optionsSYS@noncdb> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.SYS@noncdb> startup mount;ORACLE instance started.Total System Global Area 838860800 bytesFixed Size 2929936 bytesVariable Size 599788272 bytesDatabase Buffers 230686720 bytesRedo Buffers 5455872 bytesDatabase mounted.SYS@noncdb> alter database open read only;Database altered.
--這里,數(shù)據(jù)庫需要開歸檔才能以read only模式打開,至于原因嘛,恩,各位小伙伴應該都能想的出來吧
3,利用DBMS_PDB包生成該數(shù)據(jù)庫的pdb描述文件并關閉數(shù)據(jù)庫。
SYS@noncdb> begindbms_pdb.describe(pdb_descr_file => '/home/oracle/noncdb.xml');end;/PL/SQL procedure successfully completed.SYS@noncdb>SYS@noncdb> shutdown immediate;Database closed.Database dismounted.ORACLE instance shut down.
--這里生成的pdb描述文件為xml格式的,各位可以進去看一下它的內容。
--該文件中包含了數(shù)據(jù)庫的版本信息,非默認值的初始化參數(shù)信息,表空間及數(shù)據(jù)文件信息,其他可選組件的版本信息,service信息,以及AWR中l(wèi)oadprofile的內容。
4,登陸CDB,檢測要插入的pdb是否存在兼容性問題
SYS@ora12c> set serveroutput ondeclaretest_via boolean;begintest_via := dbms_pdb.check_plug_compatibility(pdb_descr_file => '/home/oracle/noncdb.xml');if test_via thendbms_output.put_line('Yes');elsedbms_output.put_line('No');end if;end;/YesPL/SQL procedure successfully completed.
--輸出結果為yes,表示沒有兼容性問題。
--如果為no,則需要去檢查pdb_plug_in_violations視圖。
5,創(chuàng)建PDB
SYS@ora12c> create pluggable database PDB_NEWusing '/home/oracle/noncdb.xml'copyfile_name_convert = ('/u01/oracle/oradata/noncdb','/u01/oracle/oradata/cdb/pdb_new');Pluggable database created.SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 PDB_NEW MOUNTED
6,執(zhí)行腳本
SYS@ora12c> conn sys/oracle@ora12:1521/PDB_NEW as sysdba;Connected.SYS@ora12:1521/PDB_NEW> @?/rdbms/admin/noncdb_to_pdb.sql;
--該腳本的用處是:更新非CDB的數(shù)據(jù)庫中的數(shù)據(jù)字典表,將其調整為PDB。
執(zhí)行完成之后,該PDB就可以使用了。
需要注意的是:
在執(zhí)行該腳本的時候,建議同時查看alert 日志,因為我的虛擬機只有2G內存,然后新創(chuàng)建的這個數(shù)據(jù)庫noncdb我將其內存設置為了800M。所以在將該數(shù)據(jù)庫創(chuàng)建為PDB時,oracle需要調整其參數(shù)設置。alert 日志中就看到如下類似的內容:
Active Session History (ASH) performed an emergency flush. This may mean that ASH is undersized. If emergency flushes are a recurring issue, you may consider increasing ASH size by setting the value of _ASH_SIZE to a sufficiently large value. Currently, ASH size is 2097152 bytes. Both ASH size and the total number of emergency flushes since instance startup can be monitored by running the following query:select total_size,awr_flush_emergency_count from v$ash_info;以及:
Default pga_aggregate_limit value is too high for theamount of physical memory in the systempga_aggregate_limit is 2048 MBlimit based on physical memory and SGA usage is 1285 MB
因此,在虛擬機上創(chuàng)建新的PDB時,需要考慮內存以及其他比如說磁盤容量等方面的限制。
從CDB中拔出和插入PDB:
SYS@ora12c> create pluggable database PDB12 admin user test_admin identified by test3 file_name_convert = ('/u01/oracle/oradata/ora12c/pdbseed','/u01/oracle/oradata/ora12c/cdb/pdb1');Pluggable database created.SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 PDB1 MOUNTEDSYS@ora12c> alter pluggable database PDB1 open;Pluggable database altered.SYS@ora12c> show pdbs;CON_ID CON_NAME OPEN MODE RESTRICTED---------- ------------------------------ ---------- ----------2 PDB$SEED READ ONLY NO3 PDB1 READ WRITE NOSYS@ora12c> alter pluggable database PDB1 close;Pluggable database altered.
--需要先關閉可插拔數(shù)據(jù)庫,然后再unplug。
SYS@ora12c> alter pluggable database PDB1unplug into '/home/oracle/pdb1.xml';Pluggable database altered.
--需要注意的是,這里只是unplug了,實際上該PDB還存在。如果想重新插入該PDB,則需要先刪除。
SYS@ora12c> drop pluggable database PDB1;Pluggable database dropped.插入PDB的時候,首先需要做兼容性檢查。也就是上篇文章中提到的DBMS_PDB.check_plug_compatibility函數(shù)。
如果沒有問題,再插入。
插入語句跟創(chuàng)建新的PDB一樣
SYS@ora12c> create pluggable database PDB1using '/home/oracle/pdb1.xml'copyfile_name_convert = ('/u01/oracle/oradata/pdb1','/u01/oracle/oradata/cdb/pdb_new');
使用DBCA創(chuàng)建PDB的方式,這里不再多說
本文來自云棲社區(qū)合作伙伴“DBGEEK”
總結
以上是生活随笔為你收集整理的Oracle Database 12C 学习之多租户(连载四)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 工信部:加强中欧在5G、物联网等领域合作
- 下一篇: Linux shell编程学习笔记---