【跟我學oracle18c】第十八天:Multitenant Architecture:2.3 Overview of Applications in an Application Container
2.3 Overview of Applications in an Application Container
在應用程式容器中,應用程式是儲存在應用程式root中的命名的、版本化的公共資料和元資料集.
在應用程式容器的上下文中,術語“應用程式”指的是“主應用程式定義”。例如,應用程式可能包括表、檢視和包的定義.
This section contains the following topics:
- About Application Containers
An application container is an optional, user-created CDB component that stores data and metadata for one or more application back ends. A CDB includes zero or more application containers. - Application Common Objects
An application common object is a common object created within an application in an application root. Common objects are either data-linked or metadata-linked. - Application Maintenance
In this context, application maintenance refers to installing, uninstalling, upgrading, or patching an application. - Migration of an Existing Application
You can migrate an application that is installed in a PDB to either an application root or to an application PDB. - Implicitly Created Applications
In addition to user-created applications, application containers can also contain implicitly created applications. - Application Synchronization
Within an application PDB, synchronization is the user-initiated update of the application to the latest version and patch in the application root. - Container Maps
A container map enables a session connected to application root to issue SQL statements that are routed to the appropriate PDB, depending on the value of a predicate used in the SQL statement.
See Also:
-
"Overview of Common and Local Objects in a CDB" to learn about application common objects
Parent topic: Overview of the Multitenant Architecture
2.3.1 About Application Containers
應用程式容器是一個可選的、使用者建立的CDB元件,用於為一個或多個應用程式後端儲存資料和元資料。一個CDB包含零個或多個應用程式容器.
例如,您可以在一個應用程式容器中建立多個與銷售相關的PDBs,這些PDBs共享由一組公共表和表定義組成的應用程式後端。您可以在一個單獨的應用程式容器中儲存多個與hr相關的PDBs,並使用它們自己的公共表和表定義.
帶有AS APPLICATION container子句的CREATE PLUGGABLE資料庫語句建立應用程式容器的應用程式根,從而隱式地建立應用程式容器本身。當您第一次建立應用程式容器時,它不包含PDBs。要建立應用程式PDBs,必須連線到應用程式根,然後執行create PLUGGABLE資料庫語句.
在CREATE PLUGGABLE DATABASE語句中,必須指定容器名(與應用程式根名稱相同),例如saas_sales_ac。應用程式容器名稱必須在CDB內是唯一的,並且在所有CDBs的範圍內,這些CDBs的例項是通過特定的偵聽器到達的。每個應用程式容器都有一個與應用程式容器同名的預設服務.
- Purpose of Application Containers
In some ways, an application container functions as an application-specific CDB within a CDB. An application container, like the CDB itself, can include multiple PDBs, and enables these PDBs to share metadata and data. - Application Root
An application container has exactly one application root, which is the parent of the application PDBs in the container. - Application PDBs
An application PDB is a PDB that resides in an application container. Every PDB in a CDB resides in either zero or one application containers. - Application Seed
An application seed is an optional, user-created PDB within an application container. An application container has either zero or one application seed.
See Also:
Parent topic: Overview of Applications in an Application Container
2.3.1.1 Purpose of Application Containers
在某種程度上,應用程式容器在CDB中充當特定於應用程式的CDB。一個應用程式容器,像CDB本身一樣,可以包含多個PDBs,並允許這些PDBs共享元資料和資料.
應用程式根允許應用程式PDBs共享應用程式,在此上下文中,這意味著一組命名的、版本化的公共元資料和資料。典型的應用程式安裝應用程式公共使用者、元資料鏈接公共物件和資料鏈接公共物件.
This section contains the following topics:
- Key Benefits of Application Containers
Application containers provide several benefits over storing each application in a separate PDB. - Application Container Use Case: SaaS
A SaaS deployment can use multiple application PDBs, each for a separate customer, that share metadata and data. - Application Containers Use Case: Logical Data Warehouse
A customer can use multiple application PDBs to address data sovereignty issues.
Parent topic: About Application Containers
2.3.1.1.1 核心利益of Application Containers
與將每個應用程式儲存在單獨的PDB中相比,應用程式容器提供了一些好處.
-
應用程式根儲存所有應用程式PDBs可以共享的元資料和資料.
例如,所有應用程式PDBs都可以在中心表中共享資料,例如列出預設應用程式角色的表。此外,所有PDBs都可以共享一個表定義,並向其新增特定於pdb的行.
-
在應用程式根中維護主應用程式定義,而不是在每個PDB中維護單獨的副本.
如果您在應用程式根目錄中升級應用程式,那麼更改將自動傳播到所有應用程式PDBs。應用程式後端可能包含資料鏈接的公共物件app_roles,這是一個表,列出預設角色:admin、manager、sales_rep等等。連線到任何應用程式PDB的使用者都可以查詢這個表.
-
應用程式容器可以包括應用程式種子、應用程式PDBs和代理PDBs(在其他CDBs中引用PDBs)。
-
您可以從應用程式種子快速建立新的應用程式PDBs。
-
您可以查詢報告應用程式容器中所有PDBs的檢視。
-
在連線到應用程式根目錄時,可以使用容器函式對多個PDBs中的物件執行DML。
例如,如果products表存在於每個應用程式PDB中,那麼您可以使用一個SELECTstatement連線到應用程式根並查詢所有應用程式PDBs中的產品。 -
您可以從應用程式根目錄下拔下PDB,然後在更高的Oracle資料庫版本中將其插入到應用程式根目錄中。因此,PDBs在Oracle資料庫升級中非常有用。
See Also:
"Overview of Applications in an Application Container"
Parent topic: Purpose of Application Containers
2.3.1.1.2 Application Container使用案例: SaaS
SaaS部署可以使用多個應用程式PDBs,每個PDBs用於單獨的客戶,共享元資料和資料。
在純SaaS環境中,主應用程式定義駐留在應用程式根中,而特定於客戶的資料駐留在其自己的應用程式PDB中。例如,sales_app是應用程式根目錄中的應用程式模型。名為cust1_pdb的應用程式只包含客戶1的銷售資料,而名為cust2_pdb的應用程式只包含客戶2的銷售資料。對於單個客戶PDBs,可以進行插入、斷開、克隆和其他pdb級操作。
Figure 2-8 Saas Use Case
Description of "Figure 2-8 Saas Use Case"
純SaaS配置提供了以下好處:
- 效能
- 安全
-
支援多個客戶
每個客戶的資料駐留在其自己的容器中,但經過整合後,您可以集體管理許多客戶。該模型將管理多個as one的規模經濟擴充套件到應用程式管理員,而不僅僅是DBA。
Parent topic: Purpose of Application Containers
2.3.1.1.3 Application Containers 使用案例: 邏輯資料倉庫
客戶可以使用多個應用程式PDBs來解決資料主權問題。
在一個示例用例中,公司將特定於每個財務季度的資料放在一個單獨的PDB中。例如,名為sales_ac的應用程式容器包括q1_2016_pdb、q2_2016_pdb、q3_2016_pdb和q4_2016_pdb。在對應於相關季度的PDB中定義每個事務。要生成彙總一年效能的報告,可以使用container()子句在四個PDBs之間進行彙總。
這種邏輯倉庫設計的好處包括:
-
特定於單個PDB的資料的ETL不會影響其他PDBs。
-
執行計劃更高效,因為它們基於實際的資料分佈。
Parent topic: Purpose of Application Containers
2.3.1.2 Application Root
應用程式容器只有一個應用程式根,它是容器中應用程式PDBs的父類。
作為應用程式根的屬性是在建立時建立的,不能更改。應用程式根屬於的唯一容器是CDB根。應用程式根在某些方面類似於CDB根,在其他方面類似於PDB:
-
與CDB根一樣,應用程式根充當插入其中的PDBs的父容器。當連線到應用程式根目錄時,您可以管理普通使用者和特權,建立應用程式PDBs,切換容器,併發出應用於應用程式容器中的所有PDBs的DDL
-
與PDB類似,您可以使用create PLUGGABLE資料庫語句建立應用程式根,使用alter PLUGGABLE資料庫更改它,並通過啟動和關閉更改其可用性。可以使用DDL插入、拔掉和刪除應用程式根。應用程式根有自己的服務名稱,使用者可以像連線PDB一樣連線到應用程式根。
應用程式根不同於CDB根和標準PDB,因為它可以儲存使用者建立的公共物件,這些公共物件稱為應用程式公共物件。插入到應用程式根目錄的應用程式PDBs可以訪問應用程式公共物件。對於不屬於應用程式根的CDB根、其他應用程式根或PDBs,應用程式公共物件是不可見的。
See Also:
Example 2-7 Creating an Application Root
在本例中,您以管理公共使用者c##系統的身份登入到CDB根。建立一個名為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;
將當前容器設定為saas_sales_ac,然後驗證該容器是否是應用程式根:
-- Set the current container to saas_sales_ac
ALTER SESSION SET CONTAINER = saas_sales_ac;
COL NAME FORMAT a15
COL ROOT FORMAT a4
SELECT CON_ID, NAME, APPLICATION_ROOT AS ROOT,
APPLICATION_PDB AS PDB,
FROM V$CONTAINERS;
CON_ID NAME ROOT PDB
---------- --------------- ---- ---
3 SAAS_SALES_AC YES NO
Parent topic: About Application Containers
2.3.1.3 Application PDBs
應用程式PDB是駐留在應用程式容器中的PDB。CDB中的每個PDB都駐留在零個或一個應用程式容器中。
例如,saas_sales_ac應用程式容器可能支援多個客戶,每個客戶應用程式將其資料儲存在單獨的PDB中。應用程式PDBs cust1_sales_pdb和cust2_sales_pdb可能駐留在saas_sales_ac中,在這種情況下,它們不屬於其他應用程式容器(儘管作為PDBs,它們也必須屬於CDB根)。
通過在連線到應用程式根目錄時執行Create PLUGGABLE資料庫來建立應用程式PDB。您可以從種子建立應用程式PDB,或者克隆PDB,或者插入一個未插入的PDB。就像插入到CDB根目錄中的PDB一樣,您可以克隆、拔掉或刪除應用程式PDB。然而,應用程式PDB必須始終屬於應用程式根。
See Also:
"Creating and Removing Application Containers and Seeds"
Parent topic: About Application Containers
2.3.1.4 Application Seed
應用程式種子是應用程式容器中使用者建立的可選PDB。一個應用程式容器有0個或1個應用程式種子。
應用程式種子使您能夠快速建立應用程式PDBs。它在應用程式容器中的作用與PDB$SEED在CDB本身中的作用相同。
應用程式種子名總是application_container_name$ seed,其中application_container_name是應用程式容器的名稱。例如,使用CREATE PDB…作為種子語句在saas_sales_ac應用程式容器中建立saas_sales_ac$SEED。
See Also:
"Creating and Removing Application Seeds"
Parent topic: About Application Containers
2.3.2 Application Common Objects
應用程式公共物件是在應用程式根中的應用程式內建立的公共物件。公共物件可以是資料鏈接的,也可以是元資料鏈接的。
對於資料鏈接的公共物件,應用程式PDBs共享一組資料。例如,saas_sales_ac應用程式容器的應用程式名為saas_sales_app,擁有1.0版本,幷包含一個數據連結的usa_zipcodes表。在本例中,行儲存在應用程式根目錄中的表中,但是在所有應用程式PDBs中都是可見的。
對於元資料鏈接的公共物件,應用程式PDBs只共享元資料,但包含不同的資料集。例如,元資料鏈接產品表在每個應用程式PDB中都有相同的定義,但是行本身是特定於PDB的。名為cust1pdb的應用程式可能有一個包含書籍的產品表,而名為cust2pdb的應用程式可能有一個包含汽車零件的產品表。
This section contains the following topics:
- Creation of Application Common Objects
To create common objects, connect to an application root, and then execute aCREATE
statement that specifies a sharing attribute. - Metadata-Linked Application Common Objects
A metadata link is a dictionary object that supports referring to, and granting privileges on, common metadata shared by all PDBs in the application container. - Data-Linked Application Common Objects
A data-linked object is an object whose metadata and data reside in an application root, and are accessible from all application PDBs in this application container. - Extended Data-Linked Application Objects
An extended data-linked object is a hybrid of a data-linked object and metadata-linked object.
See Also:
-
"Overview of Common and Local Objects in a CDB" to learn about common objects
Parent topic: Overview of Applications in an Application Container
2.3.2.1 Creation of Application Common Objects
要建立公共物件,請連線到應用程式根,然後執行一個create語句,該語句指定一個共享屬性。
您只能作為應用程式安裝、升級或補丁的一部分建立或更改應用程式公共物件。您可以通過以下方式指定共享:
-
DEFAULT_SHARING初始化引數
該設定是根中建立的受支援型別的所有資料庫物件的預設共享屬性。
-
SHARING
clause在CREATE語句本身中指定這個子句。當在SQL語句中包含共享子句時,它優先於default_sharinginitial引數中指定的值。可能的值是元資料、資料、擴充套件資料,沒有。
The following table shows the types of application common objects, and where the data and metadata is stored.
Table 2-7 Application Common Objects
Object Type | SHARING Value | Metadata Storage | Data Storage |
---|---|---|---|
Data-Linked | DATA |
Application root | Application root |
Extended Data-Linked | EXTENDED DATA |
Application root | Application root and application PDB |
Metadata-Linked | METADATA |
Application root | Application PDB |
See Also:
-
Oracle Database Security Guide to learn how to manage privileges for common objects
Parent topic: Application Common Objects
2.3.2.2 Metadata-Linked Application Common Objects
元資料鏈接是一個dictionary物件,它支援引用和授予應用程式容器中所有PDBs共享的公共元資料的特權。
在SHARING子句或default_sharinginitialize引數中指定元資料值,指定到物件元資料的連結,稱為元資料鏈接公共物件。物件的元資料在應用程式根中儲存一次。
表、檢視和程式碼物件(例如PL/SQL過程)可以共享元資料。在此上下文中,“元資料”包括列定義、約束、觸發器和程式碼。例如,如果sales_mlt是一個元資料鏈接的公共表,那麼所有應用程式PDBs都通過元資料鏈接訪問這個表的相同定義,該定義儲存在應用程式根目錄中。sales_mlt中的行在每個應用程式PDB中都是不同的,但是列定義是相同的。
通常,應用程式中的大多數物件都是元資料鏈接的。因此,您只需要維護一個主應用程式定義。這種方法將應用程式的管理集中在多個應用程式PDBs中。
Example 2-8 Creating a Metadata-Linked Common Object
在本例中,system使用者登入到saas_sales_ac應用程式容器。在1.0版安裝一個名為saas_sales_app的應用程式(請參閱“應用程式維護”)。這個應用程式建立一個名為saas_sales_adm的公共使用者帳戶。該模式包含一個名為sales_mlt的元資料鏈接公共表。
-- Begin the install of saas_sales_app
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN INSTALL '1.0';
-- Create the tablespace for the app
CREATE TABLESPACE saas_sales_tbs DATAFILE SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE 200M;
-- Create the user account saas_sales_adm, which will own the app
CREATE USER saas_sales_adm IDENTIFIED BY ****** CONTAINER=ALL;
-- Grant necessary privileges to this user account
GRANT CREATE SESSION, DBA TO saas_sales_adm;
-- Makes the tablespace that you just created the default for saas_sales_adm
ALTER USER saas_sales_adm DEFAULT TABLESPACE saas_sales_tbs;
-- Now connect as the application owner
CONNECT saas_sales_adm/******@saas_sales_ac
-- Create a metadata-linked table
CREATE TABLE saas_sales_adm.sales_mlt SHARING=METADATA
(YEAR NUMBER(4),
REGION VARCHAR2(10),
QUARTER VARCHAR2(4),
REVENUE NUMBER);
-- End the application installation
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END INSTALL '1.0';
您可以使用ALTER PLUGGABLE資料庫應用程式…同步語句,以同步應用程式PDBs,以使用相同的主應用程式定義。這樣,每個應用程式PDB都有一個到saas_sales_adm的元資料鏈接。sales_mlt常見的表。在名為cust1_pdb的PDB中更新sales_mlt的中間層程式碼在cust1_pdb中向這個表新增行,而在cust2_pdb中更新sales_mlt的中間層程式碼在cust2_pdb中向這個表的副本新增行。只有儲存在應用程式根目錄中的表元資料是共享的。
(執行報錯啊:ORA-65021: SHARING 子句的使用非法,ORA-65295: 服務名稱或模組名稱不匹配?
我是這麼處理的:
ORA-65021: SHARING 子句的使用非法
檢查了預設的初始化引數show parameter DEFAULT_SHARING=metadata 報錯那就不加了,可以過去
ORA-65295: 服務名稱或模組名稱不匹配(在END INSTALL '1.0'時出現)
在執行這個語句之前切換到system/@saas_sales_ac 下即可,這個應該是oracle18c文件一處bug,要麼就是人家執行環境與我不一樣,大家遇到注意一下
但是下面的Example 2-11 完全正常
)
Note:
-
Oracle Database Security Guide to learn more about how commonly granted object privileges work
- Metadata Links
For metadata-linked application common objects, the metadata for the object is stored once in the application root. A metadata link is a dictionary object whose object type is the same as the metadata it is sharing.
Parent topic: Application Common Objects
2.3.2.2.1 Metadata Links
對於元資料鏈接的應用程式公共物件,物件的元資料在應用程式根中儲存一次。元資料鏈接是一個字典物件,其物件型別與其共享的元資料相同。
元資料鏈接的描述儲存在建立它的PDB的資料字典中。元資料鏈接必須由應用程式公共使用者擁有。您只能使用元資料鏈接在CDB根或應用程式根中共享其建立者擁有的公共物件的元資料。
與資料鏈接不同,元資料鏈接僅依賴於公共資料。例如,如果應用程式在應用程式根目錄中包含本地表dow_close_lt和nasdaq_close_lt,那麼普通使用者就不能建立到這些物件的元資料鏈接。但是,名為sales_mlt的應用程式公共表可能是元資料鏈接的。
例如,如果有特權的普通使用者更改sales_mlt的元資料,則向表中新增一列,然後將此更改傳播到元資料鏈接。應用程式PDB使用者可能不會更改元資料鏈接中的元資料。例如,管理名為cust1_pdb的應用程式PDB的DBA不能僅在此PDB中向sales_mlt新增列:這種元資料更改只能在應用程式根中進行。
See Also:
"About Application Common Objects"
Parent topic: Metadata-Linked Application Common Objects
2.3.2.3 Data-Linked Application Common Objects
資料鏈接物件是一個物件,其元資料和資料駐留在應用程式根中,可以從這個應用程式容器中的所有應用程式PDBs訪問。
在SHARING子句或DEFAULT_SHARING初始化引數中指定到一個公共物件(稱為資料鏈接公共物件)的連結。資料倉庫中的維度表通常是資料鏈接公共表的理想選擇。
資料鏈接是一個字典物件,其功能很像同義詞。例如,如果國家是一個應用程式公共表,那麼所有應用程式PDBs都通過資料鏈接訪問這個表的相同副本。如果將一行新增到這個表中,那麼這一行在所有應用程式PDBs中都是可見的。
資料鏈接必須由應用程式公共使用者擁有。連結從它指向的物件繼承物件型別。資料鏈接的描述儲存在建立資料鏈接的PDB字典中。例如,如果一個應用程式容器包含10個應用程式PDBs,如果每個PDB包含一個到country應用程式公共表的連結,那麼所有10個PDBs都包含此連結的字典定義。
Example 2-9 Creating a Data-Linked Object
在本例中,system連線到saas_sales_ac應用程式容器。系統將名為saas_sales_app的應用程式從1.0版本升級到2.0版本。這個應用程序升級以公共使用者saas_sales_adm的身份登入到容器中,建立一個名為countryes_dlt的資料鏈接表,然後將行插入其中。
-- Begin an upgrade of the application
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN UPGRADE '1.0' to '2.0';
-- Connect as application owner to application root
CONNECT saas_sales_adm/[email protected]_sales_ac
-- Create data-linked table named countries_dlt
CREATE TABLE countries_dlt SHARING=DATA
(country_id NUMBER,
country_name VARCHAR2(20));
-- Insert records into countries_dlt
INSERT INTO countries_dlt VALUES(1, 'USA');
INSERT INTO countries_dlt VALUES(44, 'UK');
INSERT INTO countries_dlt VALUES(86, 'China');
INSERT INTO countries_dlt VALUES(91, 'India');
-- End application upgrade
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END UPGRADE TO '2.0';
使用ALTER PLUGGABLE DATABASE APPLICATION ... SYNC
將應用程式PDBs與應用程式根同步(請參閱“應用程式同步”)。這樣,每個同步應用程式PDB都有一個到saas_sales_adm的資料鏈接。countries_dlt資料表。
Note:
"About Application Common Objects"
Parent topic: Application Common Objects
2.3.2.4 Extended Data-Linked Application Objects
擴充套件資料鏈接物件是資料鏈接物件和元資料鏈接物件的混合。
在擴充套件的資料鏈接物件中,儲存在應用程式根中的資料對於所有應用程式PDBs是通用的,所有PDBs都可以訪問該資料。但是,每個應用程式PDB都可以建立自己的特定於PDB的資料,同時在應用程式根中共享公共資料。因此,PDBs用自己的資料補充了公共資料。
例如,銷售應用程式可能支援多個應用程式PDBs。所有的應用程式PDBs都需要美國的郵政編碼。在這種情況下,可以在應用程式根目錄中建立zipcodes_edt擴充套件資料鏈接表。應用程式根儲存美國郵政編碼,因此所有應用程式PDBs都可以訪問它們。然而,一個應用程式PDB需要美國和加拿大的郵政編碼。這個應用程式PDB可以將加拿大的郵政編碼儲存在應用程式PDB中的擴充套件資料鏈接物件中,而不是儲存在應用程式根中。
通過連線到應用程式根並在Create語句中指定SHARING= extended DATA關鍵字,建立一個擴充套件資料鏈接物件。
Example 2-10 Creating an Extended-Data Object
在本例中,system連線到saas_sales_ac應用程式容器,然後將名為saas_sales_app(在“示例2-8”中建立)的應用程式從2.0版本升級到3.0版本。這個應用程式以公共使用者saas_sales_adm的身份登入到容器中,建立一個名為zipcodes_edt的擴充套件資料鏈接表,然後將行插入其中。
-- Begin an upgrade of the app
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN UPGRADE '2.0' to '3.0';
-- Connect as app owner to app root
CONNECT saas_sales_adm/[email protected]_sales_ac
-- Create a common-data table named zipcodes_edt
CREATE TABLE zipcodes_edt SHARING=EXTENDED DATA
(code VARCHAR2(5),
country_id NUMBER,
region VARCHAR2(10));
-- Load rows into zipcodes_edt
INSERT INTO zipcodes_edt VALUES ('08820','1','East');
INSERT INTO zipcodes_edt VALUES ('10005','1','East');
INSERT INTO zipcodes_edt VALUES ('44332','1','North');
INSERT INTO zipcodes_edt VALUES ('94065','1','West');
INSERT INTO zipcodes_edt VALUES ('73301','1','South');
COMMIT;
-- End app upgrade
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END UPGRADE TO '3.0';
Use the ALTER PLUGGABLE DATABASE APPLICATION ... SYNC
語句將應用程式PDBs與應用程式同步(請參閱“應用程式同步”)。這樣,每個同步應用程式PDB都有一個到saas_sales_adm的資料鏈接。zipcodes_edt資料表。連線到這些PDBs的應用程式可以看到在應用程序升級期間插入到zipcodes_edt中的zip程式碼,但也可以將它們自己的zip程式碼插入到這個表中。
Note:
"About Application Common Objects"
Parent topic: Application Common Objects
2.3.3
- 應用維護
在這種情況下,應用程式維護是指安裝、解除安裝、升級或修補應用程式。
應用程式必須有名稱和版本號。屬性的組合決定了您可以執行哪些維護操作。在所有維護操作中,執行以下步驟:
-
首先執行
ALTER PLUGGABLE DATABASE ... APPLICATION
statement with theBEGIN INSTALL
,BEGIN UPGRADE
, orBEGIN PATCH
clauses. -
執行語句以修改應用程式.
-
結束通過執行the
ALTER PLUGGABLE DATABASE ... APPLICATION
statement with theEND INSTALL
,END UPGRADE
, orEND PATCH
clauses.
隨著應用程式的發展,應用程式容器維護所有版本和補丁更改。
This section contains the following topics:
Note:
"About Managing Applications in an Application Container"
- About Application Maintenance
Perform application installation, upgrade, and patching operations using anALTER PLUGGABLE DATABASE APPLICATION
statement. - Application Installation
An application installation is the initial creation of a master application definition. A typical installation creates user accounts, tables, and PL/SQL packages. - Application Upgrade
An application upgrade is a major change to an installed application. - Application Patch
An application patch is a minor change to an application.
Parent topic: Overview of Applications in an Application Container
2.3.3.1 關於應用程式維護
使用ALTER PLUGGABLE資料庫應用程式語句執行應用程式安裝、升級和補丁操作。
應用程式維護的基本步驟如下:
-
登入到應用程式根目錄。
-
Begin the operation with an
ALTER PLUGGABLE DATABASE APPLICATION ... BEGIN
statement in the application root. -
Execute the application maintenance statements.
-
End the operation with an
ALTER PLUGGABLE DATABASE APPLICATION ... END
statement.
Perform the maintenance using scripts, SQL statements, or GUI tools.
See Also:
"About Managing Applications in an Application Container"
Parent topic: Application Maintenance
2.3.3.2 Application Installation
應用程式安裝是主應用程式定義的初始建立。典型的安裝建立使用者帳戶、表和PL/SQL包。
To install the application, specify the following in the ALTER PLUGGABLE DATABASE APPLICATION
statement:
-
Name of the application
-
Application version number
Example 2-11 Installing an Application
這個示例假設您已登入到名為saas_sales_acas的應用程式容器。這個示例在1.0版安裝了一個名為saas_sales_app的應用程式。注意,使用字串而不是數字指定版本。應用程式建立一個名為saas_sales_adm的應用程式公共使用者,授予必要的特權,然後作為該使用者連線到應用程式根。該使用者建立一個名為sales_mlt的元資料鏈接表。
-- Begin the install of saas_sales_app
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN INSTALL '1.0';
-- Create the tablespace for the app
CREATE TABLESPACE saas_sales_tbs DATAFILE SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE 200M;
-- Create the user account saas_sales_adm, which will own the application
CREATE USER saas_sales_adm IDENTIFIED BY manager CONTAINER=ALL;
-- Grant necessary privileges to this user account
GRANT CREATE SESSION, DBA TO saas_sales_adm;
-- Make the tablespace that you just created the default for saas_sales_adm
ALTER USER saas_sales_adm DEFAULT TABLESPACE saas_sales_tbs;
-- Now connect as the application owner
CONNECT saas_sales_adm/[email protected]_sales_ac
-- Create a metadata-linked table
CREATE TABLE saas_sales_adm.sales_mlt SHARING=METADATA
(YEAR NUMBER(4),
REGION VARCHAR2(10),
QUARTER VARCHAR2(4),
REVENUE NUMBER);
-- End the application installation
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END INSTALL '1.0';
PDB同步是使用者發起的應用程式PDB與應用程式根目錄中的應用程式的更新。在將應用程式PDBs與saas_sales_app應用程式同步之後,每個應用程式PDB將包含一個名為products_mlt的空表。應用程式可以連線到應用程式PDB,然後將特定於PDB的行插入到該表中。
See Also:
Parent topic: Application Maintenance
2.3.3.3 Application Upgrade
應用程序升級是對已安裝應用程式的重大更改。
通常,升級會改變應用程式的物理體系結構。例如,升級可能會新增新的使用者帳戶、表和包,或者更改現有物件的定義。
To upgrade the application, you must specify the following in the ALTER PLUGGABLE DATABASE APPLICATION
statement:
-
Name of the application
-
Old application version number
-
New application version number
Example 2-12 Upgrading an Application Using the Automated Technique
在本例中,您作為管理員連線到應用程式根,然後將應用程式saas_sales_app從1.0版本升級到2.0版本。這個升級建立了一個數據連結表,名為countryes_dlt,然後向它新增行。它還建立一個名為zipcodes_edt的擴充套件資料鏈接表,然後向其新增行。
-- Begin an upgrade of the app
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN UPGRADE '1.0' to '2.0';
-- Connect as app owner to app root
CONNECT saas_sales_adm/[email protected]_sales_ac
-- Create data-linked table named countries_dlt
CREATE TABLE countries_dlt SHARING=DATA
(country_id NUMBER,
country_name VARCHAR2(20));
-- Insert records into countries_dlt
INSERT INTO countries_dlt VALUES(1, 'USA');
INSERT INTO countries_dlt VALUES(44, 'UK');
INSERT INTO countries_dlt VALUES(86, 'China');
INSERT INTO countries_dlt VALUES(91, 'India');
-- Create an extended data-linked table named zipcodes_edt
CREATE TABLE zipcodes_edt SHARING=EXTENDED DATA
(code VARCHAR2(5),
country_id NUMBER,
region VARCHAR2(10));
-- Load rows into zipcodes_edt
INSERT INTO zipcodes_edt VALUES ('08820','1','East');
INSERT INTO zipcodes_edt VALUES ('10005','1','East');
INSERT INTO zipcodes_edt VALUES ('44332','1','North');
INSERT INTO zipcodes_edt VALUES ('94065','1','West');
INSERT INTO zipcodes_edt VALUES ('73301','1','South');
COMMIT;
-- End app upgrade
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END UPGRADE TO '2.0';
This section contains the following topics:
- How an Application Upgrade Works
During an application upgrade, the application remains available. To make this availability possible, Oracle Database clones the application root. - Applications at Different Versions
Different application PDBs might use different versions of the application.
See Also:
"Upgrading Applications in an Application Container"
Parent topic: Application Maintenance
2.3.3.3.1 How an Application Upgrade Works
在應用程序升級期間,應用程式仍然可用。為了使這種可用性成為可能,Oracle資料庫克隆應用程式根。
下圖概述了應用程序升級過程。
Figure 2-9 Application Upgrade
Description of "Figure 2-9 Application Upgrade"
升級過程如下所示:
-
在初始狀態下,應用程式根在特定版本中有一個應用程式。
-
The user executes the
ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADE
statement, and then issues the application upgrade statements.在升級期間,資料庫會自動執行以下操作:
-
克隆應用程式根
For example, if the
saas_sales_app
application is at version 1.0 in the application root, then the clone is also at version 1.0 -
Points the application PDBs to the application root clone
The clone is in read-only mode. The application remains available to the application PDBs.
-
-
The user executes the
ALTER PLUGGABLE DATABASE APPLICATION END UPGRADE
statement.在這個階段,應用程式PDBs仍然指向應用程式根克隆,而原來的應用程式根仍然指向一個新版本。例如,如果saas_sales_app應用程式在應用程式根目錄中處於1.0版本,那麼升級可能會將其帶到2.0版本。然而,應用程式根克隆仍然是1.0版本。
-
Optionally, the user synchronizes the application PDBs with the upgraded application root by issuing
ALTER PLUGGABLE DATABASE APPLICATION
statement with theSYNC
clause.例如,在同步之後,一些應用程式PDBs被插入到2.0版本的應用程式根目錄中。但是,應用程式根克隆繼續支援必須保持在1.0版本上的應用程式PDBs,或任何在1.0版本時插入到應用程式根上的新應用程式PDBs。
See Also:
Parent topic: Application Upgrade
2.3.3.3.2 Applications at Different Versions
不同的應用程式PDBs可能使用不同版本的應用程式。
例如,一個應用程式PDB可能擁有saas_sales_app的1.0版本。在同一個應用程式容器中,另一個應用程式PDB擁有這個應用程式的2.0版本。
用例是提供給不同客戶的SaaS應用程式。如果每個客戶都有自己的應用程式PDB,那麼一些客戶可能會等待更長的時間來升級應用程式。在這種情況下,一些應用程式PDBs可能使用應用程式的最新版本,而其他應用程式PDBs使用的是舊版本。
See Also:
"Upgrading Applications in an Application Container" to learn more about applications at different versions
Parent topic: Application Upgrade
2.3.3.4 Application Patch
應用程式補丁是對應用程式的微小更改。
應用程式補丁的典型例子包括錯誤修復和安全補丁。新的功能和包被允許在一個補丁。
一般來說,破壞性操作是不允許的。例如,一個補丁不能包含dropstatement,或ALTER TABLE語句(刪除列或更改資料型別)。
正如Oracle資料庫補丁程式限制Oracle資料庫補丁程式允許的操作種類一樣,應用程式補丁程式也限制應用程式補丁程式允許的操作。如果一個修復程式包含一個引發“應用程式補丁中不支援的操作”錯誤的操作,那麼執行一個應用程序升級。
Note:
當另一個應用程式補丁或升級正在進行時,您不能對應用程式進行補丁。
要對應用程式進行補丁,請在ALTER PLUGGABLE DATABASE application語句中指定應用程式名稱和補丁號。您可以選擇指定應用程式的最小版本。
示例2-13使用自動技術對應用程式進行修補
在本例中,system登入到應用程式根目錄,然後在1.0或更高版本上對應用程式saas_sales_app進行補丁。補丁101以saas_sales_adm的身份登入到應用程式容器,然後建立一個元資料鏈接的PL/SQL函式,名為get_total_revenue。
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app BEGIN PATCH 101 MINIMUM VERSION '1.0';
-- Connect to the saas_sales_ac container as saas_sales_adm, who owns the application
CONNECT saas_sales_adm/*******@saas_sales_ac
-- Now install the get_total_revenue() function
CREATE FUNCTION get_total_revenue SHARING=METADATA (p_year IN NUMBER)
RETURN SYS_REFCURSOR
AS
c1_cursor SYS_REFCURSOR;
BEGIN
OPEN c1_cursor FOR
SELECT a.year,sum(a.revenue)
FROM containers(sales_data) a
WHERE a.year = p_year
GROUP BY a.year;
RETURN c1_cursor;
END;
/
-- End the patch
ALTER PLUGGABLE DATABASE APPLICATION saas_sales_app END PATCH 101;
懷疑此處是不是表名寫錯了,我改成下邊的表了,因為sales_data沒見過doc裡面提到
FROM containers(sales_mlt) a
See Also:
"Patching Applications in an Application Container"
Parent topic: Application Maintenance
2.3.4 Migration of an Existing Application
您可以將安裝在PDB中的應用程式遷移到應用程式根目錄或應用程式PDB目錄。
遷移已經存在的應用程式的典型原因包括:
-
Applications that use an installation program
有些應用程式使用安裝程式而不是指令碼。在這種情況下,您可以在新的應用程式根中執行安裝程式,然後使用DBMS_PDB_ALTER_SHARING包將物件設定為適當的共享模式:元資料、資料或擴充套件資料。根目錄自動將更改傳播到應用程式PDBs。Oracle資料庫建立安裝的語句日誌,因此可以將具有以前應用程式版本的PDBs插入到應用程式根目錄中。
-
Applications that are defined separately in each PDB
有些應用程式定義在每個PDB中,但不存在應用程式容器。在這種情況下,您可以更新安裝指令碼以設定適當的共享模式。建立一個應用程式根,然後在這個根中建立主應用程式定義。您可以將現有的PDBs作為應用程式PDBs,方法是將它們插入到應用程式根目錄中,然後執行一個SQL指令碼,用對公共定義的引用替換完整的定義。
例如,您可以將安裝在PDB中的應用程式遷移到插入到Oracle資料庫12c CDB中的應用程式容器中,遷移到Oracle資料庫18c CDB中的應用程式容器中。
See Also:
-
"About Managing Applications in an Application Container" to learn how to migrate an existing application
-
Oracle Database PL/SQL Packages and Types Reference to learn more about the
DBMS_PDB_ALTER_SHARING
package
Parent topic: Overview of Applications in an Application Container
2.3.5隱式建立的應用程式
除了使用者建立的應用程式之外,應用程式容器還可以包含隱式建立的應用程式。
當應用程式公共使用者操作使用容器=ALL子句發出時,應用程式將隱式地在應用程式根中建立,而不需要在ALTER PLUGGABLE DATABASE BEGIN語句之前。
應用程式通用使用者操作包括使用CREATE user語句建立通用使用者或使用ALTER user語句更改通用使用者等操作。資料庫自動命名一個隱式應用程式應用程式$guid,其中guid是應用程式根的全域性惟一ID。當第一次開啟應用程式根目錄時,將建立一個隱式應用程式。
See Also:
"Synchronizing Applications in an Application PDB" to learn more about implicitly created applications
Parent topic: Overview of Applications in an Application Container
2.3.6 Application Synchronization
在應用程式PDB中,同步是使用者發起的應用程式到應用程式根目錄中最新版本和補丁的更