1. 程式人生 > >【跟我學oracle18c】第十八天:Multitenant Architecture:2.3 Application root,pdb,Container Maps專項測試(對應例項實踐)

【跟我學oracle18c】第十八天:Multitenant Architecture:2.3 Application root,pdb,Container Maps專項測試(對應例項實踐)

           

             對映表指定元資料鏈接的公共表中的一列,並使用分割槽將不同的應用程式PDBs與不同的列值關聯起來。通過這種方式,當資料沒有在表級別物理分割槽時,容器對映支援在PDB級別分割槽資料。

            下面進行一下實踐活動,昨天匆匆測試,發現oracle18c的online doc中好多用到的使用者、表等都是不存在的,得自己嘗試的建立後,測能測試通過,但是這樣會有個問題,萬一某些小細節與oracle18c的官方測試環境不一致,結果就肯能出現差異,本文就出現差異了,大家實踐後幫忙分析回覆(大家看到的加個關注吧,我也好回訪你們的csdn主頁,互相學習),

例項:

--刪除之前的實驗application container saas_sales_ac

DROP PLUGGABLE DATABASE saas_sales_ac  INCLUDING DATAFILES;

-- Create the application container called saas_sales_ac

-- Create the application container called saas_sales_ac
CREATE PLUGGABLE DATABASE saas_sales_ac AS APPLICATION CONTAINER
  ADMIN USER saas_sales_ac_adm IDENTIFIED BY manager; 

-- Open the application root
ALTER PLUGGABLE DATABASE saas_sales_ac OPEN;


ALTER SESSION SET CONTAINER = saas_sales_ac;

--Create the application  pdbs   並開啟

SQL> CREATE PLUGGABLE DATABASE amer_pdb ADMIN USER amer_pdbadm IDENTIFIED BY amer_pdbadm;
Done

SQL> CREATE PLUGGABLE DATABASE euro_pdb ADMIN USER euro_pdbadm IDENTIFIED BY euro_pdbadm;
Done

SQL>  CREATE PLUGGABLE DATABASE asia_pdb ADMIN USER asia_pdbadm IDENTIFIED BY asia_pdbadm;
Done
SQL> alter pluggable database amer_pdb open;

插接式資料庫已變更。

SQL> alter pluggable database euro_pdb open;

插接式資料庫已變更。

SQL> alter pluggable database asia_pdb open;

-----Example 2-16 Creating a Metadata-Linked Table, Map Table, and Container Map: Part 1

ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN INSTALL '1.0';

CREATE USER saas_sales_adm IDENTIFIED BY manager CONTAINER=ALL;

 GRANT CREATE SESSION, DBA TO saas_sales_adm;

 CREATE USER oe IDENTIFIED BY manager CONTAINER=ALL;

GRANT CREATE SESSION, DBA TO oe;

CREATE TABLE oe.countries_mlt SHARING=METADATA (
      region    VARCHAR2(30),
      cname     VARCHAR2(30));

SQL> CREATE TABLE saas_sales_adm.pdb_map_tbl (cname VARCHAR2(30) NOT NULL)
  2    PARTITION BY LIST (cname) (
  3      PARTITION amer_pdb VALUES ('US','MEXICO','CANADA'),
  4      PARTITION euro_pdb VALUES ('UK','FRANCE','GERMANY'),
  5      PARTITION asia_pdb VALUES ('INDIA','CHINA','JAPAN'));
Table created

ALTER PLUGGABLE DATABASE SET CONTAINER_MAP='saas_sales_adm.pdb_map_tbl';

SQL> ALTER TABLE oe.countries_mlt ENABLE CONTAINER_MAP;
Table altered

SQL> ALTER TABLE oe.countries_mlt ENABLE CONTAINERS_DEFAULT;
Table altered

SQL> ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END INSTALL '1.0';
Done

---Example 2-17 Synchronizing the Application, and Adding Data: Part 2

SQL> ALTER SESSION SET CONTAINER=amer_pdb;
Session altered

SQL> ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app SYNC;
Done

SQL> 
SQL> INSERT INTO oe.countries_mlt VALUES ('AMER','US');
1 row inserted
SQL> INSERT INTO oe.countries_mlt VALUES ('AMER','MEXICO');
1 row inserted
SQL> INSERT INTO oe.countries_mlt VALUES ('AMER','CANADA');
1 row inserted
SQL> COMMIT;
Commit complete

SQL> 
SQL> ALTER SESSION SET CONTAINER=euro_pdb;
Session altered
SQL> ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app SYNC;
Done
SQL> INSERT INTO oe.countries_mlt VALUES ('EURO','UK');
1 row inserted
SQL> INSERT INTO oe.countries_mlt VALUES ('EURO','FRANCE');
1 row inserted
SQL> INSERT INTO oe.countries_mlt VALUES ('EURO','GERMANY');
1 row inserted
SQL> COMMIT;
Commit complete

SQL> 
SQL> ALTER SESSION SET CONTAINER=asia_pdb;
Session altered
SQL> ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app SYNC;
Done
SQL> INSERT INTO oe.countries_mlt VALUES ('ASIA','INDIA');
1 row inserted
SQL> INSERT INTO oe.countries_mlt VALUES ('ASIA','CHINA');
1 row inserted
SQL> INSERT INTO oe.countries_mlt VALUES ('ASIA','JAPAN');
1 row inserted
SQL> COMMIT;
Commit complete

結果測試

SQL> ALTER SESSION SET CONTAINER=asia_pdb;
Session altered

SQL>  SELECT region FROM oe.countries_mlt;
REGION
------------------------------
ASIA
ASIA
ASIA

SQL> ALTER SESSION SET CONTAINER=euro_pdb;
Session altered

SQL>  SELECT region FROM oe.countries_mlt;
REGION
------------------------------
EURO
EURO
EURO

SQL> ALTER SESSION SET CONTAINER=saas_sales_ac;
Session altered

SQL> SELECT region FROM oe.countries_mlt;
REGION
------------------------------

SQL> SELECT region FROM oe.countries_mlt WHERE cname='MEXICO';
REGION
------------------------------

SQL> SELECT region FROM containers(oe.countries_mlt);
REGION
------------------------------

發現有問題:

1、application root中查詢怎麼是空記錄,與文章預期不符。

大家幫忙分析一下,你們有出來結果的本文回覆一下,謝謝

一些錯誤程式碼的分析:

1、ALTER PLUGGABLE DATABASE SET CONTAINER_MAP='saas_sales_adm.pdb_map_tbl'
ORA-65291: 無效的容器對映物件

原因:你沒建立application pdbs造成的,因為map內部的pdbs不存在,所以肯定是無效的

2、CREATE TABLE appadm.countries_mlt SHARING=METADATA (
  region    VARCHAR2(30),
  cname     VARCHAR2(30))
ORA-65293: 隱式使用者不能擁有公用物件。

分析:appadm是在application root下建立的common使用者,在

ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN INSTALL '1.0';

內部建立application  user就可以了

3、CREATE TABLE appadm.countries_mlt SHARING=METADATA (
  region    VARCHAR2(30),
  cname     VARCHAR2(30))
ORA-65021: SHARING 子句的使用非法

分析:

在ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN INSTALL '1.0';內部建立即可

4、CREATE PLUGGABLE DATABASE app01 ADMIN USER appadm IDENTIFIED BY manager
ORA-65001: 缺少管理使用者名稱或管理使用者名稱無效

原因:appadm是已經存在的common使用者