【跟我学oracle18c】第二十七天:Multitenant :17 管理Application Containers

这部分内容前面已经实践过部分

17 Administering Application Containers

您可以管理应用程序容器,包括应用程序根和应用程序PDBs。您还可以管理安装在应用程序容器中的应用程序。

Note:

You can complete the tasks in this chapter using SQL*Plus or Oracle SQL Developer.

This chapter contains the following topics:

Related Topics

Parent topic: Administering a Multitenant Environment

17.1 About Application Container Administration

管理应用程序容器的某些方面类似于管理CDB根和整个CDB,而管理应用程序容器的其他方面类似于管理PDB。

管理应用程序容器类似于管理CDB,因为您可以同时管理插入到应用程序根中的应用程序根和应用程序PDBs。然而,管理应用程序容器也类似于管理PDB,因为对应用程序容器的更改不会影响CDB中的其他应用程序容器或PDBs。

下表描述了与管理CDB或CDB根目录的管理任务类似的应用程序容器的管理任务。

Table 17-1 Application Container Administrative Tasks Similar to Those of a CDB

Administrative Task Description More Information
配置应用程序常见用户和通常授予的特权

应用程序公共用户和特权类似于公共用户和通常授予的特权 in a CDB root,但是在应用程序容器中,公共用户和通常授予的特权只存在于应用程序容器的容器中,包括应用程序根、属于应用程序根的应用程序PDBs和属于应用程序根的可选应用程序种子。

"Overview of Common and Local Users in a CDB"

创建应用程序容器 当前容器为CDB根的普通用户可以创建插入到CDB根的应用程序容器。为此,请在CREATE PLUGGABLE DATABASEstatement中包含AS APPLICATION CONTAINERclause

"Creating Application Containers"

Creating application PDBs

当前容器为应用程序根的普通用户可以创建插入到应用程序根的应用程序pdb。

"Creating and Removing PDBs and Application Containers"

Switching to containers

具有适当权限的普通用户可以在应用程序容器中的容器之间进行切换,这些容器包括应用程序根、属于应用程序根的应用程序PDBs和属于应用程序根的可选应用程序种子。

"Switching to a Container Using the ALTER SESSION Statement"

Issuing ALTER SYSTEM SETstatements

ALTER SYSTEM SETstatement可以在应用程序容器中的一个或多个容器中动态设置初始化参数。

"Modifying a CDB with ALTER SYSTEM"

Issuing data definition language (DDL) statements

在应用程序容器中,一些DDL语句可以应用于应用程序容器中的所有容器,也可以只应用于当前容器。

"Modifying Application Common Objects with DDL Statements"

下表描述了与管理PDB的管理任务类似的应用程序容器的管理任务。

Table 17-2 Application Container Administrative Tasks Similar to Those of a PDB

Administrative Task Description More Information
连接到应用程序根目录 应用程序根具有自己的服务名称,用户可以以与PDB连接相同的方式连接到应用程序根。类似地,每个应用程序PDB都有自己的服务名称,应用程序种子也有自己的服务名称。

"Accessing a Container in a CDB"

Issuing the ALTER PLUGGABLE DATABASEstatement

ALTER PLUGGABLE数据库语句可以像修改PDB一样修改应用程序根、应用程序PDB和应用程序种子。例如,管理员可以使用ALTER PLUGGABLE DATABASEstatement打开或关闭应用程序根目录。

"Modifying Containers When Connected to the CDB Root"

"Modifying a PDB at the Database Level"

Issuing the SQL*Plus STARTUPand SHUTDOWN commands

SQL*Plus启动和关闭命令对应用程序根、应用程序PDB和应用程序种子的操作方式与对PDB的操作相同。

"Modifying the Open Mode of One or More PDBs"

Issuing the ALTER SYSTEMstatements

ALTER SYSTEMstatement对应用程序根、应用程序PDB和应用程序种子的操作方式与对PDB的操作相同。.

"Modifying a CDB with ALTER SYSTEM"

"Modifying a PDB at the System Level"

Managing tablespaces

管理员可以为应用程序根目录和应用程序PDBs创建、修改和删除表空间。每个容器都有自己的表空间。

"About Managing Tablespaces in a CDB"

Managing data files and temp files

管理员可以为应用程序根目录和应用程序PDBs创建、修改和删除数据文件和临时文件。每个容器都有自己的文件。

Oracle Database Administrator’s Guide for information about managing data files and temp files

Managing schema objects

您可以在应用程序根目录和每个应用程序PDB中以与在PDB中相同的方式创建、修改和删除模式对象。您还可以为特定的应用程序根或应用程序PDB创建触发器。

但是,应用程序容器支持应用程序公共对象,这些对象可以在应用程序容器中的容器之间共享。不能在PDBs中创建应用程序公共对象。

"Managing Application Common Objects"

This section contains the following topics:

Parent topic: Administering Application Containers

17.2 About Modifying an Application Root

ALTER数据库语句可以修改应用程序根目录。ALTER PLUGGABLE DATABASE语句可以修改应用程序PDBs的open模式。
下表列出了ALTER数据库中的子句和应用程序根中发出的ALTER PLUGGABLE数据库语句修改了哪些容器。该表还列出了应用程序根目录中不允许的语句。

Note:

当当前容器是应用程序根时发出的语句不会影响不属于当前应用程序根的CDB根或PDBs。

Table 17-3 Statements That Modify Containers in an Application Root

Modify Application Root Only Modify One or More Application PDBs Cannot Be Issued in an Application Root

当作为当前容器为应用程序根的应用程序通用用户连接时,使用以下子句修改数据库语句以修改应用程序根only:

使用以下子句修改应用程序根目录并为应用程序PDBs设置默认值:

您可以使用这些子句为特定的应用程序PDBs设置非默认值。

当作为当前容器为应用根目录的应用程序公共用户连接时,使用以下子句更改可插拔的DATABASEstatements可以修改一个或多个应用程序PDBs的打开模式:

当当前容器是应用程序PDB时,使用此子句更改可插入数据库estatements可以修改当前应用程序PDB的打开模式。
当作为当前容器为应用根目录的应用程序公共用户连接时,使用以下子句更改可插拔的DATABASEstatements可以在CDB重启时保留或丢弃应用程序PDB的打开模式:

当作为当前容器为应用根目录的应用程序通用用户连接时,不允许使用以下子句修改数据库语句:

See Also:

Parent topic: Administering Application Containers

17.3 Managing Applications in an Application Container

在应用程序容器中安装、升级或修补应用程序。
您还可以从应用程序容器卸载应用程序。在应用程序根目录中执行这些操作。当应用程序PDBs与应用程序根中的应用程序同步时,应用程序容器将应用程序更改传播到应用程序PDBs。

This section contains the following topics:

Related Topics

Parent topic: Administering Application Containers

17.3.1 About Managing Applications in an Application Container

在应用程序容器中,应用程序是一组命名的、版本化的应用程序元数据和公共数据。
在应用程序容器中,应用程序是存储在应用程序根中的应用程序公共对象的命名、版本化集合。在此上下文中,“应用程序”指的是“应用程序后端”。应用程序常见对象包括用户帐户、表、PL/SQL包等。应用程序可以与属于应用程序根目录的应用程序PDBs共享。

您可以在应用程序根目录中安装、升级和修补应用程序。您必须发出一个ALTER PLUGGABLE数据库……BEGIN语句启动操作和ALTER PLUGGABLE数据库…结束语句来结束操作。您可以在相同的用户会话或不同的用户会话中发出这些语句。
当您以这种方式执行应用程序更改时,应用程序PDBs可以与应用程序根中的应用程序同步。应用程序容器还管理应用程序的版本和应用程序的补丁:

  • When you install an application, you must specify the application version number.

  • When you upgrade an application, you must specify the old application version number and the new application version number.

  • When you patch an application, you must specify the minimum application version number for the patch and the patch number.

随着应用程序的发展,应用程序容器将维护应用程序的所有版本和补丁更改。您还可以配置应用程序容器,以便不同的应用程序pdb使用不同的应用程序版本。例如,如果您向不同的客户提供一个应用程序,并且每个客户都有自己的应用程序PDB,那么一些客户可能会等待更长的时间来升级应用程序。在这种情况下,一些应用程序PDBs可以使用应用程序的最新版本,而其他应用程序PDBs可以使用应用程序的旧版本。

The following is the typical process for creating and maintaining an application in an application container:

  1. Create the application container.

  2. Install the application in the application root.

    This step includes creating the application data model and configuring the application common users and application common objects.

  3. Create the application PDBs in the application root.

  4. Synchronize each application PDB that should install the application with the application in the application root.

  5. Load the data for each application PDB.

  6. Maintain the application by upgrading it and patching it in the application root.

  7. Synchronize application PDBs that should apply changes from upgrades and patches.

  8. Add new application PDBs whenever necessary.

Note:

  • SQL*Loader是在应用程序安装、升级和补丁操作期间批量插入表的惟一受支持实用程序。

  • T应用程序模块名由DBMS_APPLICATION_INFO设置。SET_MODULE过程或等效的OCI属性设置。有些子句,例如SHARING子句,只有在在可插入的ALTER DATABASE之间发出时才有效……BEGINstatement和一个ALTER PLUGGABLE数据库…结束声明。对于这些子句,如果会话的模块名不匹配,则会话不包含在BEGIN和END语句之间,并且包含子句的语句将失败。

See Also:

Parent topic: Managing Applications in an Application Container

17.3.2 Installing Applications in an Application Container

You can install an application in an application container.

This section contains the following topics:

Parent topic: Managing Applications in an Application Container

17.3.2.1 关于在应用程序容器中安装应用程序

You issue ALTER PLUGGABLE DATABASE APPLICATION statements to install an application in the application root.

只在应用程序根目录中安装应用程序。与应用程序同步的应用程序PDBs自动安装应用程序。使用自动化方法,您可以使用以下一种或多种技术执行安装:脚本、SQL语句和图形用户界面工具。

Start of the installation with an 

ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL

 statement and the end of the install with an

 ALTER PLUGGABLE DATABASE APPLICATION END INSTALL 

声明。每个安装必须与应用程序名称和版本号相关联,这些名称和版本号在ALTER PLUGGABLE数据库应用程序语句中指定。

Related Topics

Parent topic: Installing Applications in an Application Container

17.3.2.2 在具有自动传播的应用程序容器中安装应用程序

在自动传播中,应用程序安装在与应用程序根中的应用程序同步的应用程序PDBs中

Prerequisites

You must meet the following prerequisites:

  • The current user must have the ALTER PLUGGABLE DATABASE system privilege, and the privilege must be commonly granted in the application root.

  • The application root must be in open read/write.

To install an application using automated propagation:

  1. In SQL*Plus or SQL Developer, ensure that the current container is a PDB.

  2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN INSTALL 'application_version_number';

    For example, run the following statement if the application_name is salesapp and the application_version_number is 4.2:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN INSTALL '4.2';
  3. Install the application using scripts, SQL statements, or graphical user interface tools.

  4. Run the ALTER PLUGGABLE DATABASE APPLICATION END INSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END INSTALL 'application_version_number';

    For example, run the following statement if the application_name is salesapp and the application_version_number is 4.2:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp END INSTALL '4.2';

    Note:

    Ensure that the application_name and application_version_number match in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL statement and theALTER PLUGGABLE DATABASE APPLICATION END INSTALLstatement.
  5. Synchronize all of the application PDBs that must install the application by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

Related Topics

Parent topic: Installing Applications in an Application Container

17.3.3 在应用程序容器中升级应用程序

Major changes to an application constitute application upgrades. You can upgrade an application in an application container.

This section contains the following topics:

Parent topic: Managing Applications in an Application Container

17.3.3.1 About Upgrading Applications in an Application Container

You issue ALTER PLUGGABLE DATABASE APPLICATION statements to upgrade an application in the application root.

只在应用程序根目录中升级应用程序,应用程序PDBs在与应用程序同步时应用升级中的更改。应用程序PDBs通过使用SYNC子句运行ALTER PLUGGABLE数据库语句与应用程序同步。您可以使用以下一种或多种技术进行升级:脚本、SQL语句和图形用户界面工具。

使用ALTER PLUGGABLE数据库应用程序BEGIN upgrade语句指示升级的开始,使用ALTER PLUGGABLE数据库应用程序end upgrade语句指示升级的结束。每个升级必须与应用程序名称、启动版本号和结束版本号相关联,这些都在ALTER PLUGGABLE数据库应用程序语句中指定。

升级应用程序时,Oracle数据库会自动克隆应用程序根目录。在升级过程中,应用程序PDBs指向克隆。应用程序在升级期间继续运行。应用程序PDBs可以在元数据链接和扩展数据链接表和视图上执行DML。应用程序PDBs可以查询元数据链接对象、扩展数据链接对象和数据链接对象。

升级之后,应用程序根克隆仍然保留并继续支持任何仍然在克隆中使用应用程序预升级版本的应用程序PDB。升级的应用程序PDBs指向升级后的应用程序根目录。不升级的应用程序PDBs可能继续使用克隆,而插入到应用程序根目录的应用程序PDBs也可能使用与克隆相同的应用程序版本。

Note:

与应用程序升级不同,补丁不会创建应用程序根克隆。如果应用程序PDB在打补丁后没有同步,那么查询将被定向到已经打补丁的应用程序根目录。

The following figure illustrates the upgrade process.

Figure 17-1 Upgrading Applications in an Application Container

Description of Figure 17-1 follows
Description of "Figure 17-1 Upgrading Applications in an Application Container"

Note:

当应用程序根处于任何打开模式时,应用程序根克隆处于只读模式。当关闭应用程序根时,应用程序根克隆也将关闭。

Related Topics

Parent topic: Upgrading Applications in an Application Container

17.3.3.2 Upgrading an Application in an Application Container

升级之后,由升级引起的应用程序更改将传播到与应用程序根同步的应用程序PDBs。

Prerequisites

  • The CDB must be in local undo mode.

  • The current user must have the ALTER PLUGGABLE DATABASE system privilege, and the privilege must be commonly granted in the application root.

  • The application root must be in open read/write.

To upgrade an application in an application container:

  1. In SQL*Plus or SQL Developer, ensure that the current container is the application root.

  2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADE statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN UPGRADE 'application_start_version_number' TO 'application_end_version_number';

    For example, run the following statement if the application_name is salesapp, the application_start_version_number is 4.2, and the application_end_version_number is 4.3:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN UPGRADE '4.2' TO '4.3';
  3. Upgrade the application using scripts, SQL statements, or graphical user interface tools.

  4. Run the ALTER PLUGGABLE DATABASE APPLICATION END UPGRADE statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END UPGRADE TO 'application_end_version_number';

    For example, run the following statement if the application_name is salesapp and the application_end_version_number is 4.3:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp END UPGRADE TO '4.3';

    Note:

    Ensure that the application_name and application_end_version_number match in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADE statement and the ALTER PLUGGABLE DATABASE APPLICATION END UPGRADEstatement.
  5. Synchronize all of the application PDBs that must upgrade the application by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

Related Topics

Parent topic: Upgrading Applications in an Application Container

17.3.4 修补应用程序容器中的应用程序

Minor changes to an application constitute application patches.

小改动的例子包括bug修复和安全补丁。您可以在应用程序容器中修补应用程序。

This section contains the following topics:

Parent topic: Managing Applications in an Application Container

17.3.4.1 About Patching Applications in an Application Container

To patch an application in the application root, issue ALTER PLUGGABLE DATABASE APPLICATION statements.

只在应用程序根目录中修补应用程序。与应用程序同步的应用程序PDBs应用这些更改。您可以使用以下一种或多种技术执行补丁:脚本、SQL语句和图形用户界面工具。

该补丁仅限于一小部分操作。通常,在补丁中不允许执行破坏性操作,例如删除表。如果试图对应用程序进行补丁,而操作引发“应用程序补丁中不支持的操作”错误,则升级应用程序,而不是对其进行补丁以进行必要的更改。

Note:

与应用程序升级不同,补丁不会创建应用程序根克隆。如果应用程序PDB在打补丁后没有同步,那么查询将被定向到已经打补丁的应用程序根目录。

使用ALTER PLUGGABLE数据库应用程序BEGIN patch语句指示补丁的开始,使用ALTER PLUGGABLE数据库应用程序end patch语句指示补丁的结束。每个补丁必须与应用程序名称、开始版本号和结束版本号相关联。在ALTER PLUGGABLE数据库应用程序语句中指定这些值。

Related Topics

Parent topic: Patching Applications in an Application Container

17.3.4.2 在应用程序容器中使用自动传播修补应用程序

补丁的应用程序更改被传播到与应用程序根中的应用程序同步的应用程序PDBs。

Prerequisites

The following prerequisites must be met:

  • The current user must have the ALTER PLUGGABLE DATABASE system privilege, and the privilege must be commonly granted in the application root.

  • The application root must be in open read/write mode.

  1. In SQL*Plus, ensure that the current container is the application root.
  2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN PATCH statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN PATCH patch_number MINIMUM VERSION 'minimum_application_version_number';

    For example, run the following statement if the application_name is salesapp, the patch_number is 987654, and the minimum_application_version_number is 4.2:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN PATCH 987654 MINIMUM VERSION '4.2';

    The minimum_application_version_number indicates the minimum application version at which an application installation must be before the patch can be applied to it.

  3. Patch the application using scripts, SQL statements, and graphical user interface tools.
  4. Run the ALTER PLUGGABLE DATABASE APPLICATION END PATCH statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END PATCHpatch_number;

    For example, run the following statement if the application_name is salesapp and the patch_number is 987654:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp END PATCH 987654;

    Note:

    Ensure that the application_name and patch_number match in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN PATCH statement and the ALTER PLUGGABLE DATABASE APPLICATION END PATCH statement.
  5. Synchronize all of the application PDBs that must patch the application by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

Related Topics

Parent topic: Patching Applications in an Application Container

17.3.5 将现有应用程序迁移到应用程序容器

You can migrate an application that is installed in a PDB to an application container.

您可以将应用程序迁移到应用程序根目录或应用程序PDB。例如,您可以将安装在插入Oracle数据库12c Release 2 (12.2) CDB的PDB中的应用程序迁移到Oracle数据库18c CDB中的应用程序容器。

This section contains the following topics:

Parent topic: Managing Applications in an Application Container

17.3.5.1 关于将现有应用程序迁移到应用程序容器

You can migrate an application to an application root by creating an application root using an existing PDB.

如果应用程序安装在多个PDB中,则可以使用其中一个PDBs创建应用程序根目录。您可以使用将PDB复制到应用程序根目录的一种可用方法,例如克隆PDB或将PDB插入到应用程序根目录。

当用于创建应用程序根的PDB中存在普通用户、角色或概要文件时,必须在DBMS_PDB包中运行过程,以便将它们与应用程序关联。当从PDB创建的应用程序根首次打开时,每个本地用户、角色和概要文件都被标记为common。DBMS_PDB包中的过程将用户、角色或概要文件与应用程序关联起来。因此,用户、角色或概要文件上的所有DDL操作必须随后在应用程序BEGIN中完成……此应用程序的结束块。

当共享数据库对象存在于应用程序根目录中时,必须在DBMS_PDB包中运行过程,以便将数据库对象与应用程序关联为应用程序公共对象。因此,应用程序公共对象上的所有DDL操作必须随后在应用程序BEGIN中完成……此应用程序的结束块。

应用程序根就绪后,您可以使用现有的PDBs在新的应用程序容器中创建应用程序PDBs。您创建的应用程序PDBs必须包含应用程序对象,包括它们的数据。还需要其他步骤来同步应用程序版本和补丁号,并在应用程序PDBs中建立共享数据库对象。

使用100个pdb运行相同应用程序的场景

假设您目前有100个正在运行相同应用程序的pdb,并且您希望将这些pdb迁移到应用程序容器中。这些pdb具有应用程序所需的公共对象和公共用户、角色和概要文件。要将PDBs迁移到应用程序容器,请遵循以下步骤:

  1. Choose one of the PDBs, and use the instructions in "Creating an Application Root Using an Existing PDB" to create the application root with this PDB.

    As part of this step, you associate the database objects, users, roles, and profiles with the application by running procedures in the DBMS_PDB package.

  2. Use the instructions in "Creating an Application PDB Using an Existing PDB" to create one hundred application PDBs using the PDBs that are running the application.

See Also:

Parent topic: Migrating an Existing Application to an Application Container

17.3.5.2 使用现有PDB创建应用程序根目录

Migrate an application that is installed in a PDB by copying the PDB to an application container.

Prerequisites

An Oracle Database 12c Release 2 (12.2) or later CDB must exist.

  1. In the CDB, create the application root by cloning the existing PDB, relocating the existing PDB, or by unplugging and plugging in the existing PDB.

    The new application root must contain all database objects used by the application.

  2. With the application root as the current container, start an application installation operation by issuing an ALTER PLUGGABLE DATABASE ... BEGIN INSTALL statement.
  3. Optional: Query the COMMON column in the DBA_USERSDBA_ROLES, and DBA_PROFILES views to determine which users, roles, and profiles are common.
  4. Run the following procedures in the DBMS_PDB package to associate users, roles. and profiles with the application:
    • Run the SET_USER_EXPLICIT procedure to set application common users.
    • Run the SET_ROLE_EXPLICIT procedure to set application common roles.
    • Run the SET_PROFILE_EXPLICIT procedure to set application common profiles.

    If you do not have EXECUTE privilege on the DBMS_PDB package, then you can run these procedures in the DBMS_PDB_ALTER_SHARING package.

  5. Optional: With the application root as the current container, query the SHARING column in the DBA_OBJECTS view to determine which database objects are shared.
  6. Run the following procedures in the DBMS_PDB package to associate database objects with the application:
    • Run the SET_DATA_LINKED procedure to set data-linked application common objects.
    • Run the SET_METADATA_LINKED procedure to set metadata-linked application common objects.
    • Run the SET_EXT_DATA_LINKED procedure to set extended data-linked application common objects.

    If you do not have EXECUTE privilege on the DBMS_PDB package, then you can run these procedures in the DBMS_PDB_ALTER_SHARING package.

  7. End the application installation operation by issuing an ALTER PLUGGABLE DATABASE ... END INSTALL statement.
  8. Optional: Rerun the queries that you ran previously to ensure that the sharing properties of the database objects are correct and that the common properties of the users, roles, and profiles are correct.
  9. Optional: If existing PDBs use the application, then create application PDBs using these existing PDBs.

    See "Creating an Application PDB Using an Existing PDB".

Related Topics

Parent topic: Migrating an Existing Application to an Application Container

17.3.5.3 使用现有PDB创建应用程序PDB

After migrating an existing application to an application root, you can use an existing PDB that uses the application to create an application PDB.

Prerequisites

You must meet the following prerequisites:

  • An Oracle Database 12c Release 2 (12.2) or later CDB must exist, and the application root to which the application PDB will belong must exist.

  • The PDB must contain all application common objects used by the application.

  • The application must be installed in the application root.

  1. In the application root, create the application PDB by cloning the existing PDB or by unplugging and plugging in the existing PDB.

    Violations will be reported during PDB creation.

  2. Connect to or switch to the new PDB as a user with the required privileges.
  3. Run the pdb_to_apppdb.sql script in the ORACLE_HOME/rdbms/admin directory.

    The script automatically synchronizes the application PDB with the application root.

  4. Optional: Query the SHARING column in the DBA_OBJECTS view to ensure that the sharing properties of the database objects are correct.
  5. Optional: Query the COMMON column in the DBA_USERSDBA_ROLES, and DBA_PROFILES views to ensure that the common properties of the users, roles, and profiles are correct.

Related Topics

Parent topic: Migrating an Existing Application to an Application Container

17.3.6 在应用程序PDB中同步应用程序

Synchronizing an application updates the application in the application PDB to the latest version and patch in the application root.

Note:

在应用程序根目录中安装、升级、修补或卸载应用程序时,属于该应用程序根目录的应用程序PDB在同步之前不会更改

除了用户创建的应用程序之外,应用程序容器还可以包含隐式创建的应用程序。当应用程序公共用户操作使用CONTAINER=ALL子句(位于ALTER PLUGGABLE DATABASE BEGIN/END语句之外)发出时,将在应用程序根目录中隐式创建应用程序。应用程序公共用户操作包括使用CREATE user语句创建公共用户或使用ALTER user语句更改公共用户等操作。隐式应用程序名为APP$guid,其中guid是应用程序根的guid。 当第一次打开应用程序根目录时,将创建隐式应用程序。

当应用程序PDB是当前容器时,通过发出以下SQL语句来同步应用程序PDB中的一个应用程序,其中application_name是应用程序的名称:

ALTER PLUGGABLE DATABASE APPLICATION application_name SYNC;

Synchronize all of the applications in an application PDB, including implicitly created applications, by issuing the following SQL statement when the application PDB is the current container:

ALTER PLUGGABLE DATABASE APPLICATION ALL SYNC;

Synchronize implicitly created applications in an application PDB by issuing one of the following SQL statement when the application PDB is the current container:

  • ALTER PLUGGABLE DATABASE APPLICATION APP$guid SYNC;

    guid is the GUID of the application root.

  • ALTER PLUGGABLE DATABASE APPLICATION APP$CON SYNC;

    APP$CON is a logical application name that Oracle Database automatically translates to the real name of the implicit application.

Prerequisites

The current user must have ALTER PLUGGABLE DATABASE system privilege.

  1. In SQL*Plus, ensure that the current container is the application PDB.
  2. Run an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

Example 17-1 Synchronizing a Specific Application in an Application PDB

This example synchronizes an application named salesapp with the latest application changes in the application root.

ALTER PLUGGABLE DATABASE APPLICATION salesapp SYNC;

Example 17-2 Synchronizing All of the Applications in an Application PDB

This example synchronizes all of the applications in an application PDB with the latest application changes in the application root.

ALTER PLUGGABLE DATABASE APPLICATION ALL SYNC;

Example 17-3 Synchronizing Implicitly-Created Applications in an Application PDB

This example synchronizes all of the implicitly-created applications in an application PDB with the latest application changes to the implicitly created applications in the application root.

ALTER PLUGGABLE DATABASE APPLICATION APP$CON SYNC;

Parent topic: Managing Applications in an Application Container

17.3.7 将应用程序根副本与代理PDB同步

When application containers in different CDBs have the same application, their application roots can be kept synchronized by creating a master application root, a replica application root, and a proxy PDB.

This section contains the following topics:

Parent topic: Managing Applications in an Application Container

17.3.7.1 关于将应用程序根副本与代理PDB同步

代理PDB可以同步应用程序根和应用程序根的副本。
应用程序可以安装在多个应用程序容器中。当您使用代理PDBs时,安装、升级和修补应用程序将更加有效。

在此配置中,一个应用程序容器具有主应用程序根。主应用程序根目录是安装、升级和修补应用程序的地方。应用程序根副本是主应用程序根的精确副本。每个应用程序根副本都由主应用程序根中的代理PDB引用。

当代理PDB与主应用程序根中的应用程序更改同步时,它将更改传播到引用的应用程序根副本。同步应用程序根副本之后,插入到应用程序根副本中的应用程序PDBs可以与副本同步,并以这种方式接收更改。

The following figure shows a configuration that synchronizes an application root replica using a proxy PDB.

Figure 17-2 Synchronizing an Application Root Replica with a Proxy PDB

Description of Figure 17-2 follows
Description of "Figure 17-2 Synchronizing an Application Root Replica with a Proxy PDB"

此外,当配置了应用程序根副本并拥有自己的应用程序PDBs时,在主应用程序根中包含CONTAINERS子句的查询可以从当前应用程序容器和带有应用程序根副本的应用程序容器返回数据。查询可以显示来自应用程序根副本和插入副本的任何开放应用程序PDBs的结果。

See Also:

"Querying Application Common Objects Across Application PDBs"

Parent topic: Synchronizing an Application Root Replica with a Proxy PDB

17.3.7.2 创建引用应用程序根副本的代理PDB

When multiple application containers run the same application, the application in the application containers can be kept synchronized using proxy PDBs.

  1. Create the application container with the master application root by using a CREATE PLUGGABLE DATABASE statement.

    Install the application in the application container now or later.

  2. Create the application container with the application root replica in one of the following ways:
    • Create an empty application container using any supported method.
    • Clone the master application root.

    If the port of the listener used by the application root replica is not 1521, then a PORT clause is required during creation. If the host of the application root replica is different from the host of the master application root, then a HOST clause is required during creation.

    This application root replica will be referenced by the proxy PDB.

  3. In the master application root, create a proxy PDB that references the application root replica that you created in the previous step.
  4. Open and synchronize the proxy PDB.

    When the proxy PDB is synchronized, it propagates the changes in the master application root to the application root replica.

  5. Optional: In the master application root, modify the application by installing, upgrading, or patching it.
  6. Optional: Synchronize the proxy PDB with the application changes in the master application root by running the ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

    When the proxy PDB is synchronized, it propagates the changes in the master application root to the application root replica.

Example 17-4 Synchronizing an Application Root Replica with a Proxy PDB

本例假设存在两个cdb: hqdb和depdb。目标是在每个CDB的应用程序容器中保持相同的应用程序同步。为了实现这个目标,本例配置了以下应用程序容器:

  • The hqdb CDB contains the application container with the master application root called msappcon.

    • An application called sampleapp is installed in the msappcon master application root.

    • The msappcon application root contains two application PDBs named mspdb1 and mspdb2.

    • The msappcon application root also contains a proxy PDB named prxypdb that references the application root replica in the other CDB.

  • The depdb CDB contains the application container with the application root replica called depappcon.

    • An application called sampleapp is propagated from the proxy PDB prxypdb in the msappcon master application root and installed in the depappcon master application root.

    • The depappcon application root contains two application PDBs named deppdb1 and deppdb2.

This example shows how changes to the sampleapp application in the msappcon master application root are applied to the application PDBs in both CDBs when the application PDBs are synchronized.

  1. Create the application container with the master application root in the hqdb CDB.

    1. In SQL*Plus, ensure that the current container is the hqdb CDB root.

    2. Create the application container from the PDB seed with the following statement:

      CREATE PLUGGABLE DATABASE msappcon 
        AS APPLICATION CONTAINER
        ADMIN USER msappconadm IDENTIFIED BY password  STORAGE (MAXSIZE 2G)
        DEFAULT TABLESPACE appcontbs 
          DATAFILE '/disk1/oracle/dbs/mssappcon/msappcon01.dbf' SIZE 250M AUTOEXTEND ON
        FILE_NAME_CONVERT = ('/disk1/oracle/dbs/pdbseed/', '/disk1/oracle/dbs/msappcon/');
    3. Open the new master application root in read/write mode:

      ALTER PLUGGABLE DATABASE msappcon OPEN;
  2. Install an application in the master application root.

    1. Change container to the master application root:

      ALTER SESSION SET CONTAINER=msappcon;
    2. Begin the application installation:

      ALTER PLUGGABLE DATABASE APPLICATION sampleapp BEGIN INSTALL '1.0';
    3. Install the application.

      For example, you can create database objects:

      CREATE TABLE apptb SHARING=METADATA
         (id            NUMBER(6), 
          widget_name   VARCHAR2(20));
      
    4. End the application installation:

      ALTER PLUGGABLE DATABASE APPLICATION sampleapp END INSTALL '1.0';
  3. Create and synchronize one or more application PDBs in the master application root.

    1. In SQL*Plus, ensure that the current container is the master application root.

    2. Create application PDBs in the master application root.

      For example, create two application PDBs from the PDB seed:

      CREATE PLUGGABLE DATABASE mspdb1 ADMIN USER mspdb1admin IDENTIFIED BY password
        STORAGE (MAXSIZE 2G)
        DEFAULT TABLESPACE mspdb1tbs 
          DATAFILE '/disk1/oracle/dbs/mspdb1/mspdb101.dbf' SIZE 250M AUTOEXTEND ON
        FILE_NAME_CONVERT = ('/disk1/oracle/dbs/pdbseed/', '/disk1/oracle/dbs/mspdb1/');
      
      CREATE PLUGGABLE DATABASE mspdb2 ADMIN USER mspdb2admin IDENTIFIED BY password
        STORAGE (MAXSIZE 2G)
        DEFAULT TABLESPACE mspdb2tbs 
          DATAFILE '/disk1/oracle/dbs/mspdb2/mspdb201.dbf' SIZE 250M AUTOEXTEND ON
        FILE_NAME_CONVERT = ('/disk1/oracle/dbs/pdbseed/', '/disk1/oracle/dbs/mspdb2/');
    3. Open both application PDBs:

      ALTER PLUGGABLE DATABASE mspdb1 OPEN;
      ALTER PLUGGABLE DATABASE mspdb2 OPEN;
    4. Synchronize the application PDBs with the master application root:

      ALTER SESSION SET CONTAINER=mspdb1;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
      
      ALTER SESSION SET CONTAINER=mspdb2;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
  4. Create the application container with the application root replica in the depdb CDB.

    1. In SQL*Plus, ensure that the current container is the depdb CDB root.

    2. Create the application container from the PDB seed with the following statement:

      CREATE PLUGGABLE DATABASE depappcon 
        AS APPLICATION CONTAINER
        ADMIN USER depappconadm IDENTIFIED BY password
        STORAGE (MAXSIZE 2G)
        DEFAULT TABLESPACE appcontbs 
          DATAFILE '/disk2/oracle/dbs/depsappcon/depappcon01.dbf' SIZE 250M AUTOEXTEND ON
        FILE_NAME_CONVERT = ('/disk2/oracle/dbs/pdbseed/', '/disk2/oracle/dbs/depappcon/');

      Note:

      • If the port of the listener used by the application root replica is not 1521, then a PORT clause is required.

      • If the host of the application root replica is different from the host of the master application root, then a HOST clause is required.

    3. Open the new application root replica in read/write mode:

      ALTER PLUGGABLE DATABASE depappcon OPEN;
  5. Create and synchronize the proxy PDB in the master application root.

    1. In SQL*Plus, ensure that the current container is the master application root.

    2. Create a database link to the application root replica:

      CREATE PUBLIC DATABASE LINK depappcon CONNECT TO depappconadm IDENTIFIED BY password USING 'depappcon';
    3. Create the proxy PDB:

      CREATE PLUGGABLE DATABASE prxypdb AS PROXY FROM depappcon@depappcon
         FILE_NAME_CONVERT = ('/disk2/oracle/dbs/depsappcon/', '/disk1/oracle/dbs/prxypdb/');
    4. Open the proxy PDB:

      ALTER PLUGGABLE DATABASE prxypdb OPEN;
    5. Synchronize the proxy PDB with the master application root:

      ALTER SESSION SET CONTAINER=prxypdb;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
  6. Create and synchronize one or more application PDBs in the application root replica.

    1. Change container to the application root replica:

      ALTER SESSION SET CONTAINER=depappcon;
    2. Create application PDBs in the application root replica.

      For example, create two application PDBs from the PDB seed:

      CREATE PLUGGABLE DATABASE deppdb1 ADMIN USER deppdb1admin IDENTIFIED BY password
        STORAGE (MAXSIZE 2G)
        DEFAULT TABLESPACE deppdb1tbs 
          DATAFILE '/disk2/oracle/dbs/deppdb1/deppdb101.dbf' SIZE 250M AUTOEXTEND ON
        FILE_NAME_CONVERT = ('/disk2/oracle/dbs/pdbseed/', '/disk2/oracle/dbs/deppdb1/');
      
      CREATE PLUGGABLE DATABASE deppdb2 ADMIN USER deppdb2admin IDENTIFIED BY password
        STORAGE (MAXSIZE 2G)
        DEFAULT TABLESPACE deppdb2tbs 
          DATAFILE '/disk2/oracle/dbs/deppdb2/deppdb201.dbf' SIZE 250M AUTOEXTEND ON
        FILE_NAME_CONVERT = ('/disk2/oracle/dbs/pdbseed/', '/disk2/oracle/dbs/deppdb2/');
    3. Open both application PDBs:

      ALTER PLUGGABLE DATABASE deppdb1 OPEN;
      ALTER PLUGGABLE DATABASE deppdb2 OPEN;
    4. Synchronize the application PDBs with the master application root:

      ALTER SESSION SET CONTAINER=deppdb1;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
      
      ALTER SESSION SET CONTAINER=deppdb2;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
  7. Check the structure of the apptb table in an application PDB in the application root replica.

    1. From the application root replica, switch containers to the deppdb1 application PDB:

      ALTER SESSION SET CONTAINER=deppdb1;
    2. Describe the apptb table:

      desc apptb

      Your output is similar to the following:

       Name                                      Null?    Type
       ----------------------------------------- -------- ----------------------------
       ID                                                 NUMBER(6)
       WIDGET_NAME                                        VARCHAR2(20)
  8. In the master application root, upgrade the application.

    1. Change container to the master application root:

      ALTER SESSION SET CONTAINER=msappcon;
    2. Begin the application upgrade.

      ALTER PLUGGABLE DATABASE APPLICATION sampleapp BEGIN UPGRADE '1.0' TO '1.1';
    3. Modify the application.

      For example, add a row to the apptb table:

      ALTER TABLE apptb ADD (widget_type VARCHAR2(30));
    4. End the application upgrade:

      ALTER PLUGGABLE DATABASE APPLICATION sampleapp END UPGRADE TO '1.1';
  9. Synchronize the proxy PDB with the master application root:

    ALTER SESSION SET CONTAINER=prxypdb;
    ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
  10. Synchronize the application PDBs in the application root replica and check for the application upgrade.

    1. Synchronize the application PDBs:

      ALTER SESSION SET CONTAINER=deppdb1;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
      
      ALTER SESSION SET CONTAINER=deppdb2;
      ALTER PLUGGABLE DATABASE APPLICATION sampleapp SYNC;
    2. From the application root replica, switch containers to the deppdb1 application PDB:

      ALTER SESSION SET CONTAINER=deppdb1;
    3. Describe the apptb table:

      desc apptb

      Your output is similar to the following:

       Name                                      Null?    Type
       ----------------------------------------- -------- ----------------------------
       ID                                                 NUMBER(6)
       WIDGET_NAME                                        VARCHAR2(20)
       WIDGET_TYPE                                        VARCHAR2(30)

      Notice that the change in the application upgrade is reflected in the output because the widget_type column has been added to the apptb table.

Related Topics

Parent topic: Synchronizing an Application Root Replica with a Proxy PDB

17.3.8设置应用程序的兼容性版本

应用程序的兼容性版本是属于该应用程序容器的应用程序PDBs可能使用的最早的应用程序版本。
兼容性版本在设置兼容性版本和创建应用程序PDB时强制执行。如果存在由于应用程序升级而产生的应用程序根克隆,则隐式地删除所有与兼容版本之前的版本对应的应用程序根克隆。

You specify the compatibility version of an application by issuing one of the following SQL statements when the application root is the current container:

  • ALTER PLUGGABLE DATABASE APPLICATION application_name SET COMPATIBILITY VERSION 'application_version_number';

    application_name is the name of the application, and application_version_number is the earliest compatible version.

  • ALTER PLUGGABLE DATABASE APPLICATION application_name SET COMPATIBILITY VERSION CURRENT;

    application_name is the name of the application. The current version is the version of the application in the application root.

  1. In SQL*Plus, ensure that the current container is the application root.
  2. Run an ALTER PLUGGABLE DATABASE APPLICATION SET COMPATIBILITY VERSION statement.

Example 17-5 Setting the Compatibility Version to a Specific Version Number

This example sets the compatibility version for an application named salesapp to version 4.2.

ALTER PLUGGABLE DATABASE APPLICATION salesapp SET COMPATIBILITY VERSION '4.2';

Example 17-6 Setting the Compatibility Version to the Current Application Version

This example sets the compatibility version for an application named salesapp to the current application version.

ALTER PLUGGABLE DATABASE APPLICATION salesapp SET COMPATIBILITY VERSION CURRENT;

See Also:

"About Upgrading Applications in an Application Container" for information about application root clones

Parent topic: Managing Applications in an Application Container

17.3.9 在应用程序安装、升级和补丁操作期间执行批量插入

SQL*Loader是在应用程序安装、升级和补丁操作期间批量插入表的惟一受支持实用程序。在应用程序安装、升级和补丁操作期间,只支持批量插入常规路径负载。
必须在ALTER PLUGGABLE数据库应用程序开始和ALTER PLUGGABLE数据库应用程序结束语句之间指定正确的SQL*Loader模块名。模块名称为SQL加载程序常规路径加载。

  1. In SQL*Plus, ensure that the current container is the application root.
  2. Set the correct module by running the following procedure:

    exec DBMS_APPLICATION_INFO.SET_MODULE('SQL Loader Conventional Path Load', '');

    This module must remain set for the entire application install, upgrade, or patch operation.

  3. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN statement for beginning an application installation, upgrade, or patch.

    For example, if you are performing the bulk insert as part of an application installation, then run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN INSTALL 'application_version_number';

  4. Perform the conventional path load with SQL*Loader.
  5. Run the ALTER PLUGGABLE DATABASE APPLICATION END statement for ending an application installation, upgrade, or patch.

    For example, if you are performing the bulk insert as part of an application installation, then run the ALTER PLUGGABLE DATABASE APPLICATION END INSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END INSTALL 'application_version_number';

    Note:

    Ensure that the application_name and application_version_numbermatch in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL statement and the ALTER PLUGGABLE DATABASE APPLICATION END INSTALL statement.

  6. Synchronize all application PDBs that must include these application changes by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

Example 17-7 Performing a Conventional Path Load During an Application Installation

In this example, the conventional path load is performed in an application root.

  1. In SQL*Plus, switch to the application root.

    ALTER SESSION SET CONTAINER=cdb1_approot1;
  2. Set the correct module.

    exec DBMS_APPLICATION_INFO.SET_MODULE('SQL Loader Conventional Path Load', '');
  3. Start the application installation.

    ALTER PLUGGABLE DATABASE APPLICATION APP1 BEGIN INSTALL '1';
  4. Use SQL*Loader to perform the conventional path load.

    host sqlldr u1/u1@cdb1_approot1 control=my_bulk_load.ctl rows=3 log=my_bulk_load.log
  5. End the application installation.

    ALTER PLUGGABLE DATABASE APPLICATION APP1 END INSTALL '1';

See Also:

Oracle Database Utilities for information about SQL*Loader

Parent topic: Managing Applications in an Application Container

17.3.10 从应用程序容器卸载应用程序

You can uninstall an application in an application container.

This section contains the following topics:

  • About Uninstalling Applications from an Application Container
    You issue ALTER PLUGGABLE DATABASE APPLICATION statements to uninstall an application from the application root.
  • Uninstalling an Application from an Application Container
    To uninstall an application in from application container, run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UNINSTALL statement to begin the uninstallation and the ALTER PLUGGABLE DATABASE APPLICATION END UNINSTALL statement to end it. The application uninstalled from the application PDBs that synchronize with the application in the application root.

Parent topic: Managing Applications in an Application Container

17.3.10.1 About Uninstalling Applications from an Application Container

You issue ALTER PLUGGABLE DATABASE APPLICATION statements to uninstall an application from the application root.

只从应用程序根目录卸载应用程序,与应用程序同步的应用程序PDBs自动卸载应用程序。卸载操作可以使用以下一种或多种工具完成:脚本、SQL语句和图形用户界面工具。

必须使用ALTER PLUGGABLE数据库应用程序BEGIN UNINSTALL语句指示卸载的开始,使用ALTER PLUGGABLE数据库应用程序end UNINSTALL语句指示卸载的结束。每次卸载都必须与应用程序名称和版本号相关联,这些名称和版本号在ALTER PLUGGABLE数据库应用程序语句中指定。

卸载应用程序不会从数据字典中删除应用程序。它将应用程序标记为卸载,因此不允许对应用程序进行升级、补丁和卸载。

在卸载应用程序期间,允许对应用程序对象进行破坏性更改。在应用程序PDB中运行的应用程序在卸载期间和从应用程序根目录卸载应用程序之后继续发挥作用。 应用程序可以在应用程序PDB中继续运行,因为 ALTER PLUGGABLE DATABASE APPLICATION BEGIN UNINSTALL statement 创建应用程序根的克隆,称为应用程序根克隆. 应用程序根克隆用作应用程序对象的旧版本的元数据存储库,以便没有与应用程序的最新版本同步的应用程序pdb能够继续工作。因为克隆是在应用程序PDB打开时创建的,所以在卸载应用程序之前,必须在CDB级别上配置本地撤销。

Note:

An application upgrade also creates an application root clone.

See Also:

Parent topic: Uninstalling Applications from an Application Container

17.3.10.2 从应用程序容器卸载应用程序

要从应用程序容器中卸载应用程序,请运行ALTER PLUGGABLE DATABASE application BEGIN uninstall语句开始卸载,然后运行ALTER PLUGGABLE DATABASE application END uninstall语句结束卸载。应用程序从与应用程序根中的应用程序同步的应用程序PDBs卸载。

The following prerequisites must be met:

  • The CDB must be in local undo mode.

  • The current user must have the ALTER PLUGGABLE DATABASE system privilege, and the privilege must be commonly granted in the application root.

  • The application root must be in open read/write mode.

  1. In SQL*Plus, ensure that the current container is the application root.
  2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UNINSTALLstatement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN UNINSTALL;

    For example, run the following statement if the application_name is salesapp:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN UNINSTALL;

  3. Uninstall the application using scripts, SQL statements, or graphical user interface tools.
  4. Run the ALTER PLUGGABLE DATABASE APPLICATION END UNINSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END UNINSTALL;

    For example, run the following statement if the application_name is salesapp:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp END UNINSTALL;

    Note:

    Ensure that the application_name matches in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UNINSTALL statement and theALTER PLUGGABLE DATABASE APPLICATION END UNINSTALL statement.
  5. Synchronize all of the application PDBs that must uninstall the application by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause.

See Also:

Parent topic: Uninstalling Applications from an Application Container

17.4 Managing Application Common Objects

应用程序公共对象是在应用程序容器中共享的、用户创建的数据库对象。应用程序公共对象是在应用程序根目录中创建的。

This section contains the following topics:

  • About Application Common Objects
    Application common objects are created in an application root and are shared with the application PDBs that belong to the application root.
  • Restrictions for Application Common Objects
    Some restrictions apply to application common objects.
  • Creating Application Common Objects
    You create an application common object in an application root either by ensuring that the DEFAULT_SHARING initialization parameter is set to the correct value or by including the SHARING clause in the CREATE SQL statement.
  • Issuing DML Statements on Application Common Objects
    The rules are different for issuing DML statements on metadata-linked, data-linked, and extended data-linked application common objects.
  • Modifying Application Common Objects with DDL Statements
    When you modify an application common object in an application root with certain DDL statements, you must modify the object between ALTER PLUGGABLE DATABASE APPLICATION BEGIN and ALTER PLUGGABLE DATABASE APPLICATION ENDstatements, and application PDBs must synchronize with the application to apply the changes.

Parent topic: Administering Application Containers

17.4.1 About Application Common Objects

应用程序公共对象在应用程序根中创建,并与属于该应用程序根的应用程序PDBs共享。
有三种类型的应用程序公共对象:元数据链接、数据链接和扩展数据链接。以下类型的数据库对象可以是应用程序通用对象:

  • Analytic views

  • Attribute dimensions

  • Directories

  • External procedure libraries

  • Hierarchies

  • Java classes, resources, and sources

  • Object tables, types, and views

  • Sequences

  • Packages, stored functions, and stored procedures

  • Synonyms

  • Tables (including global temporary tables)

  • Triggers

  • Views

This section contains the following topics:

See Also:

"Application Common Objects"

Parent topic: Managing Application Common Objects

17.4.1.1 Creation of Application Common Objects

当当前容器是应用程序根目录时,通过发出Create语句并指定SHARING子句来创建应用程序公共对象。

您可以通过在CREATE语句中包含sharing子句或在应用程序根目录中设置DEFAULT_SHARING初始化参数来指定sharing属性。在设置DEFAULT_SHARING初始化参数时,该设置是在应用程序根目录中创建的受支持类型的所有数据库对象的默认共享属性。但是,当在CREATE语句中包含SHARINGclause时,其设置将覆盖DEFAULT_SHARING初始化参数的设置。

You can specify one of the following for the sharing attribute:

  • METADATA: A metadata link shares the database object’s metadata, but its data is unique to each container. These database objects are referred to as metadata-linked application common objects. This setting is the default.

  • DATA: A data link shares the database object, and its data is the same for all containers in the application container. Its data is stored only in the application root. These database objects are referred to as data-linked application common objects.

  • EXTENDED DATA: An extended data link shares the database object, and its data in the application root is the same for all containers in the application container. However, each application PDB in the application container can store data that is unique to the application PDB. For this type of database object, data is stored in the application root and, optionally, in each application PDB. These database objects are referred to as extended data-linked application common objects.

  • NONE: The database object is not shared.

对于大多数类型的应用程序公共对象,shared子句的唯一有效设置是元数据,而没有。以下类型的应用程序公共对象允许共享子句的其他设置:

  • For tables (excluding object tables), the SHARING clause can be set to METADATADATAEXTENDED DATA, or NONE. For object tables, only METADATA or NONE is valid.

  • For views (excluding object views), the SHARING clause can be set to METADATADATAEXTENDED DATA, or NONE. For object views, only METADATA or NONE is valid.

  • For sequences, the SHARING clause can be set to METADATADATA, or NONE.

    With a metadata-linked sequence, each application PDB has its own sequence. When the metadata-linked sequence is incremented using the NEXTVAL pseudocolumn in one application PDB, it does not affect the value of the sequence in the other application PDBs in the application container.

    With a data-linked sequence, each application PDB shares the same sequence in the application root. When the metadata-linked sequence is incremented using the NEXTVAL pseudocolumn in one application PDB, all other application PDBs in the same application container also see the change.

应用程序公共对象只能作为应用程序安装、升级或补丁的一部分创建或更改。当应用程序PDB与进行更改的应用程序同步时,它将更改应用程序公共对象。如果在创建、删除或修改应用程序公共对象时关闭了应用程序PDB,那么在打开并与应用程序同步时,将在应用程序PDB中应用适当的更改。

应用程序公共对象的名称不能与属于应用程序根目录或数据库根目录中oracle提供的公共对象的任何应用程序PDBs中的本地数据库对象的名称冲突。如果新打开的应用程序PDB包含一个本地数据库对象,其名称与应用程序公共对象的名称冲突,那么应用程序PDB将以restricted模式打开。在这种情况下,必须在应用程序PDB以正常模式打开之前解决命名冲突。

Parent topic: About Application Common Objects

17.4.1.2 About Metadata-Linked Application Common Objects

For metadata-linked application common objects, the metadata for the object is stored once in the application root.

属于应用程序根目录的每个应用程序PDB中的元数据链接使应用程序PDBs能够共享对象的元数据,包括对象名称和结构。对象的数据对于每个容器都是惟一的,包括应用程序根和属于应用程序根的每个应用程序PDB。

数据定义语言(DDL)对元数据链接的应用程序公共对象的操作只能作为应用程序安装、升级或补丁的一部分在应用程序根目录中运行。但是,可以使用常规数据操作语言(DML)操作在应用程序PDB中修改数据。

例如,考虑一家拥有多个区域办事处的公司。公司希望员工信息的结构是一致的,但是每个办公室有不同的员工。如果该公司在应用程序容器中有一个人力资源应用程序,它可以为每个区域办公室创建一个单独的应用程序PDB,并使用一个元数据链接表存储员工信息。对于每个区域办公室,应用程序PDB中的表(例如列)的数据结构是相同的,但是员工数据是不同的。

另一个例子可能涉及一个公司,该公司构建并维护一个销售应用程序,该应用程序被多个不同的企业使用。每个业务使用相同的销售应用程序,但是每个业务的数据是不同的。例如,每个企业都有不同的客户,因此客户数据也不同。为了确保每个客户端对其应用程序使用相同的数据结构,公司可能会创建一个应用程序容器,其中包含与元数据链接的应用程序公共对象。 每个使用销售应用程序的企业都有自己的应用程序PDB,每个应用程序PDB中的数据结构是相同的,但是数据不同。

Parent topic: About Application Common Objects

17.4.1.3 About Extended Data-Linked Application Common Objects

对于数据链接的应用程序公共对象,对象的元数据和数据都存储在应用程序根目录中。每个应用程序PDB中属于应用程序根的数据链接使应用程序PDBs能够共享对象的元数据和数据。

数据链接应用程序公共对象上的DDL操作只能作为应用程序安装、升级或补丁的一部分在应用程序根目录中运行。此外,只能在应用程序根目录中使用常规DML操作修改数据。不能在应用程序PDBs中修改数据。

例如,考虑一家拥有多个区域办事处的公司。该公司希望他们销售的产品的信息,如产品名称和描述,在所有区域办事处保持一致。如果该公司在应用程序容器中有一个销售应用程序,那么它可以为每个区域办公室创建一个单独的应用程序PDB,并使用一个数据链接表存储产品信息。每个应用程序PDB都可以查询产品信息,每个区域办事处的产品信息是一致的。

对于标准且不变的数据,数据链接应用程序公共对象也很有用。例如,存储国家邮政编码的表可能是应用程序容器中的数据链接应用程序公共对象。所有的应用程序PDBs都访问应用程序根目录中的相同邮政编码数据。

Note:

如果数据应用程序常见的对象是一个配置的一部分,同步应用程序根与代理PDB复制品,然后DML操作数据对象在应用程序之外的根可以做应用程序行动,但DML操作不是自动传播到应用程序通过代理PDB根复制。如果希望将DML操作传播到应用程序根副本,则必须在应用程序安装、升级或补丁中完成对应用程序根中的数据链接对象的DML操作。

Parent topic: About Application Common Objects

17.4.1.4 About Extended Data-Linked Application Common Objects

对于扩展的数据链接对象,每个应用程序PDB都可以在共享应用程序根中的公共数据的同时创建自己的数据。只有存储在应用程序根中的数据对所有应用程序pdb都是通用的。
扩展数据链接应用程序公共对象上的DDL操作只能作为应用程序安装、升级或补丁的一部分在应用程序根目录中运行。但是,可以使用常规DML操作在应用程序根目录或应用程序PDB中修改数据。

例如,应用程序容器中的销售应用程序可能支持多个应用程序PDBs,而所有应用程序PDBs都需要美国的邮政编码才能用于航运。在这种情况下,邮政编码可以存储在应用程序根目录中,以便所有应用程序PDBs都可以访问它。但是,有一个应用程序PDB也在加拿大销售,这个应用程序PDB需要美国和加拿大的邮政编码。This one application PDB can store the postal codes for Canada in an extended data-linked object in the application PDB instead of in the application root.

Note:

  • Tables and views are the only types of database objects that can be extended data-linked objects.

  • 如果扩展链路层应用程序常见的对象是一个配置的一部分,同步应用程序根与代理PDB复制品,然后DML操作在一个扩展的数据对象在应用程序之外的根可以做应用程序行动,但DML操作不是自动传播到应用程序通过代理PDB根复制。如果希望将DML操作传播到应用程序根副本,则必须在应用程序安装、升级、补丁。

Parent topic: About Application Common Objects

17.4.2 Restrictions for Application Common Objects

Some restrictions apply to application common objects.

对应用程序公共对象的查询可以从不是当前容器的容器返回数据。例如,当当前容器是应用程序根目录时,包含CONTAINERS子句的查询可以从应用程序PDBs返回用于元数据链接的应用程序公共对象的数据。此外,当当前容器是应用程序PDB时,对数据链接和扩展数据链接应用程序公共对象的查询将返回驻留在应用程序根目录中的数据。

Columns of the following types return no data in queries that return data from a container other than the current container:

  • The following user-defined types: object types, varrays, REFs, and nested tables

  • The following Oracle-supplied types: ANYTYPEANYDATASET, URI types, SDO_TOPO_GEOMETRYSDO_GEORASTER, and Expression

In addition, queries on object tables and object views return no data from containers other than the current container.

Related Topics

Parent topic: Managing Application Common Objects

17.4.3 Creating Application Common Objects

您可以通过确保DEFAULT_SHARING初始化参数设置为正确的值,或者通过在create SQL语句中包含SHARINGclause,在应用程序根中创建应用程序公共对象。

可以在应用程序根目录中创建元数据链接对象、扩展数据链接对象或数据链接对象,作为应用程序安装、升级或补丁的一部分。当应用程序PDB与应用程序根中的应用程序同步时,它将更改应用程序公共对象。

  1. In SQL*Plus, ensure that the current container is the application root.

    The current user must have the privileges required to create the database object.

  2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN statement for beginning an application installation, upgrade, or patch.

    For example, if you are creating the application common object as part of an application installation, then run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN INSTALL 'application_version_number';

  3. Create the application common object and specify its sharing attribute in one of the following ways:
    • Ensure that the DEFAULT_SHARING initialization parameter is set to the desired sharing attribute in the application root, and issue the CREATE SQL statement to create the database object.
    • Issue the CREATE SQL statement, and include the SHARING clause set to METADATADATA, or EXTENDED DATA.
    When a SHARING clause is included in a SQL statement, it takes precedence over the value specified in the DEFAULT_SHARING initialization parameter. For example, if the DEFAULT_SHARING initialization parameter is set to METADATA in the application root, and a database object is created with SHARING set to DATA, then the database object is created as a data-linked database object.

    Note:

    Once a database object is created, its sharing attribute cannot be changed.
  4. Run the ALTER PLUGGABLE DATABASE APPLICATION END statement for ending an application installation, upgrade, or patch.

    For example, if you are creating the application common object as part of an application installation, then run the ALTER PLUGGABLE DATABASE APPLICATION END INSTALL statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END INSTALL 'application_version_number';

    Note:

    Ensure that the application_name and application_version_number match in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN INSTALL statement and the ALTER PLUGGABLE DATABASE APPLICATION END INSTALLstatement.
  5. Synchronize all of the application PDBs that must apply these changes by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause with the application PDB as the current container.

Example 17-8 Setting the DEFAULT_SHARING Initialization Parameter

这个示例将DEFAULT_SHARING初始化参数设置为内存和SPFILE中的数据。当在应用程序根目录中创建支持共享的数据库对象,且CREATE SQL语句中不包含共享子句时,数据库对象使用DEFAULT_SHARING初始化参数中指定的共享属性。

ALTER SYSTEM SET DEFAULT_SHARING=DATA SCOPE=BOTH;

Example 17-9 Creating a Metadata-Linked Object

This example creates the employees_md metadata-linked table by including the SHARING=METADATA clause. The application_name is salesapp and the application_version_number is 4.2, and the object is created during application installation.

ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN INSTALL '4.2';
CREATE TABLE employees_md SHARING=METADATA
    (employee_id    NUMBER(6), 
     first_name     VARCHAR2(20),
     last_name      VARCHAR2(25) CONSTRAINT emp_last_name_nn_demo NOT NULL, 
     email          VARCHAR2(25) CONSTRAINT emp_email_nn_demo     NOT NULL, 
     phone_number   VARCHAR2(20), 
     hire_date      DATE  DEFAULT SYSDATE CONSTRAINT emp_hire_date_nn_demo  NOT NULL, 
     job_id         VARCHAR2(10) CONSTRAINT     emp_job_nn_demo  NOT NULL, 
     salary         NUMBER(8,2)  CONSTRAINT     emp_salary_nn_demo  NOT NULL, 
     commission_pct NUMBER(2,2), 
     manager_id     NUMBER(6), 
     department_id  NUMBER(4), 
     dn             VARCHAR2(300), 
          CONSTRAINT emp_salary_min_demo CHECK (salary > 0), 
          CONSTRAINT emp_email_uk_demo UNIQUE (email));
ALTER PLUGGABLE DATABASE APPLICATION salesapp END INSTALL '4.2';

Example 17-10 Creating a Data-Linked Object

This example creates the product_descriptions_ob data-linked table by including the SHARING=DATA clause. The application_name is salesapp and the application_version_number is 4.2, and the object is created during application installation.

ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN INSTALL '4.2';
CREATE TABLE product_descriptions_ob SHARING=DATA     
    (product_id             NUMBER(6), 
     language_id            VARCHAR2(3), 
     translated_name        NVARCHAR2(50)   CONSTRAINT translated_name_nn NOT NULL, 
     translated_description NVARCHAR2(2000) CONSTRAINT translated_desc_nn NOT NULL);
ALTER PLUGGABLE DATABASE APPLICATION salesapp END INSTALL '4.2';

Example 17-11 Creating an Extended Data-Linked Object

This example creates the postalcodes extended data-linked table by including the EXTENDEDkeyword and the SHARING clause. The application_name is salesapp and the application_version_number is 4.2, and the object is created during application installation.

ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN INSTALL '4.2';
CREATE TABLE postalcodes SHARING=EXTENDED DATA
    (code        VARCHAR2(7),
     country_id  NUMBER,
     place_name  VARCHAR2(20));
ALTER PLUGGABLE DATABASE APPLICATION salesapp END INSTALL '4.2';

Example 17-12 Creating an Object That Is Not Shared in an Application Root

This example creates the departments_ns table and specifies that it is not a shared common application object by including the SHARING=NONE clause. After creation, this database object can be accessed only in the application root.

CREATE TABLE departments_ns SHARING=NONE
    (department_id    NUMBER(4), 
     department_name  VARCHAR2(30) CONSTRAINT  dept_name_nn  NOT NULL, 
     manager_id       NUMBER(6), 
     location_id      NUMBER(4), 
     dn               VARCHAR2(300));

Note:

The ALTER PLUGGABLE DATABASE APPLICATION BEGIN and END statements are not required when you create an object that is not a shared common object. However, if you create an object that is not shared in between ALTER PLUGGABLE DATABASE APPLICATION BEGIN and END statements, then the object is created in application PDBs that synchronize with the application.

Related Topics

Parent topic: Managing Application Common Objects

17.4.4 对应用程序公共对象发出DML语句

The rules are different for issuing DML statements on metadata-linked, data-linked, and extended data-linked application common objects.

The following rules apply for issuing DML statements on application common objects:

  • Metadata-linked application common objects: DML statements can be issued on metadata-linked application objects normally. For metadata-linked application common objects, the structure is the same in all containers in an application container, but the data is different. Users and applications can issue DML statements on these objects in the same way that they would for ordinary database objects, and the DML statements only affect the current container.

    For metadata-linked objects, the CONTAINERS clause is useful when the DML statement is run in the application root. This clause lets you query data in the specified table or view across all application PDBs in an application container. It also lets you perform DML changes on the data in the specified table or view across all application PDBs in an application container. To use the containers clause, you wrap a table in the clause in the SQL statement, as in the following example:

    SELECT * FROM CONTAINERS(sales.customers);

    In addition, you can specify that a table or view must always be wrapped in the CONTAINERSclause by issuing an ALTER TABLE or ALTER VIEW statement with the ENABLE CONTAINERS_DEFAULT clause in the application root, as in the following example:

    ALTER TABLE sales.customers ENABLE CONTAINERS_DEFAULT;

    在设置此属性之后,在应用程序根目录中发出的查询和DML语句默认情况下将容器子句用于数据库对象。DBA_TABLES和DBA_VIEWS视图中的CONTAINERS_DEFAULTcolumn视图显示默认情况下是否为CONTAINERS子句启用数据库对象。

  • 数据链接应用程序公共对象:DML语句通常可以在应用程序根目录中的数据链接应用程序对象上发出。应用程序根中的DML更改会影响应用程序容器中所有应用程序PDBs可用的数据。不能在应用程序PDBs中的数据链接应用程序对象上发出DML语句。

  • 扩展数据链接应用程序公共对象:DML语句通常可以在应用程序根目录和应用程序PDBs中对扩展数据链接应用程序对象发出。应用程序根中的DML更改会影响应用程序容器中所有应用程序PDBs可用的数据。应用程序PDB中的DML更改只影响应用程序PDB特有的数据。

考虑一个具有数据链接或扩展数据链接对象的应用程序根,并假设这个应用程序根是与代理PDBs同步的一个或多个应用程序根副本的主应用程序根。在此配置中,只有在应用程序安装、升级或补丁期间发出DML语句时,DML更改才与应用程序根副本同步。具体来说,DML更改必须在应用程序根中发布ALTER PLUGGABLE DATABASE application BEGIN和ALTER PLUGGABLE DATABASE application END语句之间的更改. 在应用程序安装、升级或补丁之外所做的DML更改只应用于当前应用程序根,而不与应用程序根副本同步

To issue DML statements on a data-linked or extended data-linked application common object:

  1. Complete the appropriate steps:

    For an application common object that is not part of an application root replica configuration:

    1. Connect to the appropriate container in the application container as a user with the privileges required to issue DML statements on the database object.
    2. Issue DML statements normally.

    For a data-linked or extended data-linked object that is part of an application root replica configuration:

    1. In SQL*Plus, ensure that the current container is the master application root in the application root replica in the configuration.

      The current user must have the privileges required to issue the DML statements on the database object.

    2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN statement for beginning an application installation, upgrade, or patch.

      For example, if you are modifying the application common object as part of an application upgrade, then run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADE statement in the following form:

      ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN UPGRADE 'application_start_version_number' TO 'application_end_version_number';

      For example, run the following statement if the application_name is salesapp, the application_start_version_number is 4.2, and the application_end_version_number is 4.3:

      ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN UPGRADE '4.2' TO '4.3';

    3. Issue the DML statements on the data-linked application common object.
    4. Run the ALTER PLUGGABLE DATABASE APPLICATION END statement for ending an application installation, upgrade, or patch.

      For example, if you are modifying the application common object as part of an application upgrade, then run the ALTER PLUGGABLE DATABASE APPLICATION END UPGRADE statement in the following form:

      ALTER PLUGGABLE DATABASE APPLICATION application_name END UPGRADE TO 'application_end_version_number';

      For example, run the following statement if the application_name is salesapp and the application_end_version_number is 4.3:

      ALTER PLUGGABLE DATABASE APPLICATION salesapp END UPGRADE TO '4.3';

      Note:

      Ensure that the application_name and application_end_version_number match in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADEstatement and ALTER PLUGGABLE DATABASE APPLICATION END UPGRADE statements.
    5. Synchronize all of the application PDBs that must apply these changes by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause when the application PDB is the current container.

Related Topics

Parent topic: Managing Application Common Objects

17.4.5 使用DDL语句修改应用程序通用对象

在使用某些DDL语句修改应用程序根中的应用程序公共对象时,必须修改可插入数据库应用程序BEGINand可插入数据库应用程序END语句之间的对象,应用程序PDBs必须与应用程序同步才能应用更改。

您可以更改应用程序根中的元数据链接对象或数据链接对象。在数据库对象上运行ALTER、RENAME或DROP SQL语句来执行DDL更改。

  1. In SQL*Plus, ensure that the current container is the application root.

    The current user must have the privileges required to make the planned changes to the database object.

  2. Run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN statement for beginning an application installation, upgrade, or patch.

    For example, if you are modifying the application common object as part of an application upgrade, then run the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADE statement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name BEGIN UPGRADE 'application_start_version_number' TO 'application_end_version_number';

    For example, run the following statement if the application_name is salesapp, the application_start_version_number is 4.2, and the application_end_version_number is 4.3:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN UPGRADE '4.2' TO '4.3';

  3. Modify the application common object with the DDL statement.

    For example, an ALTER TABLE statement might add a column to a table.

  4. Run the ALTER PLUGGABLE DATABASE APPLICATION END statement for ending an application installation, upgrade, or patch.

    For example, if you are modifying the application common object as part of an application upgrade, then run the ALTER PLUGGABLE DATABASE APPLICATION END UPGRADEstatement in the following form:

    ALTER PLUGGABLE DATABASE APPLICATION application_name END UPGRADE TO 'application_end_version_number';

    For example, run the following statement if the application_name is salesapp and the application_end_version_number is 4.3:

    ALTER PLUGGABLE DATABASE APPLICATION salesapp END UPGRADE TO '4.3';

    Note:

    Ensure that the application_name and application_end_version_number match in the ALTER PLUGGABLE DATABASE APPLICATION BEGIN UPGRADE statement and the ALTER PLUGGABLE DATABASE APPLICATION END UPGRADEstatement.
  5. Synchronize all of the application PDBs that must apply these changes by issuing an ALTER PLUGGABLE DATABASE APPLICATION statement with the SYNC clause with the application PDB as the current container.

Related Topics

Parent topic: Managing Application Common Objects

17.5在应用程序容器中的容器上发出DML语句

A DML statement issued in an application root can modify one or more containers in the application container. In addition, you can specify one or more default container targets for DML statements.

This section contains the following topics:

Parent topic: Administering Application Containers

17.5.1关于在应用程序容器中的容器上发出DML语句

DML语句可以影响应用程序容器中多个容器中的数据库对象。

在应用程序根目录中,包含CONTAINERS子句的单个DML语句可以修改应用程序容器中一个或多个容器中的表或视图。要使用CONTAINERS子句,请在CONTAINERS子句中指定要修改的表或视图,并在WHEREclause中指定容器。通过在VALUES子句中为CON_ID指定值,可以在INSERT VALUES语句中指定目标容器。此外,可以通过在WHERE子句中指定CON_ID谓词,在UPDATE或DELETE语句中指定目标容器。

For example, the following DML statement updates the sales.customers table in the containers with a CON_ID of 7 or 8:

UPDATE CONTAINERS(sales.customers) ctab 
   SET ctab.city_name='MIAMI' 
   WHERE ctab.CON_ID IN(7,8) AND
   CUSTOMER_ID=3425;

The values specified for the CON_ID in the WHERE clause must be for containers in the current application container.

您可以为DML操作指定缺省目标容器。如果DML语句没有在WHERE子句中指定CON_ID的值,那么DML操作的目标容器就是应用程序根目录中的数据库属性CONTAINERS_DEFAULT_TARGET中指定的那些容器。当在应用程序根目录中发出时,以下DML语句将修改应用程序容器的默认目标容器:

UPDATE CONTAINERS(sales.customers) ctab 
   SET ctab.city_name='MIAMI' 
   WHERE CUSTOMER_ID=3425;

By default, the default target containers in an application container include all of its application PDBs but not its application root or application seed. You can determine the default target containers for an application container by running the following query:

SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME='CONTAINERS_DEFAULT_TARGET';

另外,您可以为应用程序根目录中的表或视图启用CONTAINERS_DEFAULT属性。当启用此属性时,默认情况下容器子句用于数据库对象上的查询和DML语句,并且不需要在SQL语句中指定容器子句。要为应用程序根目录中的表或视图启用CONTAINERS_DEFAULT属性,请使用enable CONTAINERS_DEFAULT子句运行ALTER table或ALTER view语句。

The following restrictions apply to the CONTAINERS clause:

  • The CONTAINERS DEFAULT TARGET clause does not affect SELECT statements.

  • INSERT as SELECT statements where the target of the INSERT is in CONTAINERS() is not supported.

  • A multi-table INSERT statement where the target of the INSERT is in CONTAINERS() is not supported.

  • DML statements using the CONTAINERS clause require that the database listener is configured using TCP (instead of IPC) and that the PORT and HOST values are specified for each target PDB using the PORT and HOST clauses, respectively.

Related Topics

Parent topic: Issuing DML Statements on Containers in an Application Container

17.5.2 为应用程序容器中的DML语句指定默认容器

要为应用程序容器中的DML语句指定默认容器,请使用容器默认目标子句发出ALTER PLUGGABLE数据库语句。

当DML语句在应用程序根中发出而没有在WHEREclause中指定容器时,DML语句会影响应用程序容器的默认容器。默认容器可以是应用程序容器中的任何容器,包括应用程序根或应用程序PDB。只允许一个默认容器。

  1. In SQL*Plus, ensure that the current container is the application root.

    The current user must have the commonly granted ALTER PLUGGABLE DATABASEprivilege.

  2. Run the ALTER PLUGGABLE DATABASE statement with the CONTAINERS DEFAULT TARGET clause.

Example 17-13 Specifying the Default Container for DML Statements in an Application Container

This example specifies that APDB1 is the default container for DML statements in the application container.

ALTER PLUGGABLE DATABASE CONTAINERS DEFAULT TARGET = (APDB1);

Example 17-14 Clearing the Default Container

This example clears the default container setting. When it is not set, the default container is the application root.

ALTER PLUGGABLE DATABASE CONTAINERS DEFAULT TARGET = NONE;

Parent topic: Issuing DML Statements on Containers in an Application Container

17.6 用带有容器映射的PDB分区

Container maps enable the partitioning of data at the application PDB level when the data is not physically partitioned at the table level.

This section contains the following topics:

  • About Container Maps
    container map is a database property that specifies a partitioned map table defined in an application root.
  • Creating a Container Map
    Create a container map by creating a map object and setting the CONTAINER_MAP database property to the map object.

Parent topic: Administering Application Containers

17.6.1 About Container Maps

container map is a database property that specifies a partitioned map table defined in an application root.

Use a container map to partition the data in metadata-linked objects. Container maps partition data in application PDBs based on a commonly-used column.

For example, you might create a metadata-linked table named countries_mlt (with a column cname) that stores different data in each application PDB. The map table named pdb_map_tblpartitions by list on the cname column. The partitions amer_pdbeuro_pdb, and asia_pdbcorrespond to the names of the application PDBs.

A container map can define a logical partition key on a column for a common object. Because the container is resolved internally based on the container map, this mapping removes the requirement to define a query with a CON_ID predicate or use the CONTAINERS clause in the query.

Some types of row-based consolidation use a tenant ID with a single PDB that contains multiple tenants. Container maps are useful for migrating to a configuration that uses a different PDB for each tenant.

This section contains the following topics:

Parent topic: Partitioning by PDB with Container Maps

17.6.1.1 Map Objects

The map object is the partitioned table.

The names of the partitions in the map table match the names of the application PDBs in the application container. The metadata-linked object is not physically partitioned at the table level, but it can be queried using the partitioning strategy used by the container map.

To associate the map table with the metadata-linked table, specify the map table in ALTER PLUGGABLE DATABASE ... CONTAINER_MAP while connected to the application root. You can create no more than one container map in an application container. You cannot create container maps in the CDB root.

Note:

  • Data must be loaded into the PDB tables in a manner that is consistent with the partitions defined in map object.

  • When there are changes to the application PDBs in an application container, the map object is not synchronized automatically to account for these changes. For example, an application PDB that is referenced in a map object can be unplugged, renamed, or dropped. The map object must be updated manually to account for such changes.

Starting in Oracle Database 18c, for a CONTAINERS() query to use a map, the partitioning column in the map table does not need to match a column in the metadata-linked table. Assume that the table sh.sales is enabled for the container map pdb_map_tbl, and cname is the partitioning column for the map table. Even though sh.sales does not include a cname column, the map table routes the following query to the appropriate PDB: SELECT * FROM CONTAINERS(sh.sales) WHERE cname = 'US' ORDER BY time_id.

Parent topic: About Container Maps

17.6.1.2 List-Partitioned Container Map: Example

This example uses a container map to route queries to PDBs that store data for a geographical region.

The following illustration of an application root shows a map object, a metadata-linked table, and a query on the metadata-linked table. The query is executed in the appropriate application PDB.

Figure 17-3 Container Map

Description of Figure 17-3 follows
Description of "Figure 17-3 Container Map"

The illustration shows an application container with three application PDBs named AMEREURO, and ASIA. The PDBs store data for the corresponding regions. A metadata-linked table named oe.cmtbstores information for an application. This table has a COUNTRY column. For this partitioning strategy, partition by list is used to create a map object that creates a partition for each region. The country value, which is GERMANY in the query shown in the illustration, determines the region, which is EURO.

See Also:

"Creating a Container Map" for a detailed description of this example

Parent topic: About Container Maps

17.6.1.3 Range-Partitioned Container Map: Example

This example uses a container map to route queries to PDBs that store data for a particular department.

Consider another example that uses a range-partitioned table for the map object. The following SQL statement creates the map object in the application root:

CREATE TABLE app_con_admin.conmap (
   department_id NUMBER NOT NULL)
PARTITION BY RANGE (department_id) (
PARTITION apppdb1 VALUES LESS THAN (100),
PARTITION apppdb2 VALUES LESS THAN (200),
PARTITION apppdb3 VALUES LESS THAN (300));

This map object partitions data in the application PDBs apppdb1apppdb2, and apppdb3 based on the commonly-used column department_id. The following SQL statement sets the CONTAINER_MAP database property to the app_con_admin.conmap table in the application root:

ALTER PLUGGABLE DATABASE SET CONTAINER_MAP='app_con_admin.conmap';

Queries that use container maps produce similar results to queries that use the CONTAINERS clause. For example, the following queries return similar results:

SELECT employee_id 
FROM   CONTAINERS(hr.employees) 
WHERE  department_id = 10 
AND    CON_ID IN (44); 

SELECT employee_id 
FROM   hr.employees 
WHERE  department_id = 10;

As shown in the first query with the CONTAINERS clause, when the query only pertains to a single application PDB, the query must specify the container ID of this application PDB in the WHERE clause. This requirement might cause application changes.

The second query uses the container map, replacing the CONTAINERS clause. The second query does not specify the container because the container map directs the query to the correct application PDB. Queries that use container maps are generally more efficient than queries that use the CONTAINERSclause.

The container map must be created by a common user with ALTER DATABASE system privilege. Queries run against an object that is enabled for container map. Query privileges are determined by privileges granted on the object.

Parent topic: About Container Maps

17.6.2 Creating a Container Map

Create a container map by creating a map object and setting the CONTAINER_MAP database property to the map object.

The map object is a partitioned table in which each partition name matches the name of an application PDB in an application container.

Prerequisites

To create a container map, you must meet the following prerequisites:

  • Before creating a container map, an application container with application PDBs must exist in the CDB.

  • The application container must have at least one application installed in it.

To create a container map:

  1. In SQL*Plus, ensure that the current container is the application root.

  2. Set the CONTAINER_MAP database property to the map object.

    In the following statement, replace map_table_schema with the owner of the table, and replace map_table_name with the name of the table:

    ALTER DATABASE SET CONTAINER_MAP =  'map_table_schema.map_table_name';
  3. Start an application installation, upgrade, or patch.

  4. If the metadata-linked table that will be used by the container map does not exist, then create it.

  5. Enable the container map for the table to be queried by issuing an ALTER TABLE ... ENABLE CONTAINER_MAP statement.

  6. Ensure that the table to be queried is enabled for the CONTAINERS clause by issuing an ALTER TABLE ... ENABLE CONTAINERS_DEFAULT statement.

  7. End the application installation, upgrade, or patch started previously.

Example 17-15 Creating and Using a Container Map

This example creates a simple application that uses a container map. Assume that an application container has three application PDBs named AMEREURO, and ASIA. The application PDBs store data for the different regions (America, Europe, and Asia, respectively). A metadata-linked table stores information for an application and has a COUNTRY column. For this partitioning strategy, partition by list is used to create a map object that creates a partition for each region, and the country value is used to determine the region.

  1. In SQL*Plus, ensure that the current container is the application root.

  2. Create the map object.

    CREATE TABLE salesadm.conmap (country VARCHAR2(30) NOT NULL)
    PARTITION BY LIST (country) (
      PARTITION AMER VALUES ('US','MEXICO','CANADA'),
      PARTITION EURO VALUES ('UK','FRANCE','GERMANY'),
      PARTITION ASIA VALUES ('INDIA','CHINA','JAPAN')
    );
    
  3. Set the CONTAINER_MAP database property to the map object.

    ALTER PLUGGABLE DATABASE SET CONTAINER_MAP='salesadm.conmap';
  4. Begin an application installation.

    ALTER PLUGGABLE DATABASE APPLICATION salesapp BEGIN INSTALL '1.0';
  5. Create a metadata-linked table that will be queried using the container map.

    CREATE TABLE oe.cmtb SHARING=METADATA (
      value   VARCHAR2(30),
      country VARCHAR2(30));
  6. Enable the container map for the table to be queried.

    ALTER TABLE oe.cmtb ENABLE CONTAINER_MAP;
  7. Ensure that the table to be queried is enabled for the CONTAINERS clause.

    ALTER TABLE oe.cmtb ENABLE CONTAINERS_DEFAULT;
  8. End the application installation.

    ALTER PLUGGABLE DATABASE APPLICATION salesapp END INSTALL '1.0';
  9. Switch session into each application PDB and synchronize it.

    ALTER SESSION SET CONTAINER=amer;
    ALTER PLUGGABLE DATABASE APPLICATION salesapp SYNC;
    
    ALTER SESSION SET CONTAINER=euro;
    ALTER PLUGGABLE DATABASE APPLICATION salesapp SYNC;
    
    ALTER SESSION SET CONTAINER=asia;
    ALTER PLUGGABLE DATABASE APPLICATION salesapp SYNC;
  10. Insert values into the oe.cmtb table in each application PDB based on the partitioning strategy.

    ALTER SESSION SET CONTAINER=amer;
    INSERT INTO oe.cmtb VALUES ('AMER VALUE','US');
    INSERT INTO oe.cmtb VALUES ('AMER VALUE','MEXICO');
    INSERT INTO oe.cmtb VALUES ('AMER VALUE','CANADA');
    COMMIT;
    
    ALTER SESSION SET CONTAINER=euro;
    INSERT INTO oe.cmtb VALUES ('EURO VALUE','UK');
    INSERT INTO oe.cmtb VALUES ('EURO VALUE','FRANCE');
    INSERT INTO oe.cmtb VALUES ('EURO VALUE','GERMANY');
    COMMIT;
    
    ALTER SESSION SET CONTAINER=asia;
    INSERT INTO oe.cmtb VALUES ('ASIA VALUE','INDIA');
    INSERT INTO oe.cmtb VALUES ('ASIA VALUE','CHINA');
    INSERT INTO oe.cmtb VALUES ('ASIA VALUE','JAPAN');
    COMMIT;
  11. Switch session into the application root and query the data using the container map.

    ALTER SESSION SET CONTAINER=sales;
    
    SELECT value FROM oe.cmtb WHERE country='MEXICO';
    
    SELECT value FROM oe.cmtb WHERE country='GERMANY';
    
    SELECT value FROM oe.cmtb WHERE country='JAPAN';

    The output for the first query should be AMER VALUE, the output for the second query should be EURO VALUE, and the output for the third query should be ASIA VALUE. These values illustrate that the container map is working correctly.

Parent topic: Partitioning by PDB with Container Maps

猜你喜欢

转载自blog.csdn.net/viviliving/article/details/84637407