【跟我学oracle18c】第二十二天:Multitenant :13 管理CDB(红色部分关键新知识点,关注一下rac部分即可)

        这个内容好多,看了好一阵子,都是一些普通的操作,就是

13.4.5.5 Starting and Stopping PDBs in Oracle RAC

中的一些内容是rac操作是需要注意的

 

13 管理cdb

管理多租户容器数据库(CDB)包括访问容器、修改CDB、执行DDL语句和运行oracle提供的SQL脚本等任务。

Note:

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

This chapter contains the following topics:

See Also:

"Tools for a Multitenant Environment"

Parent topic: Administering a Multitenant Environment

13.1 About CDB Administration

管理cdb与管理non-cdb类似,但有一些区别。

Most differences occur because some administrative tasks apply to the entire CDB, whereas others apply to specific containers.

This section contains the following topics:

Parent topic: Administering a CDB

13.1.1 关于当前容器

CDB中每个容器中的数据字典是独立的,当前容器是其数据字典用于名称解析和特权授权的容器。
当前容器可以是CDB根、应用程序根、PDB或应用程序PDB。每个会话在任何时间点都只有一个当前容器。但是,会话可以从一个容器切换到另一个容器。

在CDB中,每个容器都有惟一的ID和名称。您可以使用USERENV名称空间中的CON_ID和CON_NAMEparameters来使用SYS_CONTEXT函数确定当前容器ID和名称。例如,以下查询返回当前容器名称:

SELECT SYS_CONTEXT ('USERENV', 'CON_NAME') FROM DUAL;

您可以通过各种方式访问容器。例如,您可以使用SQL*Plus CONNECTcommand,还可以使用ALTER SESSION SET CONTAINER语句来切换当前会话的容器。

以下规则适用于CDB中的当前容器:

  • 当前容器可以是CDB$ROOT (CDB ROOT),仅供普通用户使用。
    当前容器可以是普通用户和本地用户的特定PDB。
    当前容器只能是普通用户或在应用程序根中创建的应用程序普通用户的应用程序根。

  • 当前容器可以是针对普通用户、应用程序普通用户和本地用户的特定应用程序PDB。

  • 当SQL语句包含container = ALL时,当前容器必须是CDB根或应用程序根。
    您可以在几个SQL语句中包含容器子句,例如CREATE USER、ALTER USER、CREATE ROLE、GRANT、REVOKE和ALTER SYSTEM语句。注意以下关于CONTAINER = ALL的规则:

    • 当SQL语句包含CONTAINER = ALL且当前容器是CDB根时,SQL语句将影响CDB中的所有容器,包括所有PDBs、应用程序根和应用程序PDBs。

    • 当SQL语句包含CONTAINER = ALL且当前容器是应用程序根时,SQL语句将影响应用程序容器中的所有容器,包括应用程序根和属于应用程序根的所有应用程序PDBs。SQL语句不影响CDB根或不属于当前应用程序根的任何PDBs或应用程序PDBs。

    • 只有具有通常授予的SET CONTAINER特权的公共用户或应用程序公共用户才能运行包含CONTAINER = ALL的SQL语句。

See Also:

Parent topic: About CDB Administration

13.1.2 关于CDB中的管理任务

普通用户为CDB执行管理任务。

普通用户只有一个身份,可以登录到CDB根、任何应用程序根、PDB或具有特权的应用程序PDB。有些任务,例如启动CDB实例,只能由普通用户执行。
对于CDB和非CDB,其他管理任务是相同的。下表描述了其中一些任务,并提供了指向相关文档的指针。

Table 13-1 Administrative Tasks Common to CDBs and Non-CDBs

Task Description Additional Information
启动一个CDB实例 要启动一个CDB实例,当前用户必须是一个公共用户,其当前容器是CDB根用户。
打开CDB时,会打开CDB根,但会挂载它的其他容器。使用ALTER PLUGGABLE数据库语句修改一个或多个容器的打开模式。

Oracle Database Administrator’s Guide for information about starting up a database

"Modifying the Open Mode of One or More PDBs"

"Modifying a PDB with the ALTER PLUGGABLE DATABASE Statement"

"About the Current Container"

管理 processes

CDB有一组由CDB根和所有容器共享的后台进程。

Oracle Database Administrator’s Guide for information about managing processes

  • 管理

memory

CDB具有单个系统全局区域(SGA)和单个聚合程序全局区域(PGA)。CDB所需的内存是作为CDB一部分的所有容器的内存需求的总和。

Oracle Database Administrator’s Guide for information about managing memory

  • 管理

security

您可以在CDB中创建和删除普通用户、应用程序普通用户和本地用户。您还可以向这些用户授予特权并从这些用户撤消特权。您还可以管理普通用户和应用程序普通用户的CONTAINER_DATA属性。
此外,向适当的用户授予下列角色:
将CDB_DBA角色授予CDB管理员。
将PDB_DBA角色授予应用程序容器管理员和PDB管理员。

Oracle Database Security Guide

监视错误和警报 对于整个CDB, CDB有一个警报日志。应用程序容器、PDB或应用程序PDB的名称在适当的时候包含在跟踪文件中的记录中。

Oracle Database Administrator’s Guide for information about monitoring errors and alerts

管理诊断数据 在CDB中,您可以使用Oracle数据库可诊断性基础设施和自动诊断存储库(ADR)。

Oracle Database Administrator’s Guide for information about managing diagnostic data

  • 控制文件的管理
CDB有一个控制文件。

Oracle Database Administrator’s Guide for information about managing control files

管理联机重做日志和归档的重做日志文件 CDB有一个联机重做日志和一组归档的重做日志文件。

Oracle Database Administrator’s Guide for information about managing the redo log

Oracle Database Administrator’s Guide for information about managing archived redo log files

管理表空间 您可以为CDB根目录和单个容器创建、修改和删除表空间和临时表空间。您还可以为CDB根目录指定默认表空间、默认表空间类型和默认临时表空间。CDB根目录有它自己的一组oracle提供的表空间,比如系统表空间,而其他容器有它们自己的一组oracle提供的表空间。

Oracle Database Administrator’s Guide for information about managing tablespaces

"About Container Modification When Connected to CDB Root"

管理数据文件和临时文件 CDB根目录有自己的数据文件,其他容器也有自己的数据文件。在CDB中,您可以管理数据文件和临时文件,其方式与管理非CDB文件的方式基本相同。然而,以下例外情况适用于CDBs:
通过在CREATE PLUGGABLE DATABASE或ALTER PLUGGABLE DATABASE语句中使用STORAGEclause,可以限制数据文件用于容器的存储量。
对于CDB根目录和单个容器,有一个默认的临时表空间。

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

"About Container Modification When Connected to CDB Root"

"Storage Limits"

"Modifying a PDB at the Database Level"

管理 undo

CDB可以在本地撤消模式或共享撤消模式下运行。本地撤销模式意味着CDB中的每个容器都使用本地撤销。共享撤销模式是指对于单个实例的CDB,或者对于Oracle RAC CDB,对于每个实例,都有一个活动的撤销表空间。
在CDB中,必须将undo_managementinitialize参数设置为AUTO,并且需要一个undo表空间来管理undo数据。

"Setting the Undo Mode in a CDB Using ALTER DATABASE"

Oracle Database Administrator’s Guide for information about managing undo

"About the Current Container"

在容器之间移动数据 您可以使用与在非cdbs之间移动数据相同的方法在容器之间移动数据。例如,您可以传输数据或使用数据泵导出/导入来移动数据

Oracle Database Administrator’s Guide for information about transporting data

Oracle Database Utilities

使用Oracle托管文件 使用Oracle托管文件可以简化对CDB和非CDB的管理。

Oracle Database Administrator’s Guide for information about using Oracle Managed Files

使用透明数据加密 透明数据加密是一种特性,它支持在将单个表列存储到数据文件之前进行加密,或者支持对整个表空间进行加密。在CDB中,每个容器都有自己用于透明数据加密的主密钥,并且在适用的情况下,管理员密钥管理SQL语句支持在CDB级别和单个容器上进行密钥管理。(这个高级啊

Oracle Database Advanced Security Guide

"About the Current Container"

使用备用数据库 Oracle Data Guard可以配置CDB的物理备用或逻辑备用。数据保护在整个CDB上运行,而不是在CDB中的单个容器上。

Oracle Data Guard Concepts and Administration

Using Oracle Database Vault

Oracle Database Vault公共领域可以限定到公共对象上的应用程序根目录。数据库库通用命令规则的作用域可以限定为CDB或应用程序根目录。本地领域和命令规则可以本地作用域到单个PDBs或应用程序PDBs。当Oracle数据库Vault安全对象位于CDB根目录或应用程序根目录中时,安全对象的实施仅适用于启用Oracle数据库Vault的容器。

Oracle Database Vault Administrator’s Guide

  • 删除数据库
当您删除一个CDB时,将删除CDB中的所有容器及其数据。这些容器包括CDB根和PDB种子以及所有应用程序容器、应用程序种子、PDBs和应用程序PDBs。
还可以使用可插入数据库estatement删除单个应用程序容器、应用程序种子、PDBs和应用程序PDBs。

Oracle Database Administrator’s Guide for information about dropping a database

"Dropping a PDB"

See Also:

"Overview of the Multitenant Architecture" for more information about the architecture of a CDB

Parent topic: About CDB Administration

13.1.3 关于在CDB中使用可管理性特性

对于CDB中的每个Oracle数据库的可管理性特性,了解数据位置和数据可见性非常重要。

为了实现CDB中的Oracle数据库的可管理性特性,理解数据存储在哪里非常重要。当某个特性的数据仅存储在CDB根目录中时,如果PDB未被插入,则不包括与PDB相关的数据。但是,当某个特性的数据存储在PDB中时,如果PDB未被插入,则包含与PDB相关的数据,如果将该数据插入相同的CDB或不同的CDB,则该数据仍然是PDB的一部分。

理解哪些数据对不同的用户是可见的也很重要。通常,在CDB中,当公共用户的当前容器是CDB根时,公共用户可以查看CDB根和多个PDBs的数据。普通用户可以通过查询容器数据对象来查看这些数据。可见的特定数据因可管理性特性而异。当前容器为PDB的用户只能查看该PDB的数据。

下表描述了可管理性特性在CDB中的工作方式。

Table 13-2 CDB中的可管理性特性

Manageability Feature Data Location Data Visibility Additional Information
活动会话历史(ASH)
ASH收集关于活动数据库会话的信息。您可以使用这些信息来分析和识别性能问题。
大部分ash数据存储在内存中。一小部分ash数据样本存储在CDB根目录中。
如果PDB未插拔,则不包含与PDB相关的ASH数据。

当前容器为CDB根的普通用户可以查看CDB根和PDBs的ASH数据。
当前容器为PDB的用户只能查看PDB的ASH数据.

Oracle Database 2 Day + Performance Tuning Guide

Oracle Database Performance Tuning Guide

警报
警告是对可能出现的问题的通知。
与PDB相关的阈值设置存储在PDB中。
当阈值被违反时发出的警报被排队到CDB根目录中的警报队列中。
如果PDB未被插入,则包含与PDB相关的阈值设置。如果PDB未插入,则不包含与PDB相关的警告。
当前容器为CDB根的普通用户可以查看CDB根和PDBs的警报。
当前容器为PDB的用户只能查看PDB的警报阈值和警报

Oracle Database Administrator’s Guidefor information about monitoring errors and alerts

自动化数据库维护任务
自动数据库维护任务是定期自动启动的任务,用于对数据库执行维护操作。自动化任务包括自动优化器统计信息收集、自动段顾问任务和自动SQL调优顾问任务。

ENABLE_AUTOMATIC_MAINTENANCE_PDB初始化参数可以为CDB中的所有pdb或CDB中的单个pdb启用或禁用自动维护任务的运行。
AUTOTASK_MAX_ACTIVE_PDBSinitialization参数限制可以同时(在维护窗口期间)调度自动维护任务的pdb数量。

用户可以调度维护窗口,并仅为当前容器启用或禁用维护任务。如果当前容器是CDB根,那么更改只应用于CDB根。如果当前容器是PDB,那么更改只适用于PDB。

与PDB相关的数据存储在PDB中,用于自动优化器统计信息收集和自动段顾问。如果PDB未插入,则包含此数据。
自动SQL调优顾问仅在CDB根目录中运行。有关自动SQL调优顾问收集的数据的信息,请参阅该表中的SQL调优顾问行。

有关以下可管理性特性的数据可见性信息,请参见表中的适当行:自动优化器统计信息收集、优化器统计信息顾问、自动段顾问和自动SQL调优顾问。

Oracle Database Administrator’s Guidefor information about managing automated database maintenance tasks

Oracle Database Reference for information about the ENABLE_AUTOMATIC_MAINTENANCE_PDB initialization parameter

Oracle Database Reference for information about the AUTOTASK_MAX_ACTIVE_PDBSinitialization parameter

自动数据库诊断监视器(ADDM)
ADDM可以诊断数据库的性能,并确定如何解决识别出的问题。

所有ADDM运行必须在CDB根目录中执行。所有ADDM结果都存储在CDB根目录中。
ADDM在当前分析目标上下文中分析PDB中的活动。ADDM不会一次分析一个PDB。与以前的版本一样,ADDM以整个实例或Oracle Real Application Clusters (Oracle RAC)数据库为目标运行。
如果PDB未被插入,则不包括与PDB相关的ADDM结果.

ADDM结果只对当前容器是CDB根目录的普通用户可见。ADDM结果可以包含关于多个pdb的信息。当当前容器为PDB时,无法查看ADDM结果。

Oracle Database 2 Day DBA

Oracle Database Performance Tuning Guide

自动优化器统计信息收集
自动优化器统计信息集合为数据库中没有统计信息或只有过时统计信息的所有模式对象收集优化器统计信息。SQL查询优化器使用此任务收集的统计信息来改进SQL执行的性能。
当自动优化器统计信息收集任务为PDB收集数据时,它将该数据存储在PDB中。如果PDB未插入,则包含此数据 当前容器为CDB根的普通用户可以查看PDBs的优化器统计数据。
当前容器为PDB的用户只能查看PDB的优化器统计数据。

"Using Oracle Resource Manager for PDBs"

Oracle Database SQL Tuning Guide

自动段顾问
自动段顾问识别有可用空间进行回收的段,并就如何对这些段进行碎片整理提出建议
当自动段Advisor为PDB收集数据时,它将这些数据存储在PDB中。如果PDB未插入,则包含此数据。 当前容器为CDB根的普通用户可以查看用于PDBs的自动段顾问数据。
当前容器为PDB的用户只能查看自动段顾问数据。

Oracle Database Administrator’s Guidefor information about reclaiming unused space

"Using Oracle Resource Manager for PDBs"

自动工作负载存储库(AWR)
AWR收集、处理和维护性能统计数据,用于问题检测和自调优。这些数据存储在数据库中。收集到的数据可以显示在报告和视图中。

AWR报告可以在CDB根目录或任何PDB中生成。在CDB根目录中生成的AWR报告属于整个CDB,而当PDB是当前容器时生成的AWR报告只属于该PDB。
在CDB根中生成的AWR数据存储在CDB根中。PDB中生成的AWR数据存储在PDB中

不插入PDB时,不包括存储在CDB根中的AWR数据。
当PDB被拔出时,将包括存储在PDB中的AWR数据。

当前容器为CDB根的普通用户可以查看CDB根和PDBs的AWR数据。
当前容器为PDB的用户只能查看PDB的AWR数据。

Oracle Database Performance Tuning Guide

数据库重放
数据库重播是Oracle Real应用程序测试的一个特性。数据库重播捕获数据库的工作负载,并在测试数据库上准确地重播它。(
这个研究一下,什么新东西

关于数据库捕获和回放的信息存储在CDB根目录中.

当前容器为CDB根的普通用户可以查看数据库捕获和重播信息。

Oracle Database Testing Guide

优化器统计顾问
优化器统计信息顾问分析如何收集统计信息,并建议可以对统计信息收集进行微调的更改
与PDB相关的数据存储在优化器统计信息顾问的PDB中。如果PDB未插入,则包含此数据。 当前容器为CDB根的普通用户可以查看用于PDBs的Optimizer Statistics Advisor数据。
当前容器为PDB的用户只能查看PDB的优化器统计信息顾问数据。

Oracle Database SQL Tuning Guide

SQL管理库(SMB)
SMB在数据字典中存储语句日志、计划历史记录、SQL计划基线和SQL概要文件。
与PDB相关的SMB数据存储在PDB中。如果PDB未插入,则包含与PDB相关的SMB数据 当前容器为CDB根的普通用户可以查看用于PDBs的SMB数据。
当前容器为PDB的用户只能查看PDB的SMB数据。

Oracle Database SQL Tuning Guide

SQL性能分析器(SPA)
SPA可以分析SQL调优和其他系统更改对SQL性能的影响。SPA通常与数据库重播一起使用。
当前容器为CDB根的普通用户可以为任何PDB运行SPA。在这种情况下,SPA结果数据存储在CDB根目录中,如果PDB未被插入,则不包含这些数据。
当前容器为PDB的用户可以在PDB上运行SPA。在这种情况下,SPA结果数据存储在PDB中,如果PDB未被插入,就会包含这些数据。
当前容器为CDB根的普通用户可以查看PDBs的SPA结果数据。
当前容器为PDB的用户只能查看PDB的SPA结果数据。

Oracle Database Testing Guide

SQL调优集(STS)
STS是一个数据库对象,它包含一个或多个SQL语句及其执行统计信息和执行上下文,并且可以包含用户优先级排序。
您可以使用STS优化一组SQL语句,或者使用SPA测试它们的性能。
STS可以存储在CDB根目录或任何PDB中。如果它存储在CDB根目录中,那么可以从任何PDB中加载SQL语句。
不插入PDB时,不包括存储在CDB根中的STS,即使STS包含来自PDB的SQL语句。
当PDB被拔掉时,PDB中存储的STS也被包括在内。
当前容器为CDB根的普通用户只能查看存储在CDB根中的STS数据。
当前容器为PDB的用户只能查看PDB的STS数据。

Oracle Database SQL Tuning Guide

SQL调优顾问
SQL调优顾问优化已被标识为高负载SQL语句的SQL语句。

自动SQL调优Advisor数据存储在CDB根目录中。它可能包含由advisor分析的在PDB中执行的SQL语句的结果,但是如果PDB未被插入,则不包括这些结果。
当前容器是CDB根目录的普通用户可以为来自任何PDB的SQL语句手动运行SQL调优顾问。调优语句时,将在运行该语句的任何容器中对其进行调优。

当前容器为PDB的用户还可以手动为PDB中的SQL语句运行SQL调优顾问。当从PDB手动运行SQL调优顾问时,结果存储在运行它的PDB中。在这种情况下,语句只针对当前PDB进行优化,如果PDB未被插入,则会包含与PDB相关的结果。

当SQL调优顾问自动运行时,结果只对当前容器是CDB根目录的普通用户可见。当当前容器为PDB时,无法查看这些结果。
当SQL调优顾问由当前容器为PDB的用户手动运行时,结果只对当前容器为该PDB的用户可见。

Oracle Database 2 Day + Performance Tuning Guide

Oracle Database SQL Tuning Guide

要为来自PDB的SQL语句运行SPA或SQL调优顾问,公共用户必须具有以下特权:

  • PDB中的公共集容器特权或本地集容器特权

  • 在PDB中执行SQL语句所需的特权

See Also:

Parent topic: About CDB Administration

13.1.4 关于在CDB中管理表空间

表空间是消耗存储空间的数据库对象(如表和索引)的逻辑存储容器。
在物理级别,表空间将数据存储在一个或多个数据文件或临时文件中。您可以使用ALTER DATABASE语句来管理CDB中的表空间。

下面是表空间的注意事项in a CDB:

  • 永久表空间可以只与一个容器关联

  • 在容器中创建表空间时,表空间与该容器关联。

  • 当本地撤销对CDB禁用时,CDB对于Oracle RAC CDB的每个实例只有一个活动的撤销表空间,或者只有一个活动的撤销表空间。当为CDB启用本地撤销时,CDB中的每个容器都有自己的撤销表空间。

  • 在打开PDB的Oracle Real Application Clusters (Oracle RAC)集群中,每个节点都需要一个本地undo表空间。

  • 在CDB中,每个容器都有一个默认的临时表空间,包括CDB根、每个PDB、每个应用程序根和每个应用程序PDB。

This section contains the following topics:

Parent topic: About CDB Administration

13.1.4.1 关于管理CDB中的永久表空间

永久表空间只能与一个容器关联。因此,一个永久表空间可以与根表空间相关联,也可以与一个PDB相关联。
CDB中的每个容器必须有自己的默认永久表空间,并且在容器之间不能共享默认的永久表空间。未显式分配表空间的连接到容器的用户使用容器的默认永久表空间。

Parent topic: About Managing Tablespaces in a CDB

13.1.4.2 关于管理CDB中的临时表空间

CDB中的每个容器都有自己的默认临时表空间(或表空间组)。
您还可以为单个容器创建额外的临时表空间,并且可以将容器中的特定用户分配给这些临时表空间。当您拔掉PDB时,它的临时表空间也会被拔掉。
当用户没有在容器中显式地分配临时表空间时,用户的临时表空间是容器的默认临时表空间。

See Also:

Parent topic: About Managing Tablespaces in a CDB

13.1.5关于管理CDB中的数据库对象

在CDB中,不同的容器可以包含不同的数据库对象。
Oracle数据库存储数据库对象,例如表、索引和目录。属于模式的数据库对象称为模式对象,而不属于模式的数据库对象称为非模式对象。根和pdb包含模式,模式包含模式对象。根目录和PDBs还可以包含非模式对象,例如用户、角色、表空间、目录和版本。

在CDB中,根包含oracle提供的模式和数据库对象。oracle提供的公共用户,如SYS和SYSTEM,拥有这些模式和公共数据库对象。它们还可以拥有根目录和PDB中的本地对象。
您可以在根目录中创建公共用户来管理CDB中的容器。用户创建的普通用户可以在根目录中创建数据库对象。Oracle建议,在根目录中,由用户创建的普通用户拥有的模式只包含数据库触发器及其定义中使用的对象。用户创建的公共用户也可以拥有任何类型的本地对象

您可以在PDB中创建本地用户。PDB中的本地用户可以在PDB中创建模式对象和非模式对象。不能在根目录中创建本地用户。
CDB中的名称解析类似于非CDB中的名称解析,只不过名称是在用户当前容器的字典上下文中解析的。

See Also:

Parent topic: About CDB Administration

13.1.6 关于闪回一个PDB

可以使用FLASHBACK可插拔数据库语句将PDB返回到过去的时间或系统更改号(SCN)。
您可以为PDB创建恢复点,并将PDB闪回到恢复点,而不会影响CDB或其他PDBs。

Note:

Oracle Database Backup and Recovery User’s Guide

Parent topic: About CDB Administration

13.1.7 关于限制PDB用户以增强安全性

为了增强安全性,有几种方法可以限制PDB用户。
PDB锁定配置文件限制PDB中用户可用的特性和选项。PDB_OS_CREDENTIAL初始化参数可以为PDB指定惟一的操作系统用户,以限制操作系统访问。此外,当在PDB创建期间指定PATH_PREFIX和CREATE_FILE_DEST子句时,它们会限制文件系统访问。(
这个高级!!!

This section contains the following topics:

  • PDB Lockdown Profiles
    When identities are shared between PDBs, elevated privileges might exist. You can use lockdown profiles to prevent this elevation of privileges.
  • The PDB_OS_CREDENTIAL Initialization Parameter
    When the database accesses an external procedure with the extproc agent, the PDB_OS_CREDENTIAL initialization parameter determines the identity of the operating system user employed when interacting with the operating system from a PDB.
  • The PATH_PREFIX and CREATE_FILE_DEST PDB Creation Clauses
    The PATH_PREFIX clause of CREATE PLUGGABLE DATABASE ensures that all directory object paths associated with the PDB are restricted to the specified directory or its subdirectories.

Parent topic: About CDB Administration

13.1.7.1 PDB Lockdown Profiles

当身份在pdb之间共享时,可能存在提升的特权。您可以使用锁定配置文件来防止特权的提升。
身份可以在以下情况下共享:

  • 在操作系统级别,当数据库与操作系统资源(如文件或进程)交互时
    在网络级,当数据库与其他系统通信时
    在数据库内部,当PDBs访问或创建公共对象或使用数据库链接等功能跨容器边界通信时

为了提高安全性,CDB管理员可以使用PDB锁定配置文件来限制特定的PDB用户。PDB锁定配置文件可以禁用用户运行指定的SQL语句,如ALTER SYSTEM语句,或者禁用对可以访问网络的包的访问,如UTL_SMTP。PDB锁定配置文件还可以限制对普通用户、普通对象、管理工具(如Oracle XML DB)、管理特性(如游标共享)和数据库选项(如Oracle数据库高级队列)的访问。PDB锁定配置文件可以禁止具有XDB_PROTOCOLS特性的PDB使用XDB协议(FTP、HTTP、HTTPS)。

当登录到CDB根目录或应用程序根目录时,通过发出create lockdown profile语句创建一个锁定配置文件,该语句支持以下可选条款:

  • 通过使用现有概要文件中的值,从static_base_profile创建一个新的锁定概要文件。对现有概要文件的任何后续更改都不会影响新概要文件。

  • 包含dynamic_base_profile通过使用现有概要文件中的值创建一个新的锁定概要文件,但是这个新的锁定概要文件继承了包含基本概要文件的DISABLE语句规则,以及对基本概要文件的任何后续更改。

发出该语句的用户必须在当前容器中具有CREATE LOCKDOWN PROFILE system特权。您可以使用ALTER LOCKDOWN PROFILEstatement添加和删除限制。用户必须在CDB根或应用程序根中发出ALTER语句,并且必须在当前容器中拥有have ALTER LOCKDOWN概要文件系统特权。
使用PDB_LOCKDOWN初始化参数指定一个锁定配置文件。该参数确定PDB锁定配置文件是否适用于给定的PDB。您可以在以下级别设置此参数:

  • PDB
    配置文件仅适用于设置它的PDB。

  • 应用程序容器
    该概要文件适用于应用程序容器中的所有应用程序pdb。只有具有应用程序公共SYSDBA或公共ALTER系统特权的应用程序公共用户或具有公共SYSDBA或公共ALTER系统特权的CDB公共用户才能修改该值。

  • CDB

    该概要文件适用于所有PDBs。具有公共SYSDBA或公共ALTER SYSTEM特权的公共用户可以覆盖特定PDB的整个cdb设置。

如果PDB中的PDB_LOCKDOWN参数被设置为与此PDB (CDB或应用程序容器)的容器不同的锁定配置文件的名称,那么一组规则将控制限制之间的交互。

See Also:

Parent topic: About Restricting PDB Users for Enhanced Security

13.1.7.2 PDB_OS_CREDENTIAL初始化参数

当数据库使用extproc代理访问外部过程时,PDB_OS_CREDENTIAL初始化参数确定从PDB与操作系统交互时使用的操作系统用户的身份。

使用凭据描述的操作系统用户(凭据的名称指定为pdb_os_凭据初始化参数的值)可以确保操作系统交互作为功能较弱的用户执行。通过这种方式,该特性保护属于一个PDB的数据不被连接到另一个PDB的用户访问。凭据是使用dbms_凭据包中的create_凭据过程创建的对象。

Oracle OS用户通常是高度特权用户。不建议将此帐户用于操作系统交互。此外,使用相同的OS用户进行来自不同PDBs的操作系统交互可能会损害属于给定PDB的数据。

See Also:

Parent topic: About Restricting PDB Users for Enhanced Security

13.1.7.3 The PATH_PREFIX and CREATE_FILE_DEST PDB Creation Clauses

CREATE PLUGGABLE DATABASE的PATH_PREFIX子句确保与PDB关联的所有目录对象路径都限制在指定目录或其子目录中。
PATH_PREFIX还确保与PDB关联的以下文件被限制在指定目录下:

  • 用于PDB的Oracle XML存储库
    使用CREATE PFILE语句创建的文件
    Oracle钱包的导出目录
    使用CREATE Library语句创建的库对象

Note:

库必须使用目录对象。如果PDB使用预定义的PATH_PREFIX,尝试使用不使用目录对象的库对象将导致ORA-65394错误。库对象没有无效,但是要使其可用,必须使用目录对象重新创建它。

CREATE PLUGGABLE DATABASE语句的CREATE_FILE_DEST子句确保属于PDB的所有数据库文件都限制在指定目录及其子目录中。子句为PDB启用Oracle托管文件,并为PDB文件指定默认文件系统目录或Oracle ASM磁盘组。

See Also:

Parent topic: About Restricting PDB Users for Enhanced Security

13.1.8 Oracle多租户与Oracle RAC的概述

Oracle Multitenant是Oracle Database 12c的一个选项,它简化了整合、供应、升级等。
它基于允许多租户容器数据库(CDB)保存几个可插入数据库(PDBs)的体系结构。您可以采用现有数据库作为PDB,而不必更改应用层。在这个体系结构中,Oracle RAC提供了本地高可用性,这是在一个系统上整合各种关键业务应用程序时所必需的。

在与Oracle RAC一起使用PDBs时,多租户CDB基于Oracle RAC。可以在Oracle RAC CDB的每个实例或实例的一个子集上提供每个PDB。在这两种情况下,对PDBs的访问和管理都是使用动态数据库服务进行管理的,应用程序也将使用动态数据库服务连接到各自的PDB,就像在使用Oracle Net服务进行连接的单个实例Oracle数据库中一样。

您可以隔离PDB,以防止在特定PDB上或在特定PDB内执行某些操作,这些操作可能会干扰共享相同Oracle RAC数据库或数据库实例的其他PDB。PDB隔离允许使用Oracle Multitenant进行更高程度的整合。

如果您将Oracle RAC数据库作为CDB创建,并将一个或多个PDBs插入CDB,那么,默认情况下,PDB不会在Oracle RAC CDB的任何实例上自动启动。使用分配给PDB的第一个动态数据库服务(与数据库名称相同的默认数据库服务不同),PDB可以在服务运行的那些实例上使用。

无论一个PDB在Oracle RAC CDB的多个实例上是否可用,CDB通常由运行在PDB上的服务来管理。您可以通过在Oracle RAC CDB的每个实例上手动启动PDB来手动启用PDB访问

Related Topics

Parent topic: About CDB Administration

13.2 访问CDB中的容器

您可以使用SQL*Plus connect命令连接到容器。或者,您可以使用ALTER SESSION SET container SQL语句切换到容器。

Note:

You can also log in using Oracle Enterprise Manager Cloud Control (Cloud Control). See "Logging into a Multitenant Environment in Enterprise Manager".

This section contains the following topics:

Parent topic: Administering a CDB

13.2.1 About Container Access in a CDB

可以使用SQL*Plus访问CDB中的根或PDB。

Note:

This section assumes that you understand how to connect to a non-CDB in SQL*Plus.

This section contains the following topics:

See Also:

Parent topic: Accessing Containers in a CDB

13.2.1.1 Services in a CDB

客户端通过数据库服务访问根目录或PDB。
数据库服务有一个可选的PDB属性。创建PDB时,将自动创建PDB的新默认服务。服务的名称与PDB相同。使用服务名称,您可以使用easy connect语法访问PDB,也可以使用tnsnames.orafile中的net服务名称访问PDB。必须正确配置Oracle Net服务,以便客户机访问此服务。

当用户使用具有非null PDB属性的服务连接时,用户名将在指定的PDB上下文中解析。当用户连接时不指定服务或使用带有null PDB属性的服务名称时,用户名将在根上下文中解析。您可以通过查询CDB_SERVICES数据字典视图或在SRVCTL实用程序中运行配置服务命令来查看服务的PDB属性。

Note:

当同一计算机系统上的两个或多个cdb使用相同的侦听器,而两个或多个pdb在这些cdb中具有相同的服务名称时,指定此服务名称的连接将随机连接到具有该服务名称的其中一个pdb。为了避免错误的连接,请确保PDBs的所有服务名称在计算机系统上是惟一的,或者为计算机系统上的每个CDB配置一个单独的侦听器。

See Also:

Parent topic: About Container Access in a CDB

13.2.1.2 CDB中的会话限制

会话初始化参数的设置限制了CDB中可用的会话总数,包括连接到PDBs的会话。
如果达到了CDB的限制,那么用户就不能连接到PDBs。为了确保一个PDB不会使用太多会话,可以通过在PDB中设置会话初始化参数来限制PDB可用的会话数量。

See Also:

"Listing the Modifiable Initialization Parameters in PDBs"

Parent topic: About Container Access in a CDB

13.2.1.3 多租户环境中的用户名

在每个PDB中,用户名必须相对于该PDB中的其他用户名和角色是唯一的。

Note the following restrictions:

  • 对于本地用户名,名称不能以c##(或c##)开头

  • 用户和角色不能有相同的名称。

Related Topics

Parent topic: About Container Access in a CDB

13.2.1.4 多租户选项如何影响管理用户的密码文件

在多租户环境中,本地和公共管理用户的密码信息存储在不同的位置。

  • 对于CDB管理用户:在CDB根目录中授予管理权限的CDB普通管理用户的密码信息(密码散列)存储在密码文件中。

  • 对于在CDB根目录之外被授予管理特权的CDB中的所有用户:要查看这些用户的密码散列信息,查询$PWFILE_USERS动态视图。

Related Topics

Parent topic: About Container Access in a CDB

13.2.2 访问CDB中的容器

通过发出CONNECT或ALTER会话命令,使用SQL*Plus访问CDB中的容器。

This section contains the following topics:

Parent topic: Accessing Containers in a CDB

13.2.2.1 使用SQL*Plus CONNECT命令连接到容器

您可以使用SQL*Plus CONNECT命令连接到根目录或PDB。

This section contains the following topics:

Parent topic: Accessing a Container in a CDB

13.2.2.1.1 使用SQL*Plus CONNECT命令连接到根目录

您可以以与非cdb连接相同的方式连接到根目录。

具体来说,您可以使用以下技术连接到根与SQL*Plus CONNECTcommand:

  • Local connection

  • Local connection with operating system authentication

  • Database connection using easy connect

  • Database connection using a net service name

  • Remote database connection using external authentication

连接到根目录的用户必须满足以下先决条件:

  • The user must be a common user.

  • The user must be granted CREATE SESSION privilege in the root.

使用SQL*Plus connect命令连接到根目录:

  1. Configure your environment so that you can open SQL*Plus.

  2. Start SQL*Plus with the /NOLOG argument:

    sqlplus /nolog
    
  3. Issue a SQL*Plus CONNECT command to connect to the root, as shown in the following examples.

Example 13-1使用本地连接连接到根目录

这个示例作为用户系统连接到本地CDB中的根。SQL*加上提示输入系统用户密码。

connect system

Example 13-2 使用操作系统身份验证连接到根目录

本例使用具有操作系统身份验证的SYSDBA管理特权本地连接到根目录。

connect / as sysdba

Example 13-3 Connecting to the Root with a Net Service Name

假设客户端被配置为具有用于CDB中的根的网络服务名称。例如,net服务名可以是tnsnames中的条目的一部分。ora文件。
这个示例作为普通用户c##dba连接到由网络服务名称mycdb指定的数据库服务。SQL*加上c##dba用户密码提示。

connect c##dba@mycdb

See Also:

Oracle Database Administrator’s Guide for information about submitting commands and SQL to the database

Parent topic: Connecting to a Container Using the SQL*Plus CONNECT Command

13.2.2.1.2 使用SQL*Plus CONNECT命令连接到PDB

  1. sqlplus /nolog
    
CONNECT sh@salespdb

The following command connects to the SYSTEM common user in the salespdb PDB:

CONNECT system@salespdb

See Also:

Oracle Database Administrator’s Guide for information about submitting the SQL*Plus CONNECTcommand

Parent topic: Connecting to a Container Using the SQL*Plus CONNECT Command

13.2.2.2 Switching to a Container Using the ALTER SESSION Statement

当您作为普通用户连接到容器时,可以使用ALTER SESSION语句切换到不同的容器和应用程序服务。

您可以使用以下语句切换到不同的容器和应用程序服务:

ALTER SESSION SET CONTAINER = container_name [SERVICE = service_name]

For container_name, specify one of the following:

  • CDB$ROOT to switch to the CDB root

  • PDB$SEED to switch to the PDB seed

  • A PDB name to switch to the PDB

    When the current container is the root, you can view the names of the PDBs in a CDB by querying the DBA_PDBS view.

对于service_name,指定在PDB中运行的服务。您可以将运行在CDB容器中的服务(不包括CDB根)列出,方法是发出以下查询,将CDB根作为当前容器:

COL NAME FORMAT A30
COL CON_NAME FORMAT A20

SELECT NAME,CON_NAME, CON_ID
  FROM V$ACTIVE_SERVICES
  WHERE UPPER(NAME) != CON_NAME
  AND CON_ID !=1
  ORDER BY CON_ID;

默认情况下,当您切换到容器时,会话将使用容器的默认服务。但是,默认PDB服务不支持所有服务属性和特性,例如服务度量、快速应用程序通知(FAN)、负载平衡、资源管理器、事务保护、应用程序连续性等等。最佳实践是通过指定service = service_name来为容器使用非默认服务,其中service_name是服务的名称。

有了这个新功能,连接池可以切换服务,如果需要PDB,还可以在从池中借用连接时在连接上切换服务。从Oracle Database 12c Release 2(12.2.0.1)开始,连接池使用通用连接池(UCPs)支持多个数据库服务。它也可以独立使用。(这个可以java开发试试了,好多架构师可以爽一下了,是不是一个connect 里面动态运行altrer session切换即可

在切换到服务时,应用程序可以合并到CDB,同时保持数据库服务的标识、优先级、度量和高可用性。切换到非默认服务提供了以下好处:

  • It preserves the service attributes and features.

  • It eliminates too many connection pools with too many connections serving these tenants.

  • It allows applications to use more database services for workload control without consuming too many connection pools. Customers can identify and prioritize workloads using services without over sizing the database connections.

以下是使用ALTER SESSION SET容器语句的注意事项:

  • 语句成功完成后,会话的当前模式被设置为指定容器中的公共用户所拥有的模式。

  • 语句成功完成后,安全上下文被重置为指定容器中公共用户拥有的模式的安全上下文。

  • 语句成功完成后,指定容器的登录触发器不会触发。
    如果需要触发器,那么可以在PDB中定义一个在执行ALTER SESSION SET CONTAINER语句之前或之后触发的SET容器触发器。

  • 语句成功完成并服务子句为PDB指定了一个非默认服务之后,会话将使用一个新服务,该服务设置了属性,包括新服务的指标、FAN、TAF、应用程序连续性、事务保护、漏出_timeout和stop_option。

  • 包状态不会跨容器共享。

  • 在关闭PDB时,转换到PDB的会话和直接连接到PDB的会话处理方式相同。

  • 事务不能跨多个容器。如果启动事务并使用ALTERSESSION SET容器切换到另一个容器,那么在切换回启动事务的容器之前,不能发出DML、DDL、COMMIT或ROLLBACK语句。

  • 如果打开游标并使用ALTER SESSION SET容器切换到不同的容器,那么在切换回打开游标的容器之前,不能从该游标获取数据。

  • 您可以使用ALTER SESSION SET CONTAINER语句和SERVICE子句连接池,以及高级CDB管理。

    例如,您可以将此语句用于与用于多租户应用程序的PDBs连接池。多租户应用程序在服务器上使用软件的单个实例来服务多个客户(租户)。在非cdb中,多租户通常通过向应用程序使用的每个表添加一个额外的列来支持,该列标识租户,租户从连接池签出连接。在使用PDBs的CDB中,每个租户都可以拥有自己的PDB,并且可以在连接池配置中使用ALTER SESSION SET CONTAINER语句。

  • 在使用服务于应用程序的连接池时,应用程序可能使用具有不同服务的数据源。使用带有服务子句的ALTER SESSION SET CONTAINER语句,可以使连接池对许多应用程序使用相同的连接,从而共享服务。

要使用ALTER SESSION SET CONTAINERstatement,必须满足以下先决条件:

  • 当前用户必须是普通用户。初始连接必须使用SQL*Plus CONNECT命令。

  • 当将会话更改为作为普通用户(Oracle数据库未提供此用户)切换到PDB时,必须通常授予当前用户SET容器特权,或者必须在PDB中本地授予此特权。

Note:

当使用ALTER SESSION SET CONTAINER语句切换到当前容器时,不强制执行这些先决条件,如果不满足这些条件,则不返回错误消息。

在发布带有SERVICE子句的ALTER SESSION SET CONTAINER语句之前,必须满足以下先决条件:

  • 被切换到的服务必须是活动的。您不能切换到不运行的服务。

  • 在服务之间切换时,被切换的服务和被切换的服务的服务属性必须匹配。例如,从和切换到的服务必须都具有TAF,或者必须都使用应用程序连续性,或者必须都设置了drain_timeout。

使用ALTER SESSION语句切换到容器:

  1. In SQL*Plus, connect to a container as a common user with the required privileges.

  2. 检查正在切换到的容器的当前打开模式。
    若要检查根或PDB的当前打开模式,请在V$CONTAINERS视图中查询当前容器为根时的OPEN_MODE列。
    如果需要更改根的打开模式,那么请按照Oracle Database Administrator 's Guide中的说明更改数据库可用性以更改打开模式。
    如果需要更改PDB的打开模式,请按照“修改一个或多个PDBs的打开模式”中的说明更改打开模式。

    根的开放模式对PDBs的开放模式施加了限制。例如,在打开任何PDBs之前,根必须是打开的。因此,在更改PDB的打开模式之前,可能需要更改根的打开模式。

  3. 如果您要切换到特定的服务,那么请确保服务正在运行。
    要检查服务的活动状态,请在当前容器是CDB根目录时查询V$ACTIVE_SERVICES视图。
    如果服务没有运行,那么使用SRVCTL实用程序或DBMS_SERVICE包启动服务。

  4. 运行ALTER SESSION SET CONTAINER语句并指定要切换到的容器。
    包含服务子句以切换到特定的应用程序服务。

下面的示例使用ALTER SESSION切换到各种容器。

Example 13-5 Switching to the PDB salespdb and Using the salesrep Service

ALTER SESSION SET CONTAINER = salespdb SERVICE = salesrep;

Example 13-6 Switching to the PDB salespdb and Using the Default Service

ALTER SESSION SET CONTAINER = salespdb;

Example 13-7 Switching to the CDB Root

ALTER SESSION SET CONTAINER = CDB$ROOT;

Example 13-8 Switching to the PDB Seed

ALTER SESSION SET CONTAINER = PDB$SEED;

Example 13-9 使用CDB根目录中的虚拟服务切换服务

要设计切换容器和服务的连接池,一种方法是在CDB根中创建一个虚拟服务,并在这个虚拟服务上设置所有必需的服务属性(例如,沥干_timeout、TAF或应用程序连续性)。服务属性必须跨CDB根和PDB匹配。要使用此方法,请完成以下步骤:

  1. 在首次创建连接池和创建新连接时连接到虚拟服务。

  2. 当服务被添加到每个PDB时,在这些实际服务上设置相同的属性。
    当应用程序需要连接时,完成以下操作之一:

    • 创建到虚拟服务的新连接,并切换到PDB和服务。

    • 在池中借用一个空闲连接并切换到PDB和服务。
      在切换到PDBs时,不需要返回到CDB根目录

在切换到PDBs时,不需要返回到CDB根目录。

See Also:

Parent topic: Accessing a Container in a CDB

13.3 Modifying a CDB at the System Level

可以在CDB级别设置初始化参数。在某些情况下,您可以在PDB级别覆盖这些参数。

This section contains the following topics:

Parent topic: Administering a CDB

13.3.1关于CDB的系统级修改

ALTER SYSTEM SET语句动态地在一个或多个容器中设置一个初始化参数。
CDB对初始化参数使用继承模型,其中PDBs从根节点继承初始化参数值。在这种情况下,继承意味着根中的特定参数的值应用于特定的PDB。

PDB可以覆盖某些参数的根设置。在这种情况下,PDB对每个初始化参数都有一个继承属性,该属性要么为真,要么为假。当PDB继承该参数的根值时,该继承属性对于该参数为true;否则,属性为false。

某些参数的继承属性必须为true。对于其他参数,当当前容器是PDB时,您可以通过运行ALTER SYSTEM SETstatement来更改继承属性。如果V SYSTEM_PARAMETER美元。ispdb_modiatable对于初始化参数为真,那么该参数的继承属性可能为假。

当当前容器为根时,ALTER SYSTEM SETstatement的container子句控制哪些PDBs继承要设置的参数值。container子句具有以下语法:

CONTAINER = { CURRENT | ALL }

The following settings are possible:

  • CURRENT

    The parameter setting applies only to the current container. This is the default setting for CONTAINER. When the current container is the root, the parameter setting applies to the root and to any PDB with an inheritance property of true for the parameter.

  • ALL

    The parameter setting applies to all containers in the CDB, including the root and all PDBs. Specifying ALL sets the inheritance property to true for the parameter in all PDBs.

See Also:

"About the Current Container" for more information about the CONTAINER clause and rules that apply to it

Parent topic: Modifying a CDB at the System Level

13.3.2 Modifying a CDB with ALTER SYSTEM

要在系统级修改CDB,请使用ALTER system语句。

  • 前提条件

当前用户必须具有通常授予的ALTER SYSTEM特权。

在CDB根目录中使用ALTER SYSTEM SET:

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

  2. Run the ALTER SYSTEM SET statement.

Note:

若要将PDB中的参数的继承属性从false更改为true,请运行ALTER SYSTEM RESET语句,以便在当前容器为PDB时重置该参数。下面的示例语句重置OPEN_CURSORS参数:

ALTER SYSTEM RESET OPEN_CURSORS SCOPE = SPFILE;

Example 13-10 为所有容器设置初始化参数

这个ALTER SYSTEM SET语句将所有容器的OPEN_CURSORS初始化参数设置为200,并将每个PDB中的继承属性设置为TRUE

ALTER SYSTEM SET OPEN_CURSORS = 200 CONTAINER = ALL;

Example 13-11 为根设置初始化参数

这个ALTER SYSTEM SET语句将根目录和PDBs的OPEN_CURSORS初始化参数设置为200,参数的继承属性为true。

ALTER SYSTEM SET OPEN_CURSORS = 200 CONTAINER = CURRENT;

See Also:

Parent topic: Modifying a CDB at the System Level

13.4 Modifying Containers When Connected to the CDB Root

您可以使用ALTER DATABASE语句修改整个CDB或根目录。

This section contains the following topics:

Parent topic: Administering a CDB

13.4.1 关于连接到CDB根目录时的容器修改

ALTER数据库语句修改CDB。当您连接到CDB根目录时,ALTER PLUGGABLE数据库语句可以修改一个或多个PDBs的打开模式。

ALTER数据库和ALTER PLUGGABLE数据库的行为取决于使用语句时连接到哪个容器:

  • Connected as a common user to CDB root

    在这种情况下,ALTER数据库语句的工作方式与在非cdb中相同。当带有RENAME GLOBAL_NAME子句的ALTER数据库语句修改CDB的域时,它会影响每个PDB的域,其中的域默认为CDB的域。带有pdb_change_state子句的ALTER PLUGGABLE数据库语句修改一个或多个PDBs的打开模式。

  • Connected to a PDB

    在这种情况下,ALTER数据库和ALTER PLUGGABLE数据库语句只修改当前PDB。

下表列出了哪些容器是由ALTER DATABASE和ALTER PLUGGABLE DATABASE语句中的子句修改的。

Table 13-3 Statements That Modify Containers in a CDB

Modify Entire CDB Modify Root Only Modify One or More PDBs

当以当前容器为根用户的普通用户连接时,使用以下子句修改DATABASEstatements修改整个CDB:

当以当前容器为根用户的普通用户连接时,使用以下子句修改DATABASEstatements只修改根用户:

使用以下子句修改根目录并设置PDBs的默认值:

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

当作为一个当前容器是根用户的普通用户连接时,用下面的子句修改可插入的DATABASEstatements可以修改一个或多个PDBs的open模式:

当当前容器是PDB时,使用这个子句修改可插入数据库语句可以修改当前PDB的打开模式。
当以当前容器为根用户的普通用户连接时,使用以下子句更改可插拔的DATABASEstatements可以在CDB重启时保留或丢弃PDB的打开模式:

See Also:

Parent topic: Modifying Containers When Connected to the CDB Root

13.4.2 使用ALTER数据库修改整个CDB

您可以使用ALTER DATABASE语句修改整个CDB,包括根目录和所有PDBs。大多数ALTER数据库语句都会修改整个CDB。

For a list of statements that modify the entire CDB rather than the root or individual PDBs, see the "Modify Entire CDB" column of "About Container Modification When Connected to CDB Root".

Prerequisites

To modify an entire CDB, the following prerequisites must be met:

  • The current user must be a common user with the ALTER DATABASE privilege.

  • To use an ALTER DATABASE statement with a recovery_clause, the current user must have the SYSDBA administrative privilege commonly granted. In this case, you must exercise this privilege using AS SYSDBA at connect time.

To modify an entire CDB:

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

  2. Use an ALTER DATABASE statement with a clause that modifies an entire CDB.

Example 13-12 为CDB备份控制文件

The following ALTER DATABASE statement uses a recovery_clause to back up a control file.

ALTER DATABASE BACKUP CONTROLFILE TO '+DATA/dbs/backup/control.bkp';

Example 13-13 Adding a Redo Log File to a CDB

The following ALTER DATABASE statement uses a logfile_clause to add redo log files.

ALTER DATABASE cdb ADD LOGFILE
  GROUP 4 ('/u01/logs/orcl/redo04a.log','/u02/logs/orcl/redo04b.log')
  SIZE 100M BLOCKSIZE 512 REUSE;

See Also:

Oracle Database SQL Language Reference

Parent topic: Modifying Containers When Connected to the CDB Root

13.4.3 使用ALTER数据库在CDB中设置撤销模式

当启用本地撤销时,每个容器对于其打开的每个实例都有自己的撤销表空间。当禁用本地撤销时,整个CDB有一个撤销表空间。

This section contains the following topics:

Parent topic: Modifying Containers When Connected to the CDB Root

13.4.3.1 关于CDB撤销模式

您可以配置一个CDB,以便在每个容器中使用本地撤销,或者为整个CDB使用共享撤销。
CDB可以在本地或共享撤销模式下运行。撤销模式适用于整个CDB。因此,每个容器要么使用共享撤销,要么使用本地撤销。
在CREATE DATABASE语句的ENABLE PLUGGABLE DATABASEclause中指定CDB创建期间的撤消模式。通过发出ALTER DATABASE语句并重新启动CDB,可以在创建CDB之后更改它的undo模式。

要确定当前的CDB撤销模式,请在CDB根目录中运行以下查询:

SELECT PROPERTY_NAME, PROPERTY_VALUE
FROM   DATABASE_PROPERTIES
WHERE  PROPERTY_NAME = 'LOCAL_UNDO_ENABLED';

如果查询返回PROPERTY_VALUE为TRUE,则CDB处于本地撤消模式。否则,CDB将处于共享撤消模式。

This section contains the following topics:

  • About Local Undo Mode
    Local undo mode means that each container has its own undo tablespace for every instance in which it is open.
  • About Shared Undo Mode
    Shared undo mode means that only one active undo tablespace exists for a single-instance CDB. For an Oracle RAC CDB, there is one active undo tablespace for each instance.

Parent topic: Setting the Undo Mode in a CDB Using ALTER DATABASE

13.4.3.1.1 About Local Undo Mode

本地撤销模式意味着每个容器对于其打开的每个实例都有自己的撤销表空间。
在这种模式下,Oracle数据库自动为CDB中的每个容器创建undo表空间。对于Oracle RAC CDB,在本地撤销模式下,每个PDB实例都有一个活动的撤销表空间。

本地撤销模式为每个容器提供了更高的隔离性,并提高了某些操作的效率,例如拔掉容器或在容器上执行时间点恢复。此外,一些需要支持的操作需要本地撤销模式,例如重新定位PDB或克隆处于开放读/写模式的PDB。

当CDB处于本地撤销模式时,应用以下命令:

  • 任何对当前容器具有适当特权的用户都可以为容器创建撤销表空间。
    撤销表空间在静态数据字典视图和CDB中的每个容器中的动态性能(V$)视图中都是可见的。

See Also:

Oracle Database SQL Language Reference for information about the required privileges

Parent topic: About the CDB Undo Mode

13.4.3.1.2 About Shared Undo Mode

共享撤销模式意味着对于一个单实例CDB,只有一个活动的撤销表空间存在。对于Oracle RAC CDB,每个实例都有一个活动的undo表空间。
当CDB处于共享撤销模式时,应用以下命令:

  • 只有具有适当权限且当前容器是CDB根目录的普通用户才能创建undo表空间。
    当当前容器不是CDB根目录时,创建undo表空间的尝试失败并返回错误。
    当当前容器是CDB根目录时,Undo表空间在静态数据字典视图和动态性能(V$)视图中是可见的。当当前容器是PDB、应用程序根目录或应用程序PDB时,撤销表空间仅在动态性能视图中可见。

Note:

  • 当您更改CDB的撤销模式时,新的撤销模式将在更改后容器第一次打开时应用于单个容器。
    当您更改CDB的撤销模式时,CDB中的容器不能闪回到更改之前的时间或SCN。

Parent topic: About the CDB Undo Mode

13.4.3.2 Configuring a CDB to Use Local Undo Mode

通过发出ALTER DATABASE local undo ONstatement并重新启动数据库,可以将CDB更改为本地撤销模式。
当CDB处于本地撤销模式时,每个容器对于其打开的每个实例都有自己的撤销表空间。Oracle数据库自动在CDB中没有undo表空间的任何容器中创建undo表空间。如果没有撤销表空间的PDB被克隆、重新定位或插入配置为使用本地撤销模式的CDB,那么Oracle数据库将在PDB第一次打开时自动创建撤销表空间。

当CDB从共享撤消模式更改为本地撤消模式时,Oracle数据库自动创建所需的撤消表空间。

  1. If the CDB instance is open, then shut it down.
  2. Start up the CDB instance in OPEN UPGRADE mode. For example:

    STARTUP UPGRADE

  3. In SQL*Plus, ensure that the current container is the CDB root. For example, enter the following:
    SHOW CON_NAME
    
    CON_NAME
    ------------------------------
    CDB$ROOT
    
  4. Query the current undo mode of the CDB:

    SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME = 'LOCAL_UNDO_ENABLED';

  5. To enable local undo, issue the following SQL statement:

    ALTER DATABASE LOCAL UNDO ON;

  6. Shut down and restart the CDB instance.
  7. Optional: Manually create an undo tablespace in the PDB seed.

    当Oracle数据库在PDB种子中以本地撤销模式自动创建撤销表空间时,您可能希望通过手动创建撤销表空间来控制撤销表空间的大小和配置。为了确保从PDB种子创建的PDBs使用手动创建的撤销表空间,而不是自动创建的撤销表空间,必须将UNDO_TABLESPACE初始化参数设置为手动创建的撤销表空间,或者删除自动创建的撤销表空间。

    1. In SQL*Plus, ensure that the current container is the root.
    2. Place the PDB seed in open read/write mode:

      ALTER PLUGGABLE DATABASE PDB$SEED OPEN READ WRITE FORCE;

    3. Switch container to the PDB seed:

      ALTER SESSION SET CONTAINER=PDB$SEED;

    4. Create an undo tablespace in the PDB seed. For example:
      CREATE UNDO TABLESPACE seedundots1
         DATAFILE 'seedundotbs_1a.dbf'
         SIZE 10M AUTOEXTEND ON
         RETENTION GUARANTEE;
    5. Switch container to the root:

      ALTER SESSION SET CONTAINER=CDB$ROOT;

    6. Place the PDB seed in open read-only mode:

      ALTER PLUGGABLE DATABASE PDB$SEED OPEN READ ONLY FORCE;

Parent topic: Setting the Undo Mode in a CDB Using ALTER DATABASE

13.4.3.3 Configuring a CDB to Use Shared Undo Mode

To change a CDB to use shared undo mode, use an ALTER DATABASE LOCAL UNDO OFFstatement.

  1. If the CDB instance is open, then shut it down.
  2. Start up the CDB instance in OPEN UPGRADE mode. For example:

    STARTUP UPGRADE

  3. In SQL*Plus, ensure that the current container is the CDB root. For example, enter the following:
    SHOW CON_NAME
    
    CON_NAME
    ------------------------------
    CDB$ROOT
    
  4. Optionally, query the current undo mode of the CDB:

    SELECT PROPERTY_NAME, PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME = 'LOCAL_UNDO_ENABLED';

  5. To turn off local undo, issue the following SQL statement:

    ALTER DATABASE LOCAL UNDO OFF;

  6. Shut down and restart the CDB instance.

When in shared undo mode, the CDB ignores any local undo tablespaces that were created when it was in local undo mode. Oracle recommends that you delete the unused local undo tablespaces.

Parent topic: Setting the Undo Mode in a CDB Using ALTER DATABASE

13.4.4 Modifying the CDB Root Using ALTER DATABASE

要只修改CDB的根,请使用ALTER DATABASE语句。
当当前容器是根时,一些ALTER DATABASE语句修改根,而不直接修改任何PDBs。有关这些语句的列表,请参见表13-3中的“仅修改根”列。
一些语句为CDB中的PDBs设置了默认值。可以使用ALTER PLUGGABLE数据库语句覆盖PDB的这些默认值。

Prerequisites

To modify the root, the current user must have the ALTER DATABASE privilege in the root.

To modify the root:

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

  2. Run an ALTER DATABASE statement with a clause that modifies the root.

The following examples modify the root.

当前容器为未显式分配表空间的根的用户使用根的默认永久表空间。ALTER数据库语句中指定的表空间必须存在于根目录中。
执行该语句后,根目录中随后创建的表空间的默认类型是bigfile。此设置也是PDBs的默认设置。
ALTER数据库语句中指定的表空间或表空间组必须存在于根目录中。

Example 13-14 Changing the Default Permanent Tablespace for the Root

This ALTER DATABASE statement uses a DEFAULT TABLESPACE clause to set the default permanent tablespace to root_tbs for the root.

ALTER DATABASE DEFAULT TABLESPACE root_tbs;

Example 13-15 Bringing a Data File Online for the Root

This ALTER DATABASE statement uses a database_file_clause to bring the /u02/oracle/cdb_01.dbf data file online.

ALTER DATABASE DATAFILE '/u02/oracle/cdb_01.dbf' ONLINE;

Example 13-16 Changing the Default Tablespace Type for the Root

This ALTER DATABASE statement uses a SET DEFAULT TABLESPACE clause to change the default tablespace type to bigfile for the root.

ALTER DATABASE SET DEFAULT BIGFILE TABLESPACE;

Example 13-17 Changing the Default Temporary Tablespace for the Root

This ALTER DATABASE statement uses a DEFAULT TEMPORARY TABLESPACE clause to set the default temporary tablespace to root_temp for the root.

ALTER DATABASE DEFAULT TEMPORARY TABLESPACE root_temp;

See Also:

Parent topic: Modifying Containers When Connected to the CDB Root

13.4.5 Modifying the Open Mode of One or More PDBs

可以使用ALTER PLUGGABLE DATABASE SQL语句或SQL*Plus启动命令修改PDB的open模式。

This section contains the following topics:

Parent topic: Modifying Containers When Connected to the CDB Root

13.4.5.1 About the Open Mode of a PDB

A PDB can be in various modes.

The following table describes the possible PDB modes.

Table 13-4 PDB Modes

Mode Description

OPEN READ WRITE

在开放读/写模式下的PDB允许查询和用户事务进行,并允许用户生成重做日志。

OPEN READ ONLY

PDB在open只读模式下允许查询,但不允许用户更改。

OPEN MIGRATE

当PDB处于开放迁移模式时,您可以在PDB上运行数据库升级脚本。
在运行ALTER DATABASE OPEN升级之后,PDB处于这种模式。

MOUNTED

当PDB处于挂载模式时,它的行为与非cdb处于挂载模式时类似。它不允许更改任何对象,而且只有数据库管理员可以访问它。它不能从数据文件读取或写入数据文件。有关PDB的信息从内存缓存中删除。可以对PDB进行冷备份。

开放的读/写、只读和迁移模式可以限制为PDB中会话特权受限的用户.

当PDB处于挂载或只读模式时,数据库管理员可以在CDB中创建、修改或删除常见用户和角色。当PDB的open模式更改为open in read/write模式时,CDB将这些更改应用于PDB。在应用这些更改之前,PDB中常见用户和角色的描述可能与CDB其余部分中的描述不同。

打开PDB时,Oracle数据库检查PDB与CDB的兼容性。每个兼容性违反要么是警告要么是错误。如果兼容性冲突是一个警告,那么警告将记录在警告日志中,但是PDB将正常打开,不显示警告消息。如果兼容性冲突是一个错误,那么在打开PDB时将显示一条消息,说明PDB已被错误更改,错误将记录在警报日志中。您必须纠正导致每个错误的条件。 当出现错误时,PDB将被打开,但是对PDB的访问仅限于具有受限会话特权的用户,这样就可以解决兼容性问题。您可以通过查询pdb_plug_in_breach视图来查看违规的描述。

This section contains the following topics:

See Also:

Parent topic: Modifying the Open Mode of One or More PDBs

13.4.5.1.1 About Modifying the Open Mode of PDBs with ALTER PLUGGABLE DATABASE

当当前容器是根容器时,带有pdb_change_state子句的ALTER PLUGGABLE数据库语句将修改指定PDBs的打开模式。
下表描述了修改PDB模式的ALTER PLUGGABLE数据库语句的子句。

Table 13-5 ALTER PLUGGABLE DATABASE Clauses That Modify the Mode of a PDB

Clause Description

OPEN READ WRITE [RESTRICTED] [FORCE]

以读/写模式打开PDB。
当指定RESTRICTED时,PDB只对PDB中具有受限会话特权的用户开放。连接到PDB的所有没有限制SESSIONprivilege的会话将被终止,它们的事务将回滚。
当指定FORCE时,该语句打开当前关闭的PDB,并更改处于open只读模式的PDB的打开模式。

OPEN READ ONLY[RESTRICTED] [FORCE]

以只读模式打开PDB。
当指定RESTRICTED时,PDB只对PDB中具有受限会话特权的用户开放。连接到PDB的所有没有限制SESSIONprivilege的会话都被终止。
当指定FORCE时,该语句打开当前关闭的PDB,并更改处于打开读/写模式的PDB的打开模式。

OPEN UPGRADE [RESTRICTED]

以迁移模式打开PDB。
当指定RESTRICTED时,PDB只对PDB中具有受限会话特权的用户开放。

CLOSE [IMMEDIATE|ABORT]

将PDB置于挂载模式。
CLOSE语句相当于PDB中的SQL*Plus SHUTDOWN命令。如果不指定立即或中止,则PDB将以正常模式关闭。
当指定了IMMEDIATE时,该语句相当于具有立即模式的SQL*Plus SHUTDOWN命令。

当指定中止时,将强制关闭PDB。对于单实例CDB,在指定SHUTDOWN ABORT时需要PDB媒体恢复。对于Oracle Real Application Clusters (Oracle RAC) CDB,如果SHUTDOWN ABORT命令关闭最后一个打开的实例,则需要PDB媒体恢复。

当您发出ALTER PLUGGABLE DATABASE OPEN语句时,读写是默认的,除非正在打开的PDB属于用作物理备用数据库的CDB,在这种情况下,只读是默认的。

You can specify which PDBs to modify in the following ways:

  • List one or more PDBs.

  • Specify ALL to modify all PDBs.

  • Specify ALL EXCEPT to modify all PDBs, except for the PDBs listed.

The services Clause

您可以使用services子句来指定在以以下方式打开单个PDB时启动的服务:

  • List one or more services in the services clause in the following form:

    SERVICES = ('service_name' [,'service_name'] … )
    
  • Specify ALL in the services clause to start all PDB’s services, as in the following example:

    SERVICES = ALL
    
  • Specify ALL EXCEPT in the services clause to start all PDB’s services, except for the services listed, in the following form:

    SERVICES = ALL EXCEPT('service_name' [,'service_name'] … )
    
  • Specify NONE in the services clause to start only the PDB’s default service and none of the other PDB’s services, as in the following example:

    SERVICES = NONE

    NONE is the default setting for the services clause. A PDB’s default service is always started, regardless of the setting for the services clause.

The instances Clause

对于Oracle Real Application Clusters (Oracle RAC) CDB,可以使用instances子句指定修改PDB的实例,具体方法如下

  • List one or more instances in the instances clause in the following form:

    INSTANCES = ('instance_name' [,'instance_name'] … )
    
  • Specify ALL in the instances clause to modify the PDB in all running instances, as in the following example:

    INSTANCES = ALL
    
  • Specify ALL EXCEPT in the instances clause to modify the PDB in all instances, except for the instances listed, in the following form:

    INSTANCES = ALL EXCEPT('instance_name' [,'instance_name'] … )
    

此外,当您在Oracle RAC CDB中关闭PDB时,可以使用reset子句,该子句包含以下选项:

  • Specify NORELOCATE, the default, to close the PDB in the current instance.

  • Specify RELOCATE TO and specify an instance name to reopen the PDB in the specified instance.

  • Specify RELOCATE to reopen the PDB on a different instance that is selected by Oracle Database.

Note:

如果在同一个ALTER PLUGGABLE数据库语句中指定了services子句和instances子句,那么指定的服务将在指定的实例上启动。

The relocate Clause

When you are closing a PDB in an Oracle RAC CDB, you can use the relocate clause, which includes the following options:

  • Specify NORELOCATE, the default, to close the PDB in the current instance.

  • Specify RELOCATE TO and specify an instance name to reopen the PDB in the specified instance.

  • Specify RELOCATE to reopen the PDB on a different instance that is selected by Oracle Database.

To modify the open mode of PDBs with the ALTER PLUGGABLE DATABASE statement, the following prerequisites must be met:

  • The current user must have SYSDBASYSOPERSYSBACKUP, or SYSDG administrative privilege, and the privilege must be either commonly granted or locally granted in the PDB. The user must exercise the privilege using AS SYSDBAAS SYSOPERAS SYSBACKUP, or AS SYSDG, respectively, at connect time.

  • When RESTRICTED SESSION is enabled, RESTRICTED must be specified when a PDB is opened.

  • In an Oracle RAC CDB, if a PDB is open in one or more Oracle RAC instances, then it can be opened in additional instances, but it must be opened in the same mode as in the instances in which it is already open. A PDB can be closed in some instances and opened on others.

对ALTER PLUGGABLE数据库语句的需求摘要

要使用ALTER PLUGGABLE DATABASE语句修改PDBs的open mode,必须满足以下先决条件:

  • The current user must have SYSDBASYSOPERSYSBACKUP, or SYSDG administrative privilege, and the privilege must be either commonly granted or locally granted in the PDB. The user must exercise the privilege using AS SYSDBAAS SYSOPERAS SYSBACKUP, or AS SYSDG, respectively, at connect time.

  • When RESTRICTED SESSION is enabled, RESTRICTED must be specified when a PDB is opened.

  • In an Oracle RAC CDB, if a PDB is open in one or more Oracle RAC instances, then it can be opened in additional instances, but it must be opened in the same mode as in the instances in which it is already open. A PDB can be closed in some instances and opened on others.

要使用ALTER PLUGGABLE数据库语句将PDBs置于目标模式,必须满足下表中描述的需求。

Table 13-6 Modifying the Open Mode of PDBs with ALTER PLUGGABLE DATABASE

Target Mode of PDBs ALL Keyword Included FORCE Keyword Included Required Mode for the Root Required Mode for Each PDB Being Modified

Read/write

Yes

Yes

Read/write

Mounted, read-only, or read/write

Read/write

Yes

No

Read/write

Mounted or read/write

Read/write

No

Yes

Read/write

Mounted, read-only, or read/write

Read/write

No

No

Read/write

Mounted

Read-only

Yes

Yes

Read-only or read/write

Mounted, read-only, or read/write

Read-only

Yes

No

Read-only or read/write

Mounted or read-only

Read-only

No

Yes

Read-only or read/write

Mounted, read-only, or read/write

Read-only

No

No

Read-only or read/write

Mounted

Migrate

Yes

Not applicable

Read-only or read/write

Mounted

Migrate

No

Not applicable

Read-only or read/write

Mounted

Mounted

Yes

Not applicable

Read-only or read/write

Mounted, read-only, migrate, or read/write

Mounted

No

Not applicable

Read-only or read/write

Read-only, migrate, or read/write

Note:

You can also modify the open mode of a PDB when the current container is the PDB.

See Also:

Parent topic: About the Open Mode of a PDB

13.4.5.1.2 About Modifying the Open Mode of PDBs with the SQL*Plus STARTUP Command

When the current container is the root, the STARTUP PLUGGABLE DATABASE command can open a single PDB.

Use the following options of the STARTUP PLUGGABLE DATABASE command to open a PDB:

  • FORCE

    Closes an open PDB before re-opening it in read/write mode. When this option is specified, no other options are allowed.

  • RESTRICT

    Enables only users with the RESTRICTED SESSION system privilege in the PDB to access the PDB.

    If neither OPEN READ WRITE nor OPEN READ ONLY is specified, then the PDB is opened in read-only mode when the CDB to which it belongs is a physical standby database. Otherwise, the PDB is opened in read/write mode.

  • OPEN open_pdb_options

    Opens the PDB in either read/write mode or read-only mode. You can specify OPEN READ WRITE or OPEN READ ONLY. When you specify OPEN without any other options, READ WRITE is the default.

必须满足下列先决条件:

  • 当前用户必须具有SYSDBA、SYSOPER、SYSBACKUP或SYSDG管理特权,并且该特权必须在PDB中通常授予或本地授予。用户必须在连接时分别使用SYSDBA、SYSOPER、SYSBACKUP或SYSDG来行使该特权。
    当启用受限会话时,必须在打开PDB时指定limit。

此外,要使用STARTUP PLUGGABLE DATABASE命令将PDBs置于目标模式,必须满足下表中描述的需求。

Table 13-7 Modifying the Open Mode of a PDB with STARTUP PLUGGABLE DATABASE

Target Mode of the PDB FORCE Option Included Required Mode for the Root Required Mode of the PDB Being Modified

Read/write

Yes

Read/write

Mounted, read-only, or read/write

Read/write

No

Read/write

Mounted

Read-only

No

Read-only or read/write

Mounted

Note:

You can also use the STARTUP command to modify the open mode of a PDB when the current container is the PDB.

See Also:

Parent topic: About the Open Mode of a PDB

13.4.5.2 Modifying the Open Mode of PDBs with ALTER PLUGGABLE DATABASE

You can modify the open mode of PDBs with the ALTER PLUGGABLE DATABASE statement with a pdb_change_state clause.

To modify the open mode:

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

    See "About Container Access in a CDB".

  2. Run an ALTER PLUGGABLE DATABASE statement with a pdb_change_state clause.

Example 13-18 Changing the Open Mode of Listed PDBs

This statement changes the open mode of PDBs salespdb and hrpdb to open in read/write mode.

ALTER PLUGGABLE DATABASE salespdb, hrpdb
   OPEN READ WRITE;

This statement changes the open mode of PDB salespdb to open in read-only mode. RESTRICTED specifies that the PDB is accessible only to users with RESTRICTED SESSIONprivilege in the PDB.

ALTER PLUGGABLE DATABASE salespdb
   OPEN READ ONLY RESTRICTED;

This statement changes the open mode of PDB salespdb to open in migrate mode:

ALTER PLUGGABLE DATABASE salespdb
   OPEN UPGRADE;

Example 13-19 Changing the Open Mode of All PDBs

Run the following query to display the open mode of each PDB associated with a CDB:

SELECT NAME, OPEN_MODE FROM V$PDBS WHERE CON_ID > 2;
 
NAME                           OPEN_MODE
------------------------------ ----------
HRPDB                          READ WRITE
SALESPDB                       MOUNTED
DWPDB                          MOUNTED

Notice that hrpdb is already in read/write mode. To change the open mode of salespdb and dwpdb to open in read/write mode, use the following statement:

ALTER PLUGGABLE DATABASE ALL
   OPEN READ WRITE;

The hrpdb PDB is not modified because it is already in open read/write mode. The statement does not return an error because two PDBs are in mounted mode and one PDB (hrpdb) is in the specified mode (read/write). Similarly, the statement does not return an error if all PDBs are in mounted mode.

However, if any PDB is in read-only mode, then the statement returns an error. To avoid an error and open all PDBs in the CDB in read/write mode, specify the FORCE keyword:

ALTER PLUGGABLE DATABASE ALL
   OPEN READ WRITE FORCE;

With the FORCE keyword included, all PDBs are opened in read/write mode, including PDBs in read-only mode.

Example 13-20 Changing the Open Mode of All PDBs Except for Listed Ones

This statement changes the mode of all PDBs except for salespdb and hrpdb to mounted mode.

ALTER PLUGGABLE DATABASE ALL EXCEPT salespdb, hrpdb
   CLOSE IMMEDIATE;

Note:

An ALTER PLUGGABLE DATABASE statement modifying the open mode of a PDB is instance-specific. Therefore, if this statement is issued when connected to an Oracle RAC instance, then it affects the open mode of the PDB only in that instance.

See Also:

Parent topic: Modifying the Open Mode of One or More PDBs

13.4.5.3 Modifying the Open Mode of PDBs with the SQL*Plus STARTUP Command

You can use the STARTUP PLUGGABLE DATABASE command to open a single PDB.

To modify a PDB with the STARTUP PLUGGABLE DATABASE command:

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

    See "About Container Access in a CDB".

  2. Run the STARTUP PLUGGABLE DATABASE command.

Note:

当当前容器是根容器时,SQL*Plus SHUTDOWN命令总是关闭CDB实例。它不能用于关闭单个pdb。

Example 13-21 Opening a PDB in Read/Write Mode with the STARTUP Command

STARTUP PLUGGABLE DATABASE hrpdb OPEN

Example 13-22 Opening a PDB in Read/Write Restricted Mode with the STARTUP Command

STARTUP PLUGGABLE DATABASE hrpdb RESTRICT

Example 13-23 Opening a PDB in Read-Only Restricted Mode with the STARTUP Command

STARTUP PLUGGABLE DATABASE hrpdb OPEN READ ONLY RESTRICT

Example 13-24 Opening a PDB in Read-Only Mode with the STARTUP Command

STARTUP PLUGGABLE DATABASE hrpdb OPEN READ ONLY

Example 13-25 Opening a PDB in Read/Write Mode with the STARTUP Command and the FORCE Option

This example assumes that the hrpdb PDB is currently open. The FORCE option closes the PDB and then opens it in the read/write mode.

STARTUP PLUGGABLE DATABASE hrpdb FORCE

(运行不了啊,再查资料了)

See Also:

Parent topic: Modifying the Open Mode of One or More PDBs

13.4.5.4 当CDB重启时,保留或丢弃PDBs的开放模式

当CDB重新启动时,您可以使用带有pdb_save_or_discard_state子句的ALTER PLUGGABLE数据库SQL语句来保持一个或多个PDBs的开放模式。

You can do this in the following way:

  • 指定SAVE状态,以便在重新启动CDB时保存PDBs模式。
    例如,如果一个PDB在CDB重启前处于open read/write模式,那么在CDB重启后PDB处于open read/write模式;如果PDB在重启CDB之前处于挂载模式,那么PDB在重启CDB之后也处于挂载模式。

  • 指定丢弃状态,以便在重新启动CDB时忽略PDBs的打开模式。
    当为PDB指定丢弃状态时,PDB总是在重新启动CDB之后挂载。

You can specify which PDBs to modify in the following ways:

  • List one or more PDBs.

  • Specify ALL to modify all PDBs.

  • Specify ALL EXCEPT to modify all PDBs, except for the PDBs listed.

For an Oracle RAC CDB, you can use the instances clause in the pdb_save_or_discard_state clause to specify the instances on which a PDB's open mode is preserved in the following ways:

  • List one or more instances in the instances clause in the following form:

    INSTANCES = ('instance_name' [,'instance_name'] … )
    
  • Specify ALL in the instances clause to modify the PDB in all running instances, as in the following example:

    INSTANCES = ALL
    
  • Specify ALL EXCEPT in the instances clause to modify the PDB in all instances, except for the instances listed, in the following form:

    INSTANCES = ALL EXCEPT('instance_name' [,'instance_name'] … )
    

对于Oracle RAC CDB中的PDB,保存状态和丢弃状态只影响当前实例的模式。它们不会影响其他实例的模式,即使在instances子句中指定了多个实例。


要发出带有pdb_save_or_discard_state子句的ALTER PLUGGABLE数据库SQL语句,当前用户必须在根目录中拥有ALTER数据库特权。

通过查询DBA_PDB_SAVED_STATESview,可以检查CDB中PDBs的保存状态。
当CDB重新启动时,保留或丢弃PDB的open模式:

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

    See "About Container Access in a CDB".

  2. Run an ALTER PLUGGABLE DATABASE statement with a pdb_save_or_discard_state clause.

下面的示例在CDB重新启动时保留或丢弃一个或多个PDBs的开放模式。

Example 13-26 Preserving the Open Mode of a PDB When the CDB Restarts

This statement preserves the open mode of the salespdb when the CDB restarts.

ALTER PLUGGABLE DATABASE salespdb SAVE STATE;

Example 13-27 Discarding the Open Mode of a PDB When the CDB Restarts

This statement discards the open mode of the salespdb when the CDB restarts.

ALTER PLUGGABLE DATABASE salespdb DISCARD STATE;

Example 13-28 Preserving the Open Mode of All PDBs When the CDB Restarts

This statement preserves the open mode of all PDBs when the CDB restarts.

ALTER PLUGGABLE DATABASE ALL SAVE STATE;

Example 13-29 Preserving the Open Mode of Listed PDBs When the CDB Restarts

This statement preserves the open mode of the salespdb and hrpdb when the CDB restarts.

ALTER PLUGGABLE DATABASE salespdb, hrpdb SAVE STATE;

Example 13-30 Preserving the Open Mode of All PDBs Except for Listed Ones When the CDB Restarts

This statement preserves the open mode of all PDBs except for salespdb and hrpdb.

ALTER PLUGGABLE DATABASE ALL EXCEPT salespdb, hrpdb SAVE STATE;

Parent topic: Modifying the Open Mode of One or More PDBs

13.4.5.5 在Oracle RAC中启动和停止PDBs

管理可插入数据库(PDB)涉及管理非cdb所需任务的一小部分。

管理基于Oracle racc的多租户容器数据库(CDB)类似于管理非CDB。不同之处在于,一些管理任务应用于整个CDB,一些应用于CDB根,还有一些应用于特定的PDBs。在这个任务子集中,对于PDB和非cdb,大多数任务是相同的。但是有一些区别,例如修改PDB的open模式时。此外,PDB管理员仅限于管理单个PDB,不受CDB中其他PDBs的影响。

通过管理服务,可以在Oracle RAC CDB中管理PDBs。无论PDBs是策略管理的还是管理员管理的,这都是正确的。为每个PDB分配一个动态数据库服务,以协调集群容器数据库中跨实例的PDB的启动、停止和放置。

例如,如果您在名为prod的服务器池中有一个名为raccont的CDB和一个名为spark的策略管理PDB,那么使用以下命令将一个名为plug的服务分配给这个数据库:

srvctl add service –db raccont –pdb spark –service plug –serverpool prod

The service plug is uniformly managed across all nodes in the server pool. If you want to have this service running as a singleton service in the same server pool, then use the -cardinality singleton parameter with the preceding command.

To open the PDB spark, you must start the service plug as follows:

srvctl start service -db raccont -service plug

To stop the service plug:

srvctl stop service -db raccont -service plug

The PDB spark remains open until you close the PDB using the SQL command ALTER PLUGGABLE DATABASE PDB_NAME CLOSE IMMEDIATE. You can check the status of the database using the srvctl status service command.

因为pdb是使用动态数据库服务管理的,所以应用了典型的基于Oracle racp的管理实践。因此,如果在托管该服务的服务器上关闭Oracle Clusterware时,服务插头处于在线状态,那么在此服务器上重启Oracle Clusterware后,服务将恢复到原来的状态。因此,与任何其他Oracle RAC数据库一样,启动PDBs也是自动化的。

Note:

与SQL*Plus不同,SRVCTL操作整个集群数据库。因此,当服务被定义为同时在多个服务器上运行且集群的当前状态允许这种放置时,使用服务启动PDB应用于集群CDB的多个实例。

Related Topics

Parent topic: Modifying the Open Mode of One or More PDBs

13.5 Executing SQL in Multiple Containers

To execute SQL in one or more containers, use the CONTAINERS clause for DML or the CONTAINERclause for DDL.

This section contains the following topics:

Parent topic: Administering a CDB

13.5.1 在CDB中对容器发出DML语句

在CDB根中发出的DML(数据操作语言)语句可以修改CDB中的一个或多个容器。此外,您可以为DML语句指定一个或多个默认容器目标。

This section contains the following topics:

Parent topic: Executing SQL in Multiple Containers

13.5.1.1 About Issuing DML Statements on Containers in a CDB

DML statements can affect database objects in more than one container in a CDB.

在CDB根或应用程序根中,包含CONTAINERS子句的单个DML语句可以修改该CDB或应用程序容器中的一个或多个容器中的表或视图。要使用CONTAINERS子句,请指定容器子句中正在修改的表或视图,以及WHERE子句中受影响的容器。通过在VALUES子句中为CON_ID指定值,可以在INSERT VALUESstatement中指定目标容器。此外,可以通过在WHEREclause中指定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;

WHERE子句中为CON_ID指定的值必须用于属于CDB的容器,包括PDBs、应用程序根和应用程序PDBs。

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

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

通过在VALUES子句中为CON_ID指定值,可以在INSERT VALUES语句中指定目标容器。此外,可以通过在WHERE子句中指定CON_ID谓词,在UPDATE或DELETEstatement中指定目标容器。
默认情况下,CDB中的默认目标容器包括它的所有PDBs、应用程序根、应用程序种子和应用程序PDBs,但不包括它的CDB根或PDB种子。您可以通过运行以下查询来确定CDB的默认目标容器:

SELECT PROPERTY_VALUE FROM DATABASE_PROPERTIES WHERE PROPERTY_NAME='CONTAINERS_DEFAULT_TARGET';

The following restrictions apply to the CONTAINERS clause:

  • 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.

Parent topic: Issuing DML Statements on Containers in a CDB

13.5.1.2 为CDB中的DML语句指定默认容器

To specify the default container for DML statements in a CDB, issue the ALTER DATABASE statement with the CONTAINERS DEFAULT TARGET clause.

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

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

    The current user must have the commonly granted ALTER DATABASE privilege.

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

Example 13-31 Specifying the Default Container for DML Statements in a CDB

This example specifies that PDB1 is the default container for DML statements in the CDB.

ALTER DATABASE CONTAINERS DEFAULT TARGET = (PDB1);

Example 13-32 Clearing the Default Container

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

ALTER DATABASE CONTAINERS DEFAULT TARGET = NONE;

Parent topic: Issuing DML Statements on Containers in a CDB

13.5.2 Executing DDL Statements in a CDB

In a CDB, you can execute a data definition language (DDL) statement in the current container or in all containers.

This section contains the following topics:

Parent topic: Executing SQL in Multiple Containers

13.5.2.1 About Executing DDL Statements in a CDB

In a CDB, some DDL statements can apply to all containers or to the current container only.

To specify which containers are affected, use the CONTAINER clause:

CONTAINER = { CURRENT | ALL }

The following settings are possible:

  • CURRENT means that the statement applies only to the current container.

  • ALL means that the statement applies to all containers in the CDB, including the root and all PDBs.

The following restrictions apply to the CONTAINER clause in DDL statements:

Table 13-8 DDL Statements and the CONTAINER Clause in a CDB

DDL Statement CONTAINER = CURRENT CONTAINER = ALL

CREATE USER

Creates a local user in the current PDB.

Creates a common user.

ALTER USER

Alters a local user in the current PDB.

Alters a common user.

CREATE ROLE

Creates a local role in the current PDB.

Creates a common role.

GRANT

Grants a privilege in the local container to a local user, common user, or local role.

The SET CONTAINERprivilege can be granted to a user-created common user in the current PDB.

Grants a system privilege or object privilege on a common object to a common user or common role. The specified privilege is granted to the user or role across the entire CDB.

REVOKE

Revokes a privilege in the local container from a local user, common user, or local role.

This statement can revoke only a privilege granted with CURRENT specified in the CONTAINER clause from the specified user or role in the local container. The statement does not affect privileges granted with ALL specified in the CONTAINER clause.

The SET CONTAINERprivilege can be revoked from a user-created common user in the current PDB.

Revokes a system privilege or object privilege on a common object from a common user or common role. The specified privilege is revoked from the user or role across the entire CDB.

This statement can revoke only a privilege granted with ALLspecified in the CONTAINERclause from the specified common user or common role. The statement does not affect privileges granted with CURRENT specified in the CONTAINER clause. However, any privileges granted locally that depend on the privilege granted commonly that is being revoked are also revoked.

All other DDL statements apply to the current container only.

In addition to the usual rules for user, role, and profile names, the following rules and best practices apply when you create a user, role, or profile in a CDB:

  • It is best practice for common user, role, and profile names to start with a prefix to avoid naming conflicts between common users, roles, and profiles and local users, roles, and profiles. You specify this prefix with the COMMON_USER_PREFIX initialization parameter in the CDB root. By default, the prefix is C## or c## in the CDB root.

  • In an application container, it is best practice for application common user, role, and profile names to start with a prefix to avoid naming conflicts between application common users, roles, and profiles and local users, roles, and profiles. You specify this prefix with the COMMON_USER_PREFIX initialization parameter in the application root. By default, the prefix is NULL in an application root.

  • When the COMMON_USER_PREFIX initialization parameter is set in an application root, the setting applies to the application common user, role, and profile names in the application container. The prefix can be different in the CDB root and in an application root, and the prefix can be different in different application containers.

  • Common user, role, and profile names must consist only of ASCII characters. This restriction does not apply to application common user, role, and profile names.

  • Local user, role, and profile names cannot start with the prefix specified for common users with the COMMON_USER_PREFIX initialization parameter.

  • Local user, role, and profile names cannot start with C## or c##.

  • Regardless of the value of COMMON_USER_PREFIX in the CDB root, application common user, role, and profile names cannot start with C## or c##.

  • Application common user, role, and profile names cannot start with the prefix specified for common users with the COMMON_USER_PREFIX initialization parameter.

See Also:

Parent topic: Executing DDL Statements in a CDB

13.5.2.2 Executing a DDL Statement in the Current Container

Specify CURRENT in the CONTAINER clause of a DDL statement to execute the statement in the current container.

The supported DDL statements are listed in Table 13-8.

The current user must be granted the required privileges to execute the DDL statement in the current container. For example, to create a user, the current user must be granted the CREATE USER system privilege in the current container.

To execute a DDL statement in the current container:

  1. In SQL*Plus, access a container.

    See "Accessing a Container in a CDB with SQL*Plus".

  2. Execute the DDL statement with CONTAINER set to CURRENT.

A local user's user name cannot start with the prefix specified by the COMMON_USER_PREFIXinitialization parameter. By default, in the CDB root, the prefix is C## or c##. An application root can specify its own prefix for an application container. In addition, a common user's name must consist only of ASCII characters. The specified tablespace must exist in the PDB.

Example 13-33 Creating Local User in a PDB

This example creates the local user testpdb in the current PDB.

CREATE USER testpdb IDENTIFIED BY password 
   DEFAULT TABLESPACE pdb1_tbs
   QUOTA UNLIMITED ON pdb1_tbs
   CONTAINER = CURRENT;

Parent topic: Executing DDL Statements in a CDB

13.5.2.3 Executing a DDL Statement in All Containers in a CDB

Specify ALL in the CONTAINER clause of a DDL statement to execute the statement in all containers in a CDB.

The supported DDL statements are listed in Table 13-8.

The following prerequisites must be met:

  • The current user must be a common user.

  • The current user must be granted the required privileges commonly to execute the DDL statement. For example, to create a user, the current user must be granted the CREATE USERsystem privilege commonly.

To execute a DDL statement in all containers in a CDB:

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

    See "About Container Access in a CDB".

  2. Execute the DDL statement with CONTAINER set to ALL.

A common user's user name must start with the prefix specified by the COMMON_USER_PREFIXinitialization parameter. By default, in the CDB root, the prefix is C## or c##. An application root can specify its own prefix for an application container. In addition, a common user's name must consist only of ASCII characters. The specified tablespace must exist in the root and in all PDBs.

Example 13-34 Creating Common User in a CDB

This example creates the common user c##testcdb.

CREATE USER c##testcdb IDENTIFIED BY password 
   DEFAULT TABLESPACE cdb_tbs
   QUOTA UNLIMITED ON cdb_tbs
   CONTAINER = ALL;

Parent topic: Executing DDL Statements in a CDB

13.5.3 在CDB中运行oracle提供的SQL脚本

你可以用catcon.pl脚本,用于在CDB中运行oracle提供的SQL或SQL脚本。您可以在任何指定的容器上运行脚本。

This section contains the following topics:

Parent topic: Executing SQL in Multiple Containers

13.5.3.1 About Running Oracle-Supplied SQL Scripts in a CDB

In a CDB, catcon.pl脚本是运行SQL脚本和SQL语句的最佳方式。.

Oracle数据库安装包括几个SQL脚本。这些脚本执行创建数据字典视图和安装选项等操作。

catcon。pl脚本可以以正确的顺序在根目录和指定的PDBs中运行脚本,并生成日志文件,您可以查看这些日志文件,以确认SQL脚本或SQL语句没有生成意外错误。它还启动多个进程,并在它们完成之前分配给它们的运行脚本时向它们分配新脚本。

Note:

  • 除非在运行catcon时排除PDB种子。SQL脚本或SQL语句在PDB种子上运行。
    你可以用catcon.pl脚本在CDBs和非CDBs上运行脚本。

Parent topic: Running Oracle-Supplied SQL Scripts in a CDB

13.5.3.2 Syntax and Parameters for catcon.pl

The catcon.pl脚本是必须在操作系统提示符下运行的Perl脚本。

The catcon.pl script has the following syntax and parameters:

$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl  
[--usr username[/password]] [--int_usr username[/password]] [--script_dir directory] 
[--log_dir directory] [{--incl_con|--excl_con} container] [--echo] [--spool] 
[--error_logging { ON | errorlogging-table-other-than-SPERRORLOG } ] [--app_con application_root] 
[--no_set_errlog_ident] [--diag] [-ignore_unavailable_pdbs] [--verbose] [--force_pdb_mode pdb_mode] 
[--recover] --log_file_base log_file_name_base 
-- { SQL_script [arguments] | --x'SQL_statement' }

Ensure that --x SQL_statement is preceded by -- if it follows any single-letter parameter. If --xSQL_statement is preceded by a script name or another --x SQL_statement, then do not precede it with --. Also, note that the SQL statement must be inside single quotation marks.

Command line parameters to SQL scripts can be introduced using --p. Interactive (or secret) parameters to SQL scripts can be introduced using --P.

To view the help for the catcon.pl script, change directories to $ORACLE_HOME/perl/bin/, and then run the following command:

perl $ORACLE_HOME/rdbms/admin/catcon.pl --help

Table 13-9 describes the catcon.pl parameters. A parameter is optional unless it is indicated that it is required.

下表中的短参数名称是为了向后兼容。有些参数没有短名称.

Table 13-9 catcon.pl Parameters

Parameter Description

--usr

Short name: -u

Specifies the user name and password to connect to the root and the specified PDBs. Specify a common user with the required privileges to run the SQL script or the SQL statement. The default is "/ AS SYSDBA". If no password is supplied, then catcon.pl prompts for a password.

--int_usr

Short name: -U

Specifies the user name and password to connect to the root and the specified PDBs. Specify a common user with the required privileges to perform internal tasks, such as running queries on the CDB's metadata. The default is "/ AS SYSDBA". If no password is supplied, then catcon.pl prompts for a password.

--script_dir

Short name: -d

Directory that contains the SQL script. The default is the current directory.

--log_dir

Short name: -l

Directory into which catcon.pl writes log files. The default is the current directory.

{--incl_con|--excl_con}

Short names: {-c|-C}

The containers in which the SQL script is run or is not run.

The --incl_con parameter lists the containers in which the SQL script is run.

The --excl_con parameter lists the containers in which the SQL script is not run.

Specify containers in a space-delimited list of PDB names enclosed in single quotation marks.

The --incl_con and --excl_con parameters are mutually exclusive.

When this parameter is used, the --app_con parameter cannot be used.

--echo

Short name: -e

Sets echo ON while running the script. The default is echo OFF.

--spool

Short name: -s

Spools the output of every script into a file with the following name:

log-file-name-base_script-name-without-extension_[container-name-if-any].default-extension

--error_logging

Short name: -E

When set to ON, the default error logging table is used. ON is the default setting. When set to ON, errors are written to the table SPERRORLOG in the current schema in each container in which the SQL script runs. If this table does not exist in a container, then it is created automatically.

When a table other than SPERRORLOG is specified, errors are written to the specified table. The table must exist in each container in which the SQL script runs, and the current user must have the necessary privileges to perform DML operations on the table in each of these containers.

See SQL*Plus User's Guide and Reference for more information about the error logging table.

--app_con

Short name: -F

Specify an application root. The scripts are run in the application root and in the application PDBs that are plugged into the application root.

When this parameter is used, the --incl_con and --excl_conparameters cannot be used.

--no_set_errlog_ident

Short name: -I

Do not issue a SET ERRORLOGGING identifier. This option is intended for cases in which the SET ERRORLOGGING identifier is already set and should not be overwritten.

--diag

Short name: -g

Turns on the generation of debugging information.

--verbose

Short name: -v

Turns on verbose output.

--ignore_unavailable_pdbs

Short name: -f

Ignore PDBs that are closed or, if the --incl_con or --excl_conoption is used, do not exist and process only open PDBs that were specified explicitly or implicitly.

When this option is not specified and some specified PDBs do not exist or are not open, an error is returned and none of the containers are processed.

--force_pdb_mode

The required open mode for all PDBs against which the scripts are run. Specify one of the following values:

  • UNCHANGED

  • READ WRITE

  • READ ONLY

  • UPGRADE

  • DOWNGRADE

When a value other than UNCHANGED is specified, all of the PDBs against which the script is run are changed to the specified open mode. If a PDB is open in a different mode, then the PDB is closed and re-opened in the specified mode. After all of the scripts are run, each PDB is restored to its original open mode.

When UNCHANGED, the default, is specified, the open mode of the PDBs is not changed.

--recover

Short name: -R

Causes catcon.pl to attempt to recover if a SQL*Plus process that it spawned ends unexpectedly. When this parameter is not specified, catcon.pl does not attempt to recover the process and closes.

--log_file_base

Short name: -b

(Required) The base name for log file names.

Parent topic: Running Oracle-Supplied SQL Scripts in a CDB

13.5.3.3 Running the catcon.pl Script

Examples illustrate running the catcon.pl script.

如果SQL脚本或SQL语句由catcon运行。pl执行数据操作语言(DML)或数据定义语言(DDL)操作,然后修改的容器必须处于读/写模式。

To run the catcon.pl script:

  1. Open a command line prompt.

  2. Run the catcon.pl script and specify one or more SQL scripts or SQL statements:

    cd $ORACLE_HOME/perl/bin/
    perl $ORACLE_HOME/rdbms/admin/catcon.pl parameters SQL_script
    perl $ORACLE_HOME/rdbms/admin/catcon.pl parameters -- --xSQL_statement
    

Example 13-35 Running the catblock.sql Script in All Containers in a CDB

The following example runs the catblock.sql script in all of the containers of a CDB.

$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl --usr SYS 
--script_dir $ORACLE_HOME/rdbms/admin --log_file_base catblock_output catblock.sql

The following parameters are specified:

  • The --usr parameter specifies that SYS user runs the script in each container.

  • The --script_dir parameter specifies that the SQL script is in the $ORACLE_HOME/rdbms/admin directory.

  • The --log_file_base parameter specifies that the base name for log file names is catblock_output.

Default parameter values are used for all other parameters. Neither the --incl_con nor the --excl_con parameter is specified. Therefore, catcon.pl runs the script in all containers by default.

Example 13-36 Running the catblock.sql Script in Specific PDBs

The following example runs the catblock.sql script in the hrpdb and salespdb PDBs in a CDB.

$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl --usr SYS --int_usr SYS 
--script_dir $ORACLE_HOME/rdbms/admin --log_dir '/disk1/script_output' --incl_con 'HRPDB SALESPDB' 
--log_file_base catblock_output catblock.sql

The following parameters are specified:

  • The --usr parameter specifies that SYS user runs the script in each container.

  • The --int_usr parameter specifies that SYS user performs internal tasks.

  • The --script_dir parameter specifies that the SQL script is in the $ORACLE_HOME/rdbms/admin directory.

  • The --log_dir parameter specifies that the output files are placed in the /disk1/script_output directory.

  • The --incl_con parameter specifies that the SQL script is run in the hrpdb and salespdbPDBs. The script is not run in any other containers in the CDB.

  • The --log_file_base parameter specifies that the base name for log file names is catblock_output.

Example 13-37 Running the catblock.sql Script in All Containers Except for Specific PDBs

The following example runs the catblock.sql script in all of the containers in a CDB except for the hrpdb and salespdb PDBs.

$ORACLE_HOME/perl/bin/perl $ORACLE_HOME/rdbms/admin/catcon.pl --usr SYS 
--script_dir $ORACLE_HOME/rdbms/admin --log_dir '/disk1/script_output' --excl_con 'HRPDB SALESPDB' 
--log_file_base catblock_output catblock.sql

The following parameters are specified:

  • The --usr parameter specifies that SYS user runs the script in each container.

  • The --script_dir parameter specifies that the SQL script is in the $ORACLE_HOME/rdbms/admin directory.

  • The --log_dir parameter specifies that the output files are placed in the /disk1/script_output directory.

  • The --excl_con parameter specifies that the SQL script is run in all of the containers in the CDB except for the hrpdb and salespdb PDBs.

  • The --log_file_base parameter specifies that the base name for log file names is catblock_output.

Example 13-38 Running a SQL Script with Command Line Parameters

The following example runs the custom_script.sql script in all of the containers of a CDB.

cd $ORACLE_HOME/perl/bin/
perl $ORACLE_HOME/rdbms/admin/catcon.pl --usr SYS --script_dir /u01/scripts --log_file_base custom_script_output custom_script.sql '--phr' '--PEnter password for user hr:'

The following parameters are specified:

  • The --usr parameter specifies that SYS user runs the script in each container.

  • The --script_dir parameter specifies that the SQL script is in the /u01/scripts directory.

  • The --log_file_base parameter specifies that the base name for log file names is custom_script_output.

  • The --p parameter specifies hr for a command line parameter

  • The --P parameter specifies an interactive parameter that prompts for the password of user hr.

Default parameter values are used for all other parameters. Neither the -incl_con nor the -excl_con parameter is specified. Therefore, catcon.pl runs the script in all containers by default.

Example 13-39 Running a SQL Statement in All Containers in a CDB

The following example runs a SQL statement in all of the containers of a CDB.

cd $ORACLE_HOME/perl/bin/
perl $ORACLE_HOME/rdbms/admin/catcon.pl --usr SYS --echo --log_file_base select_output -- --x"SELECT * FROM DUAL"

The following parameters are specified:

  • The --usr parameter specifies that SYS user runs the script in each container.

  • The --echo parameter shows output for the SQL statement.

  • The --log_file_base parameter specifies that the base name for log file names is select_output.

  • The SQL statement SELECT * FROM DUAL is inside quotation marks and is preceded by --x. Because --x is preceded by a parameter (--log_file_base), it must be preceded by --.

Default parameter values are used for all other parameters. Neither the -incl_con nor the -excl_con parameter is specified. Therefore, catcon.pl runs the SQL statement in all containers by default.

See Also:

Parent topic: Running Oracle-Supplied SQL Scripts in a CDB

13.5.4 使用DBMS_SQL包在容器中执行代码

当您在CDB中的容器中执行PL/SQL代码时,如果您希望在不同的容器中执行一条或多条SQL语句,请使用DBMS_SQL包来切换容器。
例如,当您需要在多个容器中执行相同的操作时,可以使用DBMS_SQL包来切换容器。

The following are considerations for using DBMS_SQL to switch containers:

  • 事务不能跨多个容器。
    如果必须在目标容器中执行的操作集需要事务,那么可以考虑使用自治事务,并将提交或回滚作为最后一个操作执行。

  • SET ROLE statements are not allowed.

Example 13-40在多个容器中执行相同的操作

这个例子包括一个PL/SQL块,它在两个PDBs (pdb1和pdb2)的hr模式中创建identact表。该示例还在两个PDBs中向identact表插入一行。

DECLARE
  c1 INTEGER;
  rowcount INTEGER;
  taskList VARCHAR2(32767) :=
    'DECLARE
      PRAGMA AUTONOMOUS TRANSACTION;
     BEGIN
       -- Create the hr.identact table.
       EXECUTE IMMEDIATE
         ''CREATE TABLE hr.identact
             (actionno NUMBER(4) NOT NULL,
              action VARCHAR2 (10))'';
       EXECUTE IMMEDIATE
         ''INSERT INTO identact VALUES(1, 'ACTION1')'';
       -- A commit is required if the tasks include DML.
       COMMIT;
       EXCEPTION
         WHEN OTHERS THEN
           -- If there are errors, then drop the table.
           BEGIN
             EXECUTE IMMEDIATE ''DROP TABLE identact'';
           EXCEPTION
            WHEN OTHERS THEN
              NULL;
            END;
        END;';
  TYPE containerListType IS TABLE OF VARCHAR2(128) INDEX BY PLS_INTEGER;
  containerList  containerListType;
BEGIN
  containerList(1) := 'PDB1';
  containerList(2) := 'PDB2';
  c1 := DBMS_SQL.OPEN_CURSOR;
  FOR conIndex IN containerList.first..containerList.last LOOP
    DBMS_OUTPUT.PUT_LINE('Creating in container: ' || containerList(conIndex));
    DBMS_SQL.PARSE(c => c1 ,
                   statement => taskList,
                   language_flag => DBMS_SQL.NATIVE,
                   edition= > NULL,
                   apply_crossedition_trigger => NULL,
                   fire_apply_trigger => NULL,
                   schema => 'HR',
                   container => containerList(conIndex));
     rowcount := DBMS_SQL.EXECUTE(c=>c1);
  END LOOP;
  DBMS_SQL.CLOSE_CURSOR(c=>c1);
END;
/

See Also:

Parent topic: Executing SQL in Multiple Containers

13.6 Shutting Down a CDB Instance

You can shut down a CDB instance in the same way that you shut down a non-CDB instance.

Prerequisites

The following prerequisites must be met:

  • The CDB instance must be mounted or open.

  • The current user must be a common user with SYSDBASYSOPERSYSBACKUP, or SYSDGadministrative privilege. To shut down a CDB, you must exercise this privilege using ASSYSDBAAS SYSOPERAS SYSBACKUP, or AS SYSDG, respectively, at connect time.

To shut down a CDB:

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

    See "Connecting to a Container Using the SQL*Plus CONNECT Command".

  2. Shut down the CDB instance.

See Also:

Parent topic: Administering a CDB

猜你喜欢

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