Oracle12c新特性大全(二)CDB的创建

Managing a Multitenant Environment官方文档链接:

https://docs.oracle.com/en/database/oracle/oracle-database/12.2/admin/managing-a-multitenant-environment.html#GUID-93F1E584-D309-4301-82E0-AD0E60D4977C

 

CDB的创建:

如果要使用可插拔数据库的功能,需要在创建数据库时专门指定启用可插拔数据库,创建CDB通常有如下两种方式:

· 使用DBCA图形工具创建CDB\
    这里需要注意的是Oracle 12.2之后支持LOCAL UNDO,这里注意需要手动要勾选LOCAL UNDO选项。

· CREATE DATABASE语句创建CDB\
    在使用脚本创建CDB时Oracle提供了两种方法,一种是使用OMF,另外一种是非OMF**的方式,注意参数文件中需要将ENABLE_PLUGGABLE_DATABASE设置为TRUE。

 
这里演示使用非OMF方式创建CDB,数据名称为ora12c:\
1.设置ENABLE_PLUGGABLE_DATABASE参数为TRUE,参数文件如下:

audit_file_dest='/u01/app/oracle/admin/ora12c/adump'

audit_trail='none'

compatible='12.2.0'

control_files='/u01/app/oracle/oradata/ora12c/control01.ctl','/u01/app/oracle/oradata/ora12c/control02.ctl'

db_block_size=8192

db_domain='linux.com'

db_name='ora12c'

diagnostic_dest='/u01/app/oracle'

enable_pluggable_database=true

memory_target=801m

nls_language='AMERICAN'

nls_territory='AMERICA'

remote_login_passwordfile='EXCLUSIVE'

undo_tablespace='UNDOTBS1'

 

2.创建相应目录以及设置环境变量

export ORACLE_SID=ora12c

export ORACLE_HOME=$ORACLE_BASE/product/12.2.0/dbhome_1

export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/OPatch: **$ORACLE_HOME/perl/bin**:$ORACLE_HOME/jdk/bin:$PATH

 

3.CREATE DATABASE脚本 createdb.sql 如下:

CREATE DATABASE ora12c

USER SYS IDENTIFIED BY oracle

USER SYSTEM IDENTIFIED BY oracle

LOGFILE GROUP 1 ('/u01/app/oracle/oradata/ora12c/redo01a.log','/u01/app/oracle/oradata/ora12c/redo01b.log')

           SIZE 100M BLOCKSIZE 512,

        GROUP 2 ('/u01/app/oracle/oradata/ora12c/redo02a.log','/u01/app/oracle/oradata/ora12c/redo02b.log')

           SIZE 100M BLOCKSIZE 512,

        GROUP 3 ('/u01/app/oracle/oradata/ora12c/redo03a.log','/u01/app/oracle/oradata/ora12c/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/ora12c/system01.dbf'

  SIZE 700M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED

SYSAUX DATAFILE '/u01/app/oracle/oradata/ora12c/sysaux01.dbf'

  SIZE 550M REUSE AUTOEXTEND ON NEXT 10240K MAXSIZE UNLIMITED

DEFAULT TABLESPACE deftbs

   DATAFILE '/u01/app/oracle/oradata/ora12c/deftbs01.dbf'

   SIZE 500M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED

DEFAULT TEMPORARY TABLESPACE tempts1

   TEMPFILE '/u01/app/oracle/oradata/ora12c/temp01.dbf'

   SIZE 20M REUSE AUTOEXTEND ON NEXT 640K MAXSIZE UNLIMITED

UNDO TABLESPACE undotbs1

   DATAFILE '/u01/app/oracle/oradata/ora12c/undotbs01.dbf'

   SIZE 200M REUSE AUTOEXTEND ON NEXT 5120K MAXSIZE UNLIMITED

ENABLE PLUGGABLE DATABASE

  SEED

  FILE_NAME_CONVERT = ('/u01/app/oracle/oradata/ora12c/',

                       '/u01/app/oracle/oradata/ora12c/pdbseed/')

  SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED

  SYSAUX DATAFILES SIZE 100M

USER_DATA TABLESPACE usertbs

  DATAFILE '/u01/app/oracle/oradata/ora12c/pdbseed/usertbs01.dbf'

  SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

 

--注意:官方文档的示例代码中使用了LOCAL UNDO ON子句的方式开启local undo mode,但我的测试环境中测试时如果加有LOCAL UNDO ON,报:ORA-02165: invalid option for CREATE DATABASE,那我这里在创建CDB时不开启local undo mode,在CDB创建完成后手动开启local undo mode。

这段代码中只有红色字体部分与PDB有关,其他部分与创建传统的Oracle数据库语句均相同。

 

FILE_NAME_CONVERT    子句指定了使用'/u01/app/oracle/oradata/ora12c/'中的文件名在'/u01/app/oracle/oradata/ora12c/pdbseed/'中生产CDB seeds。

 

USER_DATA_TABLESPACE    子句可以在容器中创建额外的表空间,这个表空间在后续使用PDB$SEED创建PDB时会被复制到PDB中。

 

4.将数据库启动到nomount状态,然后执行上面createdb.sql脚本创建CDB

**

startup nomount;

@createdb.sql

当数据库创建成功之后可以看到新建立的数据库被加入到/etc/oratab文件中。

cat /etc/oratab

+ASM:/u01/app/11.2.0/grid:N

ora12c: /u01/app/oracle/product/12.2.0/dbhome_1:N

orcl:/u01/app/oracle/product/11.2.0/dbhome_1:N          # line added by Agent

newdb:/u01/app/oracle/product/12.2.0/dbhome_1:N

yyh:/u01/app/oracle/product/12.2.0/dbhome_1:N

 

5.查看监听,根容器的服务ora12c.linux.com已经被注册到监听中。

Service "ora12c.linux.com" has 1 instance(s).

  Instance "ora12c", status READY, has 1 handler(s) for this service...

 

6.运行catcdb.sql脚本创建CDB相关视图,运行之前请看下面的注意事项:

@?/rdbms/admin/catcdb.sql

 注意事项:

1.在catcdb.pl执行过中需要输入两个参数,文档中并没有指出是什么参数,

第一个参数应输入: $ORACLE_HOME/rdbms/admin

第二个参数应输入:catcdb.pl

 

2.环境变量中必须将$ORACLE_HOME/perl/bin指定到PATH中,否则报如下错误:

Can't locate Term/ReadKey.pm

3.需要将$ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash中的catcdb.pl文件内容:

use Data::Dumper;

use util qw(trim, splitToArray);

use catcon qw(catconSqlplus);

更改为

use Data::Dumper;

use Util qw(trim, splitToArray);

use catcon qw(catconSqlplus);

 

4.切换到$ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash目录中,然后sqlplus连接到数据,在执行catcdb.sql,否则报如下错误:

Can't locate Util.pm

 

5.开启local undo mode(因为上面再创建CDB时没有加入local undo mode子句)*

sys. ora12c>shutdown immediate

sys. ora12c>startup upgrade

sys. ora12c>alter database local undo on;

 
Database altered.
 

Elapsed: 00:00:00.72

查看是否为local undo mode:

SELECT property_name, property_value

FROM database_properties

WHERE property_name='LOCAL_UNDO_ENABLED';

 

PROPERTY_NAME        PROPERTY_VALUE


LOCAL_UNDO_ENABLED   TRUE

 

Elapsed: 00:00:00.02

sys. ora12c>

 

重启数据库

shutdown immediate

startup

启动数据库的过程中会在PDB$SEED中自动创建UNDO表空间,提供给后来采用PDB$SEED方式创建PDB所使用。

PS:如果CDB中已经存在多个PDB,当在根容器中使用alter database local undo on;开启local undo mode时会自动为每个PDB创建local undo。

 

 

6.检查CDB是否已经创建成功

sys. ora12c>SELECT dbid, name, open_mode, cdb, con_id FROM v$database;

 

      DBID NAME      OPEN_MODE            CDB     CON_ID


 323027068 ORA12C    READ WRITE           YES          0

 

Elapsed: 00:00:00.11

sys. ora12c>

 

此时CDB中含有两个容器:根容器CDB$ROOT和种子容器PDB$SEED,如下:

sys. ora12c>SELECT con_id, dbid, con_uid, guid, name FROM v$containers;

 

CON_ID       DBID    CON_UID GUID                              NAME


     1  323027068          1 50A57CDEFD150C96E0530838A8C0206E  CDB$ROOT

     2 1453953285 1453953285 50A57CDEFD160C96E0530838A8C0206E  PDB$SEED

 

Elapsed: 00:00:00.00

sys. ora12c>SELECT con_id, tablespace_name, file_id, file_name

FROM cdb_data_files;

 

CON_ID TABLESPACE_NAME FILE_ID FILE_NAME


     1 SYSTEM                1 /u01/app/oracle/oradata/ora12c/system01.dbf

     1 SYSAUX                3 /u01/app/oracle/oradata/ora12c/sysaux01.dbf

     1 UNDOTBS1              5 /u01/app/oracle/oradata/ora12c/undotbs01.dbf

     1 DEFTBS                6 /u01/app/oracle/oradata/ora12c/deftbs01.dbf

 

Elapsed: 00:00:00.01

sys. ora12c>show con_id con_name user

 

CON_ID


1

 

CON_NAME


CDB$ROOT

USER is "SYS"

sys. ora12c>

你可能感兴趣的:(oracle数据库sql)