Using the CREATE DATABASE Statement to Create a CDB

This section describes creating a CDB using the CREATE DATABASE SQL statement.

Note:

Oracle strongly recommends using the Database Configuration Assistant (DBCA) instead of the CREATE DATABASE SQL statement to create a CDB, because using DBCA is a more automated approach, and your CDB is ready to use when DBCA completes.

This section contains the following topics:

About Creating a CDB with the CREATE DATABASE Statement

Creating a CDB using the CREATE DATABASE SQL statement is very similar to creating a non-CDB. This section describes additional requirements for creating a CDB.

Using the CREATE DATABASE SQL statement is a more manual approach to creating a CDB than using DBCA. One advantage of using this statement over using DBCA is that you can create CDBs from within scripts.

When you create a CDB using the CREATE DATABASE SQL statement, you must enable PDBs and specify the names and locations of the root's files and the seed's files.

This section contains the following topics:

See Also:

Oracle Database Concepts for information about a CDB's files

About Enabling PDBs

To create a CDB, the CREATE DATABASE statement must include the ENABLE PLUGGABLE DATABASE clause. When this clause is included, the statement creates a CDB with the root and the seed.

When the ENABLE PLUGGABLE DATABASE clause is not included in the CREATE DATABASE statement, the newly created database is a non-CDB. The statement does not create the root and the seed, and the non-CDB can never contain PDBs.

About the Names and Locations of the Root's Files and the Seed's Files

The CREATE DATABASE statement uses the root's files (such as data files) to generate the names of the seed's files. You must specify the names and locations of the root's files and the seed's files. After the CREATE DATABASE statement completes successfully, you can use the seed and its files to create new PDBs. The seed cannot be modified after it is created.

You must specify the names and locations of the seed's files in one of the following ways:

  1. The SEED FILE_NAME_CONVERT Clause

  2. Oracle Managed Files

  3. The PDB_FILE_NAME_CONVERT Initialization Parameter

If you use more than one of these methods, then the CREATE DATABASE statement uses one method in the order of precedence of the previous list. For example, if you use all of the methods, then the CREATE DATABASE statement only uses the specifications in the SEED FILE_NAME_CONVERT clause.

The SEED FILE_NAME_CONVERT Clause

The SEED FILE_NAME_CONVERT clause of the CREATE DATABASE statement specifies how to generate the names of the seed's files using the names of root's files.

You can use this clause to specify one of the following options:

  • One or more file name patterns and replacement file name patterns, in the following form:

    1. 'string1' , 'string2' , 'string3' , 'string4' , ...

    The string2 file name pattern replaces the string1 file name pattern, and the string4 file name pattern replaces the string3 file name pattern. You can use as many pairs of file name pattern and replacement file name pattern strings as required.

    If you specify an odd number of strings (the last string has no corresponding replacement string), then an error is returned. Do not specify more than one pattern/replace string that matches a single file name or directory.

    File name patterns cannot match files or directories managed by Oracle Managed Files.

  • NONE when no file names should be converted. Omitting the SEED FILE_NAME_CONVERT clause is the same as specifying NONE.

Example 37-1 SEED FILE_NAME_CONVERT Clause

This SEED FILE_NAME_CONVERT clause generates file names for the seed's files in the /oracle/pdbseed directory using file names in the /oracle/dbs directory.

  1. SEED
  2. FILE_NAME_CONVERT = ('/oracle/dbs/', '/oracle/pdbseed/')
Oracle Managed Files

When Oracle Managed Files is enabled, it can determine the names and locations of the seed's files.

The PDB_FILE_NAME_CONVERT Initialization Parameter

The PDB_FILE_NAME_CONVERT initialization parameter can specify the names and locations of the seed's files. To use this technique, ensure that thePDB_FILE_NAME_CONVERT initialization parameter is included in the initialization parameter file when you create the CDB.

File name patterns specified in this initialization parameter cannot match files or directories managed by Oracle Managed Files.

About the Attributes of the Seed's Data Files

The seed can be used as a template to create new PDBs. The attributes of the data files for the root's SYSTEM and SYSAUX tablespaces might not be suitable for the seed. In this case, you can specify different attributes for the seed's data files by using the tablespace_datafile clauses. Use these clauses to specify attributes for all data files comprising the SYSTEM and SYSAUX tablespaces in the seed. The values inherited from the root are used for any attributes whose values have not been provided.

The syntax of the tablespace_datafile clauses is the same as the syntax for a data file specification, excluding the name and location of the data file and the REUSE attribute. You can use the tablespace_datafile clauses with any of the methods for specifying the names and locations of the seed's data files described in "About the Names and Locations of the Root's Files and the Seed's Files".

The tablespace_datafile clauses do not specify the names and locations of the seed's data files. Instead, they specifies attributes of SYSTEM and SYSAUXdata files in the seed that differ from those in the root. If SIZE is not specified in the tablespace_datafile clause for a tablespace, then data file size for the tablespace is set to a predetermined fraction of the size of a corresponding root data file.

Example 37-2 Using the tablespace_datafile Clauses

Assume the following CREATE DATABASE clauses specify the names, locations, and attributes of the data files that comprise the SYSTEM and SYSAUXtablespaces in the root.

  1. DATAFILE '/u01/app/oracle/oradata/newcdb/system01.dbf' SIZE 325M REUSE
  2. 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:

  1. SEED
  2. SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
  3. SYSAUX DATAFILES SIZE 100M

In this example, the data files for the seed's SYSTEM and SYSAUX tablespaces inherit the REUSE attribute from the root's data files. However, the following attributes of the seed's data files differ from the root's:

  • The data file for the SYSTEM tablespace is 125 MB for the seed and 325 MB for the root.

  • AUTOEXTEND is enabled for the seed's SYSTEM data file, and it is disabled by default for the root's SYSTEM data file.

  • The data file for the SYSAUX tablespace is 100 MB for the seed and 325 MB for the root.

Creating a CDB with the CREATE DATABASE Statement

When you use the CREATE DATABASE statement to create a CDB, you must complete additional actions before you have an operational CDB. These actions include building views on the data dictionary tables and installing standard PL/SQL packages in the root. You perform these actions by running the supplied catcdb.sql script.

The examples in the following steps create a CDB named newcdb.

To create a CDB with the CREATE DATABASE statement:

  1. Complete steps 1 - 8 in "Creating a Database with the CREATE DATABASE Statement".

    To create a CDB, the ENABLE_PLUGGABLE_DATABASE initialization parameter must be set to TRUE.

    In a CDB, the DB_NAME initialization parameter specifies the name of the root. Also, it is common practice to set the SID to the name of the root. The maximum number of characters for this name is 30. For more information, see the discussion of the DB_NAME initialization parameter in Oracle Database Reference.

  2. Use the CREATE DATABASE statement to create a new CDB.

    The following examples illustrate using the CREATE DATABASE statement to create a new CDB:

    Example 1: Creating a CDB Without Using Oracle Managed Files

    The following statement creates a CDB named newcdb. This name must agree with the DB_NAME parameter in the initialization parameter file. This example assumes the following:

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

    This example includes the ENABLE PLUGGABLE DATABASE clause to create a CDB with the root and the seed. This example also includes the SEEDFILE_NAME_CONVERT clause to specify the names and locations of the seed's files. This example also includes tablespace_datafile clauses that specify attributes of the seed's data files for the SYSTEM and SYSAUX tablespaces that differ from the root's.

    1. CREATE DATABASE newcdb
    2. USER SYS IDENTIFIED BY sys_password
    3. USER SYSTEM IDENTIFIED BY system_password
    4. LOGFILE GROUP 1 ('/u01/logs/my/redo01a.log','/u02/logs/my/redo01b.log')
    5. SIZE 100M BLOCKSIZE 512,
    6. GROUP 2 ('/u01/logs/my/redo02a.log','/u02/logs/my/redo02b.log')
    7. SIZE 100M BLOCKSIZE 512,
    8. GROUP 3 ('/u01/logs/my/redo03a.log','/u02/logs/my/redo03b.log')
    9. SIZE 100M BLOCKSIZE 512
    10. MAXLOGHISTORY 1
    11. MAXLOGFILES 16
    12. MAXLOGMEMBERS 3
    13. MAXDATAFILES 1024
    14. CHARACTER SET AL32UTF8
    15. NATIONAL CHARACTER SET AL16UTF16
    16. EXTENT MANAGEMENT LOCAL
    17. DATAFILE '/u01/app/oracle/oradata/newcdb/system01.dbf'
    18. SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
    19. SYSAUX DATAFILE '/u01/app/oracle/oradata/newcdb/sysaux01.dbf'
    20. SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED
    21. DEFAULT TABLESPACE deftbs
    22. DATAFILE '/u01/app/oracle/oradata/newcdb/deftbs01.dbf'
    23. SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED
    24. DEFAULT TEMPORARY TABLESPACE tempts1
    25. TEMPFILE '/u01/app/oracle/oradata/newcdb/temp01.dbf'
    26. SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED
    27. UNDO TABLESPACE undotbs1
    28. DATAFILE '/u01/app/oracle/oradata/newcdb/undotbs01.dbf'
    29. SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED
    30. ENABLE PLUGGABLE DATABASE
    31. SEED
    32. FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/newcdb/',
    33. '/u01/app/oracle/oradata/pdbseed/')
    34. SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED
    35. SYSAUX DATAFILES SIZE 100M
    36. USER_DATA TABLESPACE usertbs
    37. DATAFILE '/u01/app/oracle/oradata/pdbseed/usertbs01.dbf'
    38. SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

    A CDB is created with the following characteristics:

    • The CDB is named newcdb. Its global database name is newcdb.us.example.com, where the domain portion (us.example.com) is taken from the initialization parameter file.

    • Three control files are created as specified by the CONTROL_FILES initialization parameter, which was set before CDB creation in the initialization parameter file. See "Sample Initialization Parameter File" and "Specifying Control Files".

    • The passwords for user accounts SYS and SYSTEM are set to the values that you specified. The passwords are case-sensitive. The two clauses that specify the passwords for SYS and SYSTEM are not mandatory in this release of Oracle Database. However, if you specify either clause, then you must specify both clauses. For further information about the use of these clauses, see "Protecting Your Database: Specifying Passwords for Users SYS and SYSTEM".

    • The new CDB has three online redo log file groups, each with two members, as specified in the LOGFILE clause. MAXLOGFILESMAXLOGMEMBERS, and MAXLOGHISTORY define limits for the redo log. See "Choosing the Number of Redo Log Files". The block size for the redo logs is set to 512 bytes, the same size as physical sectors on disk. The BLOCKSIZE clause is optional if block size is to be the same as physical sector size (the default). Typical sector size and thus typical block size is 512. Permissible values for BLOCKSIZE are 512, 1024, and 4096. For newer disks with a 4K sector size, optionally specify BLOCKSIZE as 4096. See "Planning the Block Size of Redo Log Files" for more information.

    • MAXDATAFILES specifies the maximum number of data files that can be open in the CDB. This number affects the initial sizing of the control file.

      Note:

      You can set several limits during CDB creation. Some of these limits are limited by and affected by operating system limits. For example, if you set MAXDATAFILES, then Oracle Database allocates enough space in the control file to store MAXDATAFILES filenames, even if the CDB has only one data file initially. However, because the maximum control file size is limited and operating system dependent, you might not be able to set all CREATE DATABASE parameters at their theoretical maximums.

      For more information about setting limits during CDB creation, see the Oracle Database SQL Language Referenceand your operating system–specific Oracle documentation.

    • The AL32UTF8 character set is used to store data in this CDB.

    • The AL16UTF16 character set is specified as the NATIONAL CHARACTER SET used to store data in columns specifically defined as NCHARNCLOB, or NVARCHAR2.

    • The SYSTEM tablespace, consisting of the operating system file /u01/app/oracle/oradata/newcdb/system01.dbf, is created as specified by the DATAFILE clause. If a file with that name already exists, then it is overwritten.

    • The SYSTEM tablespace is created as a locally managed tablespace. See "Creating a Locally Managed SYSTEM Tablespace".

    • SYSAUX tablespace is created, consisting of the operating system file /u01/app/oracle/oradata/newcdb/sysaux01.dbf as specified in theSYSAUX DATAFILE clause. See "About the SYSAUX Tablespace".

    • The DEFAULT TABLESPACE clause creates and names a default permanent tablespace for this CDB.

    • The DEFAULT TEMPORARY TABLESPACE clause creates and names a default temporary tablespace for this CDB. See "Creating a Default Temporary Tablespace".

    • The UNDO TABLESPACE clause creates and names an undo tablespace that is used to store undo data for this CDB. In a CDB, an undo tablespace is required to manage the undo data, and the UNDO_MANAGEMENT initialization parameter must be set to AUTO. If you omit this parameter, then it defaults to AUTO. See "Using Automatic Undo Management: Creating an Undo Tablespace".

    • Redo log files will not initially be archived, because the ARCHIVELOG clause is not specified in this CREATE DATABASE statement. This is customary during CDB creation. You can later use an ALTER DATABASE statement to switch to ARCHIVELOG mode. The initialization parameters in the initialization parameter file for newcdb relating to archiving are LOG_ARCHIVE_DEST_1 and LOG_ARCHIVE_FORMAT. See Chapter 12, "Managing Archived Redo Log Files".

    • The ENABLE PLUGGABLE DATABASE clause creates a CDB with the root and the seed.

    • SEED is required for the FILE_NAME_CONVERT clause and the tablespace_datafile clauses.

    • The FILE_NAME_CONVERT clause generates file names for the seed's files in the /u01/app/oracle/oradata/pdbseed directory using file names in the /u01/app/oracle/oradata/newcdb directory.

    • The SYSTEM DATAFILES clause specifies attributes of the seed's SYSTEM tablespace data file(s) that differ from the root's.

    • The SYSAUX DATAFILES clause specifies attributes of the seed's SYSAUX tablespace data file(s) that differ from the root's.

    • The USER_DATA TABLESPACE clause creates and names the seed's tablespace for storing user data and database options such as Oracle XML DB. PDBs created using the seed include this tablespace and its data file. The tablespace and data file specified in this clause are not used by the root.

    Note:

    • Ensure that all directories used in the CREATE DATABASE statement exist. The CREATE DATABASE statement does not create directories.

    • If you are not using Oracle Managed Files, then every tablespace clause must include a DATAFILE or TEMPFILEclause.

    • If CDB creation fails, then you can look at the alert log to determine the reason for the failure and to determine corrective actions. See "Viewing the Alert Log". If you receive an error message that contains a process number, then examine the trace file for that process. Look for the trace file that contains the process number in the trace file name. See "Finding Trace Files" for more information.

    • To resubmit the CREATE DATABASE statement after a failure, you must first shut down the instance and delete any files created by the previous CREATE DATABASE statement.

Oracle Multitenant Environment (四) Create One or More CDBs的更多相关文章

  1. Oracle Multitenant Environment (五) Create PDB

    Creating and Removing PDBs with SQL*Plus This chapter contains the following topics: About Creating ...

  2. Oracle Multitenant Environment (一) About

    About oracle mulittenant environment The multitenant architecture enables an Oracle database to func ...

  3. Oracle Multitenant Environment (三) Plan for a cdb

    Below tables contains contant you need to consider while planning for a CDB. Action Considerations f ...

  4. Oracle Multitenant Environment (二) Purpose

    Purpose of a Multitenant Environment A multitenant environment enables the central management of mul ...

  5. Oracle创建表语句(Create table)语法详解及示例、、 C# 调用Oracle 存储过程返回数据集 实例

    Oracle创建表语句(Create table)语法详解及示例 2010-06-28 13:59:13|  分类: Oracle PL/SQL|字号 订阅 创建表(Create table)语法详解 ...

  6. Oracle 物理结构(四) 文件-控制文件

    一.什么是控制文件 控制文件是Oracle数据库中十分重要的文件.Oracle启动时,首先会读取参数文件,读取了参数文件,实例所需要的共享内存和后台进程就可以启动了,这就是数据库实例的nomunt阶段 ...

  7. oracle 学习笔记(四)

    1. SQL(高级查询) 1.1. 子查询 1.1.1. 子查询在WHERE子句中 在SELECT查询中,在WHERE查询条件中的限制条件不是一个确定的值,而是来自于另外一个查询的结果.为了给查询提供 ...

  8. Oracle补习班第四天

    Everything has its time and that time must be watched. 万物皆有时,时来不可失 1,管理参数文件 参数文件分两种spfile二进制文件和pfile ...

  9. ORACLE profile列4 --CREATE PROFILE

    这个博客是ORACLE profile系列第四部分.主要说一下,假设你创建profile而使用profile资源和password控制 CREATE PROFILE Note: Oracle reco ...

随机推荐

  1. CF869C The Intriguing Obsession

    思路: 分别在两种不同颜色的岛屿群之间进行搭桥.因为相同颜色的岛屿之间不能有边,任意两个相同颜色的岛屿不能同时和另外一个不同颜色的岛屿都有边.实现: #include <bits/stdc++. ...

  2. ionic3带参数返回原来页面

    最近用ionic3+angular4做项目.我遇到了个问题,我返回原来页面时一般都会调用this.navCtrl.pop()方法,但这个方法不能携带参数.怎么办? 可以写个回调方法. 我在a页面定义个 ...

  3. 关于 VS 调用存储过程加载很慢和SQL 执行很快的那些事

    执行同样的存储过程,调用同样的参数 在VS 中调用存储过程和传参后,到数据加载需要20秒或更多, 在SQL直接调用则不到一秒,同一个存储过程为什么有这么大的区别呢? 原因:存储过程计划失效的原因 产生 ...

  4. npm换淘宝源 yarn换淘宝源

    查询初始的源 npm get registry > https://registry.npmjs.org/ 设置淘宝源 npm config set registry http://regist ...

  5. codeforces_455B

    B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  6. 系统异常 NSException.h

    FOUNDATION_EXPORT NSExceptionName const NSGenericException; FOUNDATION_EXPORT NSExceptionName const ...

  7. Mybatis学习总结二

    Mapper动态代理开发方式 实现原理: Mapper接口开发方法只需要程序员编写Mapper接口(相当于Dao接口),由Mybatis框架根据接口定义创建接口的动态代理对象. Mapper接口开发需 ...

  8. 02Microsoft SQL Server 安装,卸载,系统服务,系统组件及系统数据库

    Microsoft SQL Server 安装,卸载,系统服务,系统组件及系统数据库 1. Microsoft SQL Server 安装 通过单击下拉框,选择浏览,然后在Active Directo ...

  9. flipt 一个基于golang 的特性工具开发类库

    以前介绍过一个Flagr 的基于golang 的特性功能开发类库(技术雷达推荐),今天看到一个类似也很不错的方案flipt 参考架构 包含的特性 快速,使用golang 编写,同时进行了性能优化 运行 ...

  10. gym101673G. A Question of Ingestion (DP)

    题意:有最多100天 每天有一个食物量 你一开始有一个最大胃口表示你最开始能吃多少食物 如果你昨天吃了 那么今天的胃口为昨天的2/3 如果你前天吃了 昨天没吃 那么你的胃口可以恢复到前天的情况 如果你 ...