4 Creating and Configuring a CDB
创建和配置多租户容器数据库(CDB)包括计划、创建CDB和可选配置EM Express等任务。
This section contains the following topics:
- About Creating a CDB
The procedure for creating a multitenant container database (CDB) is similar to the procedure for creating a non-CDB. - Planning for CDB Creation
CDB creation prepares several operating system files to work together as a CDB. - Creating a CDB
You can create a CDB using DBCA or by manually issuing theCREATE DATABASE
SQL statement. - Configuring EM Express for a CDB
For a CDB, you can configure Oracle Enterprise Manager Database Express (EM Express) for the root and for each PDB by setting a global HTTPS port, or you can set a different port for every container in the CDB. - After Creating a CDB
After creation, a CDB consists of the root and the PDB seed.
Parent topic: Creating and Configuring a Multitenant Environment
4.1 About Creating a CDB
创建多租户容器数据库(CDB)的过程与创建非CDB的过程类似。
Oracle数据库管理员指南中描述了创建非cdb的过程。在创建CDB之前,您必须理解本文档中描述的概念和任务。
本章描述创建CDB时的特殊考虑。本章还描述了在Oracle数据库管理员指南中创建非CDB的过程和创建CDB的过程之间的区别。
在您使用“为创建CDB进行规划”中提供的一些指导方针规划您的CDB之后,您可以在安装Oracle数据库软件期间或之后创建CDB。以下是安装后创建CDB的典型原因:
-
您仅使用Oracle Universal Installer (OUI)安装软件,没有创建CDB。
-
您希望在与现有CDB或现有非CDB相同的主机上创建另一个CDB。在这种情况下,本章假设新的CDB使用与现有数据库相同的Oracle home。您还可以通过再次运行OUI在新的Oracle home中创建CDB。
The specific methods for creating a CDB are:
-
With the Database Configuration Assistant (DBCA), a graphical tool.
See "About CDB Creation with DBCA".
-
With the
CREATE DATABASE
SQL statement.See "Creating a CDB".
Parent topic: Creating and Configuring a CDB
4.2 Planning for CDB Creation
CDB创建准备几个操作系统文件作为CDB一起工作。
Note:
Before planning for CDBs, review the conceptual information about CDBs and PDBs in "Introduction to the Multitenant Architecture".
This section contains the following topics:
- Decide How to Configure the CDB
Prepare to create the CDB by research and careful planning. - Prerequisites for CDB Creation
You must complete prerequisites before creating a new CDB.
Parent topic: Creating and Configuring a CDB
4.2.1 Decide How to Configure the CDB
Prepare to create the CDB by research and careful planning.
下表列出了一些适用于CDBs的建议操作和注意事项。有关此表中许多操作的更多信息,请参见Oracle Database Administrator指南。
Table 4-1 Planning for a CDB
Action | Considerations for a CDB | Additional Information |
---|---|---|
计划可插入数据库(PDBs)的表和索引,并估计它们所需的空间量。 | 在CDB中,大多数用户数据都在PDBs中。根目录不包含用户数据或最少的用户数据。规划将成为cdb一部分的PDBs。CDB的磁盘存储空间需求是Oracle数据库安装所需的空间,加上将成为CDB一部分的所有PDBs的空间需求之和。CDB最多可以包含4,096个pdb,但是可以通过设置MAX_PDBSinitialization参数将CDB限制在更少的pdb中。 您还可以在CDB中创建应用程序容器。应用程序容器是存储一个或多个应用程序数据的应用程序pdb的集合。此外,应用程序容器支持用户创建的应用程序公共对象,这些对象可以由应用程序PDBs在应用程序容器中共享。 |
Oracle Database Administrator’s Guide for information about Oracle Database structure and storage Oracle Database Administrator’s Guide for information about schema objects |
计划CDB将包含的底层操作系统文件的布局. |
CDB根目录、PDB$SEED、每个PDB、每个应用程序根目录和每个应用程序PDB都有单独的数据文件。 对于单个实例的CDB有一个重做日志,或者对于Oracle Real Application Clusters (Oracle RAC) CDB的每个实例都有一个重做日志。此外,对于Oracle RAC,所有数据文件和重做日志文件都必须放在共享存储中。 |
Oracle Database Administrator’s Guide for information about using Oracle Managed Files Oracle Automatic Storage Management Administrator's Guide Oracle Database Performance Tuning Guide Oracle Database Backup and Recovery User's Guide Oracle Grid Infrastructure Installation Guide for information about configuring storage for Oracle RAC Your Oracle operating system–specific documentation, including the appropriate Oracle Database installation guide. |
后台进程的数量required by the CDB. |
根目录和所有PDBs共享一组后台进程。 | Oracle Database Administrator’s Guide for information about specifying the maximum number of processes |
选择全局数据库名,即CDB在网络结构中的名称和位置,并通过设置DB_NAME和db_domaininitialize参数为根创建全局数据库名. |
根的全局数据库名就是CDB的全局数据库名。 PDB的全局数据库名称由PDB名称和db_domaininitialize参数定义。 |
Oracle Database Administrator’s Guide for information about determining the global database name |
熟悉可以包含在初始化参数文件中的初始化参数。熟悉服务器参数文件(SPFILE)的概念和操作。SPFILE文件允许您在服务器端磁盘文件中持久存储和管理初始化参数。 | CDB使用单个SPFILE或单个文本初始化参数文件(PFILE)。为根设置的初始化参数值可以由PDBs继承。您可以使用ALTERSYSTEM语句为PDB设置一些初始化参数。 要创建一个CDB, ENABLE_PLUGGABLE_DATABASE初始化参数必须设置为TRUE。 |
Oracle Database Administrator’s Guide for information about specifying initialization parameters "Modifying a CDB with ALTER SYSTEM" |
选择字符集。 | 当根的字符集是AL32UTF8时,插入到CDB或克隆的PDBs可以具有与根不同的字符集。从PDB$SEED创建的PDB继承AL32UTF8字符集,但是可以将PDB迁移到另一个字符集。 Oracle推荐AL32UTF8用于CDB数据库字符集,AL16UTF6用于CDB国家字符集,因为它们提供了最大的灵活性。 |
|
考虑CDB必须支持哪些时区 | 您可以为整个CDB(包括所有PDBs)设置时区。您还可以为每个PDB单独设置时区。 | Oracle Database Administrator’s Guide for information about specifying the database time zone and time zone file |
选择标准数据库块大小。这是由db_block_sizeinitialize参数在CDB创建时指定的,并且在创建CDB之后不能更改 | 标准块大小适用于整个CDB。 | Oracle Database Administrator’s Guide for information about specifying database block sizes |
如果计划将联机重做日志文件存储在具有4K字节扇区大小的磁盘上,则确定是否必须手动指定重做日志块大小。同时,开发一个备份和恢复策略来保护CDB不受失败的影响。 | 对于整个CDB,只有一个重做日志和一个控制文件。 | Oracle Database Administrator’s Guide for information about planning the block size of redo log files 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 Oracle Database Administrator’s Guide for information about managing control files |
确定SYSAUXtablespace的适当初始大小。 | 根目录和每个PDB都有一个单独的SYSAUXtablespace。 | Oracle Database Administrator’s Guide for information about the |
计划为非系统用户使用默认表空间,以防止无意中在系统表空间中保存数据库对象. |
您可以为根目录和每个PDB指定单独的默认表空间。此外,根目录和每个PDB都有一个单独的系统表空间。 | Oracle Database Administrator’s Guide for information about creating a default permanent tablespace |
计划使用默认的临时表空间。 | 对于CDB中的每个容器,都有一个默认的临时表空间,包括根和每个PDB、应用程序根和应用程序PDB。 共享的临时表空间仅用于递归SQL,不被托管的PDB租户直接使用。 |
Oracle Database Administrator’s Guide for information about creating a default temporary tablespace |
计划使用撤销表空间来管理撤销数据。 | CDB可以在不同的撤销模式下运行。可以为整个CDB配置一个活动的undo表空间,也可以为CDB中的每个容器配置一个单独的undo表空间。可以在CDB创建期间指定撤销模式,也可以在创建CDB之后更改撤销模式。 当您为整个CDB选择一个活动的撤销表空间时,将使用共享的撤销,并且禁用本地撤销。在这个配置中,对于一个单实例CDB,有一个活动的undo表空间。当启用本地撤销时,在单个实例配置中,每个容器都有一个撤销表空间。对于Oracle RAC CDB,每个PDB在其打开的每个节点中都有一个undo表空间。对于共享的撤销,只有具有适当特权且当前容器是根目录的普通用户才能创建撤销表空间。 最佳实践是对CDB使用本地撤销。共享撤销主要只支持用于升级和过渡目的。尽管与共享撤销相比,与本地撤销关联的开销较小,但是本地撤销的优点使其在大多数环境中更受欢迎。本地撤销使拔插操作和时间恢复更快,并且对于某些特性(如重新定位PDB)是必需的。默认情况下,DBCA在启用本地撤销的情况下创建新的CDBs。 在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 |
计划满足应用程序需要的数据库服务。 | 根目录和每个PDB可能需要几个服务。您可以为根目录或单个pdb创建服务。 您可以使用SRVCTL实用程序、Oracle Enterprise Manager云控制和DBMS_SERVICE提供的PL/SQL包管理服务。 |
Oracle Database Administrator’s Guide for information about managing application workloads with database services Oracle Database Administrator’s Guide for information about using the SRVCTL utility with a single-instance database Oracle Real Application Clusters Administration and Deployment Guide for information about using the SRVCTL utility with an Oracle RAC database |
熟悉启动和关闭实例以及安装和打开CDB的原则和选项。 | 在CDB中,CDB根和所有容器共享一个实例,或者在使用Oracle RAC时共享多个并发实例。您可以启动和关闭整个CDB,这反过来又决定了托管的PDBs的状态。当CDB打开时,您可以来控制PDBs的打开模式 |
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" |
如果您计划使用Oracle RAC,那么就计划使用Oracle RAC环境。 | Oracle RAC文档描述了在Oracle RAC环境中对于CDB的特殊考虑。 | See your platform-specific Oracle RAC installation guide for information about creating a CDB in an Oracle RAC environment. Oracle Real Application Clusters Administration and Deployment Guide |
避免不受支持的特性。 | Oracle数据库发布说明包含了当前CDB中不支持的Oracle数据库特性列表。 如果必须使用这些特性中的一个或多个,则创建一个非cdb。 |
Oracle Database Administrator’s Guide for information about creating and configuring a database |
Parent topic: Planning for CDB Creation
4.2.2 创建CDB的先决条件
在创建新的CDB之前,您必须完成先决条件。
Before you can create a new CDB, the following prerequisites must be met:
-
确保满足“多租户环境的先决条件”中描述的先决条件。
-
必须有足够的内存来启动Oracle数据库实例。
确定CDB为适应每个容器的工作负载和容器数量所需的内存大小。 -
必须为运行Oracle数据库的计算机上计划的PDBs提供足够的磁盘存储空间。在Oracle RAC环境中,必须有足够的共享存储。
CDB所需的磁盘存储空间是所有驻留在CDB中的PDBs的空间需求的总和。
Oracle数据库安装指南或特定于操作系统的Oracle Grid基础设施安装和升级指南讨论了这些先决条件。如果您使用Oracle Universal Installer,那么它将指导您完成安装,并在设置环境变量、建立目录结构和授权方面提供帮助。
Parent topic: Planning for CDB Creation
4.3 Creating a CDB
可以使用DBCA创建CDB,也可以手动发出 CREATE DATABASE
SQL statement.
Note:
Oracle强烈建议使用数据库配置助手(DBCA)模板部署,而不是使用CREATE Database SQL语句来创建CDB,因为使用DBCA是一种更自动化的方法,并且在DBCA完成时,您的CDB就可以使用了。
This section contains the following topics:
- About CDB Creation with DBCA
Oracle strongly recommends using the Database Configuration Assistant (DBCA) to create a CDB. - About CDB Creation with SQL Statements
Creating a CDB using theCREATE DATABASE
SQL statement is similar to creating a non-CDB. - Creating a CDB with the CREATE DATABASE Statement
When you use theCREATE DATABASE
statement to create a CDB, you must complete additional actions before you have an operational CDB. - Creating a CDB with the CREATE DATABASE Statement: Examples
These examples create a CDB namednewcdb
.
Parent topic: Creating and Configuring a CDB
4.3.1 About CDB Creation with DBCA
Oracle强烈建议使用数据库配置助手(DBCA)创建CDB。
与其他技术相比,DBCA提供了以下优点:
-
创建在很大程度上是自动化的。
-
DBCA允许您在创建CDB时指定PDBs的数量。
-
当DBCA完成时,CDB就可以使用了。
创建CDB后,可以使用DBCA执行以下操作:-
Clone local PDBs
-
Plug in and unplug PDBs
-
Duplicate a CDB (silent mode only)
-
根据选择的安装类型,Oracle Universal Installer (OUI)可以启动DBCA。您还可以在安装Oracle数据库之后的任何时候将DBCA作为独立工具启动。
您可以使用DBCA以下列任何一种模式创建CDB:
-
交互模式
该模式为创建和配置CDB提供了图形化界面和指导工作流。 -
非交互模式(也称为静默模式)
此模式允许您使用适合克隆的自定义PDB种子数据库编写预配置的CDB模板部署脚本。通过指定命令行参数、响应文件或两者兼而有之,以静默模式运行DBCA。
See Also:
-
Oracle Database Administrator’s Guide to learn how to create a database with DBCA
-
The DBCA online help
Parent topic: Creating a CDB
4.3.2 关于使用SQL语句创建CDB
使用CREATE DATABASE SQL语句创建CDB与创建非CDB类似。
本节描述创建CDB的附加要求。使用create数据库创建CDB时,必须执行以下操作:
-
Enable PDBs
-
Specify the names and locations of the CDB root files
-
Specify the names and locations of the
PDB$SEED
files
Note:
Using the CREATE DATABASE
SQL statement is a more manual approach to creating a CDB than using DBCA.
This section contains the following topics:
- About Enabling PDBs
To create a CDB, theCREATE DATABASE
statement must include theENABLE PLUGGABLE DATABASE
clause. - About the Names and Locations of the Files for Root and the PDB Seed
TheCREATE DATABASE
statement uses the root files (such as data files) to generate the names of the files forPDB$SEED
. - About the Attributes of the Data Files for PDB$SEED
You can use the PDB seed (PDB$SEED
) as a template to create new containers. - About the CDB’s Undo Mode
Add the undo_mode_clause to anENABLE PLUGGABLE DATABASE
clause to specify the undo mode of the CDB.
See Also:
Oracle Database Concepts for information about the files in a CDB
Parent topic: Creating a CDB
4.3.2.1 About Enabling PDBs
To create a CDB, the CREATE DATABASE
statement must include the ENABLE PLUGGABLE DATABASE
clause.
This clause affects the CREATE DATABASE
statement as follows:
-
ENABLE PLUGGABLE DATABASE
is included该语句使用根和PDB$SEED创建一个CDB。您永远不能将CDB更改为非CDB.
-
ENABLE PLUGGABLE DATABASE
is not included新创建的数据库是非CDB的,这意味着它不包含CDB根或PDB$SEED。非cdb永远不能包含PDBs。
Parent topic: About CDB Creation with SQL Statements
4.3.2.2 关于根目录和PDB种子文件的名称和位置
The CREATE DATABASE
statement uses the root files (such as data files) to generate the names of the files for PDB$SEED
.
必须为root和PDB$SEED指定文件的名称和位置。成功完成CREATE DATABASE语句后,可以使用PDB$SEED及其文件创建新的PDBs。PDB种子创建后不能修改它。
您必须指定PDB$SEED文件的名称和位置,具体方法如下:
-
The
SEED FILE_NAME_CONVERT
clause -
Oracle Managed Files
-
The
PDB_FILE_NAME_CONVERT
initialization parameter
如果使用的技术不止一种,那么CREATE DATABASE语句将按照前面列表的优先级顺序使用一种技术。例如,如果使用所有技术,那么CREATE DATABASE语句只使用SEED FILE_NAME_CONVERT子句中的规范,因为它是列表中的第一个。
This section contains the following topics:
- The SEED FILE_NAME_CONVERT Clause
TheSEED FILE_NAME_CONVERT
clause of theCREATE DATABASE
statement specifies how to generate the names of thePDB$SEED
files using the names of the CDB root files. - Oracle Managed Files
When Oracle Managed Files is enabled, it can determine the names and locations of thePDB$SEED
files. - The PDB_FILE_NAME_CONVERT Initialization Parameter
ThePDB_FILE_NAME_CONVERT
initialization parameter can specify the names and locations of the seed's files.
See Also:
Parent topic: About CDB Creation with SQL Statements
4.3.2.2.1 The SEED FILE_NAME_CONVERT Clause
CREATE DATABASE语句的SEED FILE_NAME_CONVERT子句指定如何使用CDB根文件的名称生成PDB$SEED文件的名称。
您可以使用此子句指定以下选项之一:
-
一个或多个文件名模式和替换文件名模式,形式如下:
'string1' , 'string2' , 'string3' , 'string4' , ...
string2文件名模式替换了string1文件名模式,string4文件名模式替换了string3文件名模式。您可以根据需要使用任意多对文件名模式和替换文件名模式字符串。
如果指定奇数个字符串(最后一个字符串没有对应的替换字符串),则返回错误。不要指定与单个文件名或目录匹配的多个模式/替换字符串。
文件名模式不能匹配由Oracle托管文件管理的文件或目录。
-
如果不应该转换文件名,则为NONE。省略种子文件FILE_NAME_CONVERTclause与指定NONE相同。
Example 4-1 SEED FILE_NAME_CONVERT Clause
这个SEED FILE_NAME_CONVERT子句使用/oracle/dbs目录中的文件名为/oracle/pdbseed/目录中的PDB$SEED文件生成文件名。
SEED FILE_NAME_CONVERT = ('/oracle/dbs/', '/oracle/pdbseed/')
See Also:
Oracle Database SQL Language Reference for the syntax of the SEED FILE_NAME_CONVERT
clause
Parent topic: About the Names and Locations of the Files for Root and the PDB Seed
4.3.2.2.2 Oracle Managed Files
当启用Oracle托管文件时,它可以确定PDB$SEEDfiles的名称和位置。
See Also:
Oracle Database Administrator’s Guide
Parent topic: About the Names and Locations of the Files for Root and the PDB Seed
4.3.2.2.3 PDB_FILE_NAME_CONVERT初始化参数
PDB_FILE_NAME_CONVERT初始化参数可以指定种子文件的名称和位置。
要使用这种技术,请确保在创建CDB时初始化参数文件中包含PDB_FILE_NAME_CONVERT初始化参数。
在这个初始化参数中指定的文件名模式不能匹配由Oracle托管文件管理的文件或目录。
See Also:
Parent topic: About the Names and Locations of the Files for Root and the PDB Seed
4.3.2.3 关于PDB$SEED数据文件的属性
您可以使用PDB种子(PDB$ seed)作为模板来创建新的容器。
CDB根系统和SYSAUX表空间的数据文件的属性可能不适合PDB种子。在这种情况下,可以使用tablespace_datafile子句为PDB种子数据文件指定不同的属性。使用这些子句为PDB种子中包含系统和SYSAUX表空间的所有数据文件指定属性。从根继承的值用于没有提供值的任何属性。
tablespace_datafile子句的语法与数据文件规范的语法相同,但不包括数据文件的名称和位置以及重用属性。您可以将tablespace_datafile子句与任何指定PDB种子的数据文件的名称和位置的方法一起使用,这些方法在“关于根和PDB种子的文件的名称和位置”中描述。
tablespace_datafile子句不指定PDB种子的数据文件的名称和位置。相反,它们在PDB种子中指定与根文件不同的SYSTEM和SYSAUX数据文件的属性。如果表空间的tablespace_datafile子句中没有指定大小,那么表空间的数据文件大小将被设置为相应根数据文件大小的预定比例。
Example 4-2 Using the tablespace_datafile Clauses
假设以下CREATE DATABASE子句指定组成根目录中的系统和SYSAUX表空间的数据文件的名称、位置和属性。
DATAFILE '/u01/app/oracle/oradata/newcdb/system01.dbf' SIZE 325M REUSE
SYSAUX DATAFILE '/u01/app/oracle/oradata/newcdb/sysaux01.dbf' SIZE 325M REUSE
You can use the following tablespace_datafile
clauses to specify different attributes for these data files:
SEED
SYSTEM DATAFILES
SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES
SIZE 100M
在本例中,PDB种子的系统和SYSAUX表空间的数据文件从根的数据文件继承了REUSEattribute。但是,PDB种子数据文件的以下属性与根文件不同:
-
The data file for the
SYSTEM
tablespace is 125 MB for the PDB seed and 325 MB for the root. -
AUTOEXTEND
is enabled for the PDB seed'sSYSTEM
data file, and it is disabled by default for the root'sSYSTEM
data file. -
The data file for the
SYSAUX
tablespace is 100 MB for the PDB seed and 325 MB for the root.
See Also:
Oracle Database SQL Language Reference for information about data file specifications
Parent topic: About CDB Creation with SQL Statements
4.3.2.4 About the CDB’s Undo Mode
Add the undo_mode_clause to an ENABLE PLUGGABLE DATABASE
clause to specify the undo mode of the CDB.
undo_mode_子句指定CDB撤消模式是本地的还是共享的。本地撤销模式意味着CDB中的每个容器都使用本地撤销。若要为CDB配置本地撤消模式,请将本地撤消指定为ON。共享撤销模式是指对于单个实例的CDB,或者对于Oracle RAC CDB,对于每个实例,都有一个活动的撤销表空间。为CDB配置共享撤消模式, specify LOCAL UNDO OFF
. 如果未将undo_mode_clause添加到ENABLE PLUGGABLE数据库子句中,则默认为共享撤消模式。
Parent topic: About CDB Creation with SQL Statements
4.3.3 Creating a CDB with the CREATE DATABASE Statement
当您使用CREATE DATABASE语句创建CDB时,您必须在拥有可操作的CDB之前完成其他操作。
这些操作包括在数据字典表上构建视图,并在根目录中安装标准PL/SQL包。通过运行提供的catcdb执行这些操作。sql脚本,它安装CDB所需的所有组件。
Prerequisites
Note the following prerequisites:
-
本节中的说明仅适用于单实例数据库安装。有关创建Oracle RAC CDB的说明,请参阅平台的Oracle Real Application Clusters (Oracle RAC)安装指南。
-
如果您使用Oracle ASM来管理磁盘存储,那么在执行这些步骤之前,您必须启动Oracle ASM实例并配置磁盘组。
-
The
ENABLE_PLUGGABLE_DATABASE
initialization parameter must be set totrue
.
To create a CDB with the CREATE DATABASE statement:
-
完成Oracle Database Administrator 's Guide中的“使用CREATE Database语句创建数据库”主题中的步骤1 - 8。
在CDB中,DB_NAME初始化参数指定根的名称。另外,通常的做法是将SID设置为根的名称。此名称的最大字符数为30。有关更多信息,请参阅Oracle数据库参考中关于DB_NAME初始化参数的讨论。 -
使用CREATE DATABASE语句创建一个新的CDB。
参见“使用Oracle托管文件创建CDB:示例”和“不使用Oracle托管文件创建CDB”中的示例。Tip:
如果你创建数据库语句失败,如果你没有完成第7步的“创建一个数据库创建数据库的语句”主题在Oracle数据库管理员指南,然后确保没有一个预先存在的服务器参数文件(SPFILE)这个实例初始化参数设置在一个意想不到的方式。例如,SPFILE包含所有控件文件的完整路径的设置,如果这些控件文件不存在,则CREATE DATABASE语句将失败。在删除一个实例之后,确保关闭并重新启动实例(使用STARTUP NOMOUNT)
-
Run the
catcdb.sql
SQL script.Enter the following in SQL*Plus to run the script:
@?/rdbms/admin/catcdb.sql
-
When prompted by the script, enter the log file directory for parameter
1
and the log file name for parameter2
.For following example enters
/tmp
for the first prompt andcreate_cdb.log
for the second prompt:SQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2 Enter value for 1: /tmp Enter value for 2: create_cdb.log
-
When prompted by the script, enter any other required information.
For example, the scripts prompts for administrator passwords and the temporary tablespace name:
Enter new password for SYS: ******** Enter new password for SYSTEM: ******** Enter temporary tablespace name: TEMP
-
After
catcdb.sql
completes, perform steps 12 - 14 in the “Creating a Database with theCREATE DATABASE
Statement” topic in Oracle Database Administrator’s Guide.
See Also:
-
Oracle Database Administrator’s Guide to learn more about
CREATE DATABASE
clauses and Oracle Managed Files -
Oracle Real Application Clusters Administration and Deployment Guide for more information on Oracle RAC
-
Oracle Database SQL Language Reference to learn more about the clauses and parameter values for the
CREATE DATABASE
statement
Parent topic: Creating a CDB
4.3.4 使用CREATE DATABASE语句创建CDB:示例
These examples create a CDB named newcdb
.
The examples assume that you completed steps 1 - 8 in the “Creating a Database with the CREATE DATABASE
Statement” topic in Oracle Database Administrator’s Guide.
This section contains the following topics:
- Creating a CDB Without Using Oracle Managed Files
The following statement creates a CDB namednewcdb
. This name must agree with theDB_NAME
parameter in the initialization parameter file. - Creating a CDB Using Oracle Managed Files: Example
This example illustrates creating a CDB with Oracle Managed Files, which enables you to use a much simplerCREATE DATABASE
statement.
Parent topic: Creating a CDB
4.3.4.1 在不使用Oracle托管文件的情况下创建CDB
下面的语句创建一个名为newcdb的CDB。这个名称必须与初始化参数文件中的DB_NAMEparameter一致。
Assumptions
本例假设:
-
The initialization parameter file specifies the number and location of control files with the
CONTROL_FILES
parameter. -
The directory
/u01/app/oracle/oradata/newcdb
exists. -
The directory
/u01/app/oracle/oradata/pdbseed
exists. -
The directories
/u01/logs/my
and/u02/logs/my
exist.
这个例子包括ENABLE PLUGGABLE DATABASE子句,该子句使用根和PDB种子创建CDB。这个例子还包括SEED FILE_NAME_CONVERT子句,用于指定PDB种子文件的名称和位置。这个例子还包括tablespace_datafile子句,它们为系统指定PDB种子数据文件的属性,以及与根数据文件不同的SYSAUX表空间。这个例子包括undo_mode_clause,用来指定CDB撤销模式是本地的。
CREATE DATABASE newcdb
USER SYS IDENTIFIED BY sys_password
USER SYSTEM IDENTIFIED BY system_password
LOGFILE GROUP 1 ('/u01/logs/my/redo01a.log','/u02/logs/my/redo01b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 2 ('/u01/logs/my/redo02a.log','/u02/logs/my/redo02b.log')
SIZE 100M BLOCKSIZE 512,
GROUP 3 ('/u01/logs/my/redo03a.log','/u02/logs/my/redo03b.log')
SIZE 100M BLOCKSIZE 512
MAXLOGHISTORY 1
MAXLOGFILES 16
MAXLOGMEMBERS 3
MAXDATAFILES 1024
CHARACTER SET AL32UTF8
NATIONAL CHARACTER SET AL16UTF16
EXTENT MANAGEMENT LOCAL
DATAFILE '/u01/app/oracle/oradata/newcdb/system01.dbf'
SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE '/u01/app/oracle/oradata/newcdb/sysaux01.dbf'
SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
DEFAULT TABLESPACE deftbs
DATAFILE '/u01/app/oracle/oradata/newcdb/deftbs01.dbf'
SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
DEFAULT TEMPORARY TABLESPACE tempts1
TEMPFILE '/u01/app/oracle/oradata/newcdb/temp01.dbf'
SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
UNDO TABLESPACE undotbs1
DATAFILE '/u01/app/oracle/oradata/newcdb/undotbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
ENABLE PLUGGABLE DATABASE
SEED
FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/newcdb/',
'/u01/app/oracle/oradata/pdbseed/')
SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES SIZE 100M
USER_DATA TABLESPACE usertbs
DATAFILE '/u01/app/oracle/oradata/pdbseed/usertbs01.dbf'
SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
LOCAL UNDO ON;
A CDB is created with the following characteristics:
-
The CDB 被命名为newcdb。它的全局数据库名称是newcdb.us.example.com,其中域部分(us.example.com)取自初始化参数文件。有关确定全局数据库名称的信息,请参阅Oracle Database Administrator 's Guide。
-
三个控制文件由CONTROL_FILES初始化参数指定创建,该参数是在初始化参数文件中CDB创建之前设置的。有关指定控制文件的信息,请参阅Oracle数据库管理员指南中的示例初始化参数文件和Oracle数据库管理员指南。
-
用户帐户SYS和SYSTEM的密码设置为您指定的值。密码是区分大小写的。在Oracle数据库的这个版本中,指定SYS和systempassword的两个子句不是必须的。但是,如果指定其中一个子句,则必须指定两个子句。有关这些子句使用的更多信息,请参阅Oracle Database Administrator 's Guide,了解关于为用户SYS和SYSTEM指定密码的信息。
-
新的CDB有三个联机重做日志文件组,每个组有两个成员,如LOGFILE子句中指定的。maxlogfile、MAXLOGMEMBERS和MAXLOGHISTORY定义了重做日志的限制。有关选择重做日志文件数量的信息,请参阅Oracle Database Administrator 's Guide。重做日志的块大小设置为512字节,与磁盘上的物理扇区大小相同。如果块大小与物理扇区大小相同(默认),那么BLOCKSIZE子句是可选的。典型的扇区大小,因此典型的块大小是512。 块大小的允许值为512、1024和4096。对于扇区大小为4K的新磁盘,可以选择将块大小指定为4096。有关计划重做日志文件块大小的更多信息,请参阅Oracle Database Administrator 's Guide。
-
MAXDATAFILES指定可以在CDB中打开的数据文件的最大数量。这个数字会影响控制文件的初始大小。对于CDB,将MAXDATAFILES设置为一个较高的值,该值预期除了CDB根文件之外,所有容器的数据文件的聚合数量。
Note:
在创建CDB期间,可以设置几个限制。其中一些限制受到操作系统限制和影响。例如,如果设置MAXDATAFILES,那么Oracle数据库将在控制文件中分配足够的空间来存储MAXDATAFILESfile文件名,即使CDB最初只有一个数据文件。但是,由于最大控制文件大小是有限的,并且操作系统是独立的,所以您可能无法将所有创建数据库参数设置为其理论最大值。
有关在CDB创建期间设置限制的更多信息,请参阅Oracle数据库SQL语言参考和特定于操作系统的Oracle文档。
-
AL32UTF8字符集用于在这个CDB中存储数据。
-
L16UTF16字符集指定为用于将数据存储在专门定义为NCHAR、NCLOB或NVARCHAR2的列中的国家字符集。
-
系统表空间,由操作系统文件/u01/app/oracle/oradata/newcdb/system01组成。dbf是按照DATAFILE子句指定的方式创建的。如果具有该名称的文件已经存在,那么它将被覆盖。
-
系统表空间被创建为本地管理的表空间。有关创建本地管理的系统表空间的信息,请参阅Oracle Database Administrator 's Guide。
-
创建一个SYSAUX表空间,包含操作系统文件/u01/app/oracle/oradata/newcdb/sysaux01。在SYSAUX数据文件子句中指定的dbf。有关SYSAUX表空间的信息,请参阅Oracle Database Administrator 's Guide。
-
默认表空间子句为这个CDB创建并命名一个默认的永久性表空间。
-
默认临时表空间子句为这个CDB的根创建并命名一个默认临时表空间。有关创建默认临时表空间的信息,请参阅Oracle Database Administrator 's Guide。
-
UNDO表空间子句创建并命名一个UNDO表空间,这个UNDO表空间用于存储这个CDB的UNDO数据。在CDB中,需要一个撤销表空间来管理撤销数据,并且必须将UNDO_MANAGEMENT初始化参数设置为AUTO。如果省略此参数,则默认为AUTO。有关创建undo表空间的信息,请参阅Oracle Database Administrator 's Guide。
-
最初不会归档重做日志文件,因为在这个CREATE DATABASE语句中没有指定ARCHIVELOG子句。这在CDB创建期间是常见的。稍后可以使用ALTER数据库语句切换到ARCHIVELOG模式。与归档相关的newcdb初始化参数文件中的初始化参数为LOG_ARCHIVE_DEST_1和LOG_ARCHIVE_FORMAT。有关管理归档的重做日志文件的信息,请参阅Oracle Database Administrator 's Guide。
-
ENABLE PLUGGABLE DATABASE子句使用根和PDB种子创建一个CDB。
-
FILE_NAME_CONVERT子句和tablespace_datafileclauses需要种子。
-
FILE_NAME_CONVERT子句使用/u01/app/oracle/oradata/pdbseed目录中的文件名为PDB种子目录中的文件生成文件名。
-
The
SYSTEM DATAFILES
clause specifies attributes of the PDB seedSYSTEM
tablespace data file(s) that differ from the root's. -
The
SYSAUX DATAFILES
clause specifies attributes of the PDB seedSYSAUX
tablespace data file(s) that differ from the root's. -
USER_DATA表空间子句创建并命名PDB种子的表空间,用于存储用户数据和Oracle XML DB等数据库选项。使用PDB种子创建的PDB包括这个表空间及其数据文件。根目录不使用本子句中指定的表空间和数据文件。
-
LOCAL UNDO ON子句将CDB的撤销模式设置为LOCAL,这意味着CDB中的每个容器都使用本地撤销。
当以本地撤销模式创建CDB时,PDB种子包含一个撤销表空间,这样从PDB种子创建的任何新PDB都有一个撤销表空间。当通过将PDB插入或克隆远程PDB创建PDB时,源PDB处于共享撤消模式,在PDB第一次打开时自动为PDB创建撤消表空间。
Note:
-
确保CREATE DATABASE语句中使用的所有目录都存在。CREATE DATABASE语句不创建目录。
-
如果不使用Oracle托管文件,那么每个表空间子句必须包含一个DATAFILE或TEMPFILE子句。
-
如果CDB创建失败,那么您可以查看警报日志来确定失败的原因并确定纠正措施。有关查看警报日志的信息,请参阅Oracle Database Administrator的指南。如果接收到包含进程号的错误消息,则检查该进程的跟踪文件。在跟踪文件名中查找包含进程号的跟踪文件。有关更多信息,请参见Oracle数据库管理员指南。
-
要在失败后重新提交CREATE DATABASE语句,必须首先关闭实例并删除前一个CREATE DATABASEstatement创建的任何文件。
Parent topic: Creating a CDB with the CREATE DATABASE Statement: Examples
4.3.4.2 使用Oracle托管文件创建CDB:示例
这个例子演示了使用Oracle托管文件创建CDB,这使您能够使用更简单的CREATE DATABASE语句。
要使用Oracle托管文件,必须设置初始化参数DB_CREATE_FILE_DEST。该参数为CDB创建并自动命名的各种CDB文件定义了基本目录。
The following statement is an example of setting this parameter in the initialization parameter file:
DB_CREATE_FILE_DEST='/u01/app/oracle/oradata'
This example sets the parameter Oracle ASM storage:
DB_CREATE_FILE_DEST = +data
这个例子包括ENABLE PLUGGABLE DATABASE子句,该子句使用根和PDB种子创建CDB。这个例子不包括SEED FILE_NAME_CONVERT子句,因为Oracle托管文件决定PDB种子文件的名称和位置。但是,这个例子包含了tablespace_datafile子句,这些子句指定了系统的PDB种子数据文件的属性,以及与根数据文件不同的SYSAUX表空间。
使用Oracle托管文件和下面的CREATE DATABASE语句,CDB创建系统和SYSAUX表空间,创建语句中指定的其他表空间,并为所有数据文件、控制文件和重做日志文件选择默认大小和属性。请注意,这些属性和此方法设置的其他默认CDB属性可能不适合您的生产环境,因此建议检查生成的配置并在必要时进行修改。
CREATE DATABASE newcdb
USER SYS IDENTIFIED BY sys_password
USER SYSTEM IDENTIFIED BY system_password
EXTENT MANAGEMENT LOCAL
DEFAULT TABLESPACE users
DEFAULT TEMPORARY TABLESPACE temp
UNDO TABLESPACE undotbs1
ENABLE PLUGGABLE DATABASE
SEED
SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
SYSAUX DATAFILES SIZE 100M;
A CDB is created with the following characteristics:
-
The CDB叫 newcdb。它的全局数据库名称是newcdb.us.example.com,其中域部分(us.example.com)取自初始化参数文件。有关确定全局数据库名称的信息,请参阅Oracle Database Administrator 's Guide。
-
用户帐户SYS和SYSTEM的密码设置为您指定的值。密码是区分大小写的。在Oracle数据库的这个版本中,指定SYS和systempassword的两个子句不是必须的。但是,如果指定其中一个子句,则必须指定两个子句。有关这些子句使用的更多信息,请参阅Oracle Database Administrator 's Guide,了解关于为用户SYS和SYSTEM指定密码的信息。
-
The
DEFAULT TABLESPACE
clause creates and names a default permanent tablespace for this CDB. -
默认临时表空间子句为这个CDB的根创建并命名一个默认临时表空间。有关创建默认临时表空间的信息,请参阅Oracle Database Administrator 's Guide。
-
UNDO表空间子句创建并命名一个UNDO表空间,这个UNDO表空间用于存储这个CDB的UNDO数据。在CDB中,需要一个撤销表空间来管理撤销数据,并且必须将UNDO_MANAGEMENT初始化参数设置为AUTO。如果省略此参数,则默认为AUTO。有关创建undo表空间的信息,请参阅Oracle Database Administrator 's Guide。
-
最初不会归档重做日志文件,因为在这个CREATE DATABASE语句中没有指定ARCHIVELOG子句。这在CDB创建期间是常见的。稍后可以使用ALTER数据库语句切换到ARCHIVELOG模式。与归档相关的newcdb初始化参数文件中的初始化参数为LOG_ARCHIVE_DEST_1和LOG_ARCHIVE_FORMAT。有关管理归档的重做日志文件的信息,请参阅Oracle Database Administrator 's Guide。
-
The
ENABLE PLUGGABLE DATABASE
clause creates a CDB with the root and the PDB seed. -
SEED
is required for thetablespace_datafile
clauses. -
The
SYSTEM DATAFILES
clause specifies attributes of the PDB seed'sSYSTEM
tablespace data file(s) that differ from the root's. -
The
SYSAUX DATAFILES
clause specifies attributes of the PDB seed'sSYSAUX
tablespace data file(s) that differ from the root's.
Parent topic: Creating a CDB with the CREATE DATABASE Statement: Examples
4.4 Configuring EM Express for a CDB
对于CDB,可以通过设置一个全局HTTPS端口为根和每个PDB配置Oracle Enterprise Manager Database Express (EM Express),也可以为CDB中的每个容器设置不同的端口。
To configure EM Express for a CDB:
您可以设置一个全局端口,它允许您使用EM Express连接到CDB中的所有PDBs,使用CDB的HTTP或HTTPS端口。或者,您可以为CDB中的每个容器设置不同的HTTP或HTTPS端口。
-
In SQL*Plus, access a container in a CDB.
用户必须具有公共的SYSDBA管理特权,并且您必须在连接时作为SYSDBA使用该特权。容器可以是根或PDB。
-
Set the port in one of the following ways:
-
To set the global port, connect to the
CDB$ROOT
, and issue the following SQL statement to configure the global port for the CDB:exec DBMS_XDB_CONFIG.SETGLOBALPORTENABLED(TRUE);
-
To set the HTTP port for the current container, run the following procedure:
exec DBMS_XDB_CONFIG.SETHTTPPORT(http_port_number);
Replace
http_port_number
with the appropriate HTTP port number. -
To set the HTTPS port for the current container, run the following procedure:
exec DBMS_XDB_CONFIG.SETHTTPSPORT(https_port_number);
Replace
https_port_number
with the appropriate HTTPS port number.
-
-
Access EM Express in one of the following ways:
-
要使用全局端口,请输入数据库配置助手(DBCA)在配置包含PDB的CDB时提供的EM Express URL。当出现EM Express登录屏幕时,指定管理员凭据,并在容器名称字段中输入要连接的PDB的名称。
-
The URL for the HTTP port for a container:
http://database_hostname:http_port_number/em/
将database_hostname替换为运行数据库实例的计算机的主机名,并将http_port_number替换为适当的HTTP端口号。
-
The URL for the HTTPS port for a container:
https://database_hostname:https_port_number/em/
Replace
database_hostname
with the host name of the computer on which the database instance is running, and replacehttps_port_number
with the appropriate HTTPS port number.
当连接到根目录时,EM Express显示数据并支持应用于整个CDB的操作。当连接到PDB时,EM Express显示数据并启用仅应用于PDB的操作。
Note:
If the listener is not configured on port 1521, then you must manually configure the port for EM Express. See Oracle Database 2 Day DBA for instructions.
-
See Also:
Oracle Database 2 Day DBA for more information about EM Express
Parent topic: Creating and Configuring a CDB
4.5 After Creating a CDB
创建之后,CDB由根和PDB种子组成。
根目录包含系统提供的元数据和可以管理PDBs的普通用户。PDB种子是一个模板,您可以使用它来创建新的PDBs。下图显示了一个新创建的CDB。
Figure 4-1 A Newly Created CDB
Description of "Figure 4-1 A Newly Created CDB"
在CDB中,根目录包含最少的用户数据或没有用户数据。用户数据驻留在PDBs中。因此,在创建CDB之后,第一个任务是添加包含用户数据的PDBs。
The following graphic shows a CDB with PDBs.
Figure 4-2 CDB with PDBs
Description of "Figure 4-2 CDB with PDBs"
您可以选择创建一个或多个应用程序容器。应用程序容器由应用程序根和应用程序PDBs组成,它存储一个或多个应用程序的数据。应用程序容器可以存储应用程序公共对象,这些对象包含可由应用程序PDBs在应用程序容器中共享的用户数据。它还可以包含用于在应用程序容器中快速创建应用程序PDBs的应用程序种子。
Figure 4-3 Application Containers in a CDB
Description of "Figure 4-3 Application Containers in a CDB"
当您将PDBs和应用程序容器添加到CDB时,CDB的物理结构与非CDB的物理结构非常相似。a cdb包含以下文件:
-
One control file
-
One active online redo log for a single-instance CDB, or one active online redo log for each instance of an Oracle RAC CDB
-
Sets of temp files
There is one default temporary tablespace for the root of the CDB and one for each PDB, application root, and application PDB.
-
Sets of system data files
The primary physical difference between a CDB and a non-CDB is in the data files. A non-CDB has only one set of system data files. In contrast, a CDB includes one set of system data files for each container in the CDB, including a set of system data files for each PDB, application root, and application PDB. In addition, a CDB has one set of user-created data files for each container. If the CDB is in local undo mode, then each container also has its own undo tablespace and associated data files.
-
Sets of user-created data files
Each PDB has its own set of non-system data files. These data files contain the user-defined schemas and database objects for the PDB.
对于数据库的备份和恢复,建议使用recovery Manager (RMAN)。PDB时间点恢复(PDB PITR)必须与RMAN一起执行。默认情况下,RMAN为CDB打开控制文件自动备份。强烈建议为CDB启用控制文件自动备份,以确保PDB PITR可以撤消添加或删除的数据文件。
由于CDB和非CDB的物理结构相似,所以大多数管理任务对于CDB和非CDB是相同的。然而,一些管理任务是特定于CDBs的。以下几章描述这些任务:
-
"Creating and Removing PDBs and Application Containers"
This chapter documents the following tasks:
-
Creating a PDB using the PDB seed
-
Creating a PDB by cloning an existing PDB or Non-CDB
-
Creating a PDB by relocating it
-
Creating a PDB as a proxy PDB
-
Plugging in a PDB
-
Unplugging a PDB
-
Dropping a PDB
-
-
"Creating and Removing Application Containers and Seeds"
This chapter documents the following tasks:
-
Creating application containers
-
Creating application seeds
-
Unplugging application containers
-
Unplugging application seeds
-
Dropping application containers
-
Dropping application seeds
-
-
This chapter documents the following tasks:
-
Connecting to a container
-
Switching into a container
-
Modifying a CDB
-
Modifying the root
-
Changing the open mode of a PDB
-
Executing DDL statements in a CDB
-
Shutting down the CDB instance
-
-
"Administering CDBs and PDBs with Cloud Control"
This chapter documents the following tasks:
-
Managing CDB storage and schema objects
-
Managing per-container storage and schema objects
-
Monitoring storage and schema alerts
-
Switching into a container
-
Changing the open mode of a PDB
-
-
This chapter documents the following tasks:
-
Connecting to a PDB
-
Modifying a PDB
-
Managing services associated with PDBs
-
-
"Administering Application Containers"
This chapter documents the following tasks:
-
Managing applications in an application container, including installing, upgrading, and patching applications
-
Managing application common objects
-
Issuing DML statements on containers in an application container
-
Partitioning by PDB with container maps
-
-
This chapter documents the following tasks:
-
Querying views for monitoring a CDB and its PDBs
-
Running sample queries that provide information about a CDB and its PDBs
-
-
"Using Oracle Resource Manager for PDBs"
This chapter documents the following tasks:
-
Creating resource plans in a CDB
-
Managing resource plans in a CDB
-
-
"Using Oracle Scheduler with a CDB"
This chapter documents the following topics:
-
DBMS_SCHEDULER
invocations in a CDB -
Job coordinator and slave processes in a CDB
-
Using
DBMS_JOB
-
Processes to close a PDB
-
New and changed views
-
See Also:
-
Oracle Database Concepts for a multitenant architecture documentation roadmap
-
Oracle Database Backup and Recovery User’s Guide for information about RMAN
Parent topic: Creating and Configuring a CDB