日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Oracle Database 12C 学习之多租户(连载四)

發布時間:2025/3/17 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Oracle Database 12C 学习之多租户(连载四) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用克隆現存PDB的方式創建新的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來創建新的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的數據文件存儲目錄也可以不用事先創建,oracle會自動創建。

--可以在創建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創建:

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中創建擁有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作為遠程數據庫,也就是創建PDB的源PDB。

--利用前面創建的用戶創建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狀態。

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的數據庫來創建PDB。

這里有三種方法:

1,使用DBMS_PDB包生成源數據庫的元數據,然后再利用create pluggable database語句創建;

2,使用數據泵(可傳輸表空間);

3,使用OGG。

使用數據泵方式,請參考官方文檔Oracle? Database Utilities 12c?Release 1 (12.1)

使用OGG方式,請參閱OGG相關文檔。

我們這里測試下第一種方式。

1,先創建一個新的非CDB數據庫。我們這里用DBCA創建。這步我就不多寫了。各位一路next下去就好。記得別勾選create as a container database即可。

另外需要注意的是,數據庫版本必須得是12c或者更高版本。

2,將該數據庫以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.

--這里,數據庫需要開歸檔才能以read only模式打開,至于原因嘛,恩,各位小伙伴應該都能想的出來吧

3,利用DBMS_PDB包生成該數據庫的pdb描述文件并關閉數據庫。

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格式的,各位可以進去看一下它的內容。

--該文件中包含了數據庫的版本信息,非默認值的初始化參數信息,表空間及數據文件信息,其他可選組件的版本信息,service信息,以及AWR中loadprofile的內容。

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,創建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,執行腳本

SYS@ora12c> conn sys/oracle@ora12:1521/PDB_NEW as sysdba;Connected.SYS@ora12:1521/PDB_NEW> @?/rdbms/admin/noncdb_to_pdb.sql;

--該腳本的用處是:更新非CDB的數據庫中的數據字典表,將其調整為PDB。

執行完成之后,該PDB就可以使用了。

需要注意的是:

在執行該腳本的時候,建議同時查看alert 日志,因為我的虛擬機只有2G內存,然后新創建的這個數據庫noncdb我將其內存設置為了800M。所以在將該數據庫創建為PDB時,oracle需要調整其參數設置。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

因此,在虛擬機上創建新的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.

--需要先關閉可插拔數據庫,然后再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函數。

如果沒有問題,再插入。

插入語句跟創建新的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創建PDB的方式,這里不再多說

本文來自云棲社區合作伙伴“DBGEEK”

總結

以上是生活随笔為你收集整理的Oracle Database 12C 学习之多租户(连载四)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。