使用 SQL*Plus 创建新 CDB 的具体步骤如下所示:
1. 启动实例之前,使用常用参数准备 init
export ORACLE_SID=LHRCDB1
orapwd file=$ORACLE_HOME/dbs/orapw LHRCDB1 password=lhr format=12 entries=20
vi $ORACLE_HOME/dbs/initLHRCDB1.ora
DB_NAME = LHRCDB1
DB_BLOCK_SIZE =8192
ENABLE_PLUGGABLE_DATABASE =true
db_create_file_dest='+DATA'
sqlplus / as sysdba
startup nomount
2. 通过使用 CREATE DATABASE 命令和新子句 ENABLE PLUGGABLE DATABASE 创建 CDB 。该子句指定数据库为 CDB 而不是非 CDB 。此时会创建根容器和种子可插入数据库。您可以使用另一个子句 SEED FILE_NAME_CONVERT 指定种子文件的位置。如果省略此子句, OMF 会决定种子文件的名称和位置。 FILE_NAME_CONVERT 指定复制到目标种子目录的根数据文件的源目录。如果使用新的 init.ora 参数 PDB_FILE_NAME_CONVERT 将根数据文件的名称映射到种子数据文件,则会忽略 SEED FILE_NAME_CONVERT 子句。在本例中, /oracle/dbs 和 /oracle/seed 目录必须存在。在语句中定义的字符集依然是 CDB 的唯一字符集。
create database LHRCDB1
user sys identified by lhr
user system identified by lhr
extent management local
default tablespace users
default temporary tablespace temp
undo tablespace undotbs1
enable pluggable database
seed;
3. 运行 catcdb.sql SQL 脚本。此脚本将安装 CDB 所需的全部组件。
@? /rdbms/admin/catcdb.sql
使用create database创建CDB的具体操作如下:
1.指定实例标识(SID)
ORACLE_SID环境变量被用来区分不同的实例。
1.决定实例的唯一标识SID
2.打开命令窗口
3.设置ORACLE_SID环境变量
在Unix/Linux下设置ORACLE_SID环境变量如下:
export ORACLE_SID=mynewdb
或
setenv ORACLE_SID=mynewdb
在Windows下设置ORACLE_SID环境变量如下:
set ORACLE_SID=mynewdb
2.确保所需的环境变量被设置
依赖于平台,在启动SQL*Plus之后,可能需要设置相关的环境变量,或者验证相关的设置。例如,在大多数平台中,ORACLE_SID与ORACLE_HOME必须设置。另外,建议PATH环境变量包含ORACLE_HOME/bin目录。在Unix/Linux平
台中,必须手动设置这些环境变量。在Windows平台中,OUI会自动设置ORACLE_HOME与ORACLE_SID。如果在安装期间不创建数据库,OUI不会设置ORACLE_SID,并且在之后创建数据库时必须要设置ORACLE_SID环境变量。
3.选择数据库管理员审核方法
为了创建数据库,用户必须被审核并且被授予相关的系统权限。审核方法有以下两种:
.使用密码文件
.使用操作系统审核
4.创建初始化参数文件
当Oracle实例启动时,它将读取初始化参数文件。这个参数文件可以是文本文件可以使用文本编辑器进行编辑,或者是二进制文件,可以由数据库进行动态修改。二进制参数文件也叫服务器参数文件。对于这一步操作,可以先创建一个文本参数文件,之后通过文本参数文件来创建服务器参数文件。
5.创建实例只限于Windows平台
对于Windows平台,在连接实例之前,必须手动创建实例。ORADIM命令就是用来创建新实例,其语法如下:oradim -NEW -SID sid -STARTMODE MANUAL -PFILE file.注意在创建新实例时,不要将-STARTMODE参数指定为AUTO,因为这会造成新实例启动与mount数据库,而这时数据库是不存在的。
6.连接实例
启动SQL*Plus并且使用有sysdba权限的用户连接到数据库实例。
.使用密码文件进行审核,输入以下命令并输入sys用户的密码
$sqlplus /nolog
SQL>connect sys as sysdba
.使用操作系统审核,输入以下命令
$sqlplus /nolog
SQL>conn / as sysdba
7.创建服务器参数文件
服务器参数文件能通过alter system命令来修改参数,并且这种修改会永久生效。可以通过文本参数文件来创建服务器参数文件。
8.启动实例
启动实例但不mount数据库执行以下命令
startup nomount
9.使用create database语句来创建CDB
当使用create database语句来创建CDB时,必须在操作CDB之前完成额外的操作。这些操作包含对数据字典表创建视图,安装标准的PL/SQL包。执行catcdb.sql脚本。
使用create database语句来创建语句需要注意
9.1 将enable_pluggable_database参数设置为true。在CDB中,db_name参数指定root的名称。将SID设置为root名称是常见的做法。这个名称最多有30个字符。
9.2使用create database语句来创建新的CDB。
9.2.1 不使用OMF来创建CDB
9.2.2 使用OMF来创建CDB
不使用OMF来创建CDB
下面的例子将介绍如何不使用OMF功能来创建CDB
1.设置SID
[root@jytest3 ~]# su - oracle Last login: Fri Aug 4 15:07:33 CST 2017 [oracle@jytest3 ~]$ cd $ORACLE_HOME/dbs [oracle@jytest3 dbs]$ export ORACLE_SID=test
2.创建密码文件
[oracle@jytest3 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwtest password=abcdefg format=12.2 entries=20
3.创建初始化参数
[oracle@jytest3 dbs]$ vi inittest.ora db_name='test' memory_target=4G memory_max_target=4G control_files='+data/test/controlfile/testcdb/control01.ctl','+data/test/controlfile/testcdb/control02.ctl' enable_pluggable_database=true
4.启动实例但不mount
[oracle@jytest3 dbs]$ export ORACLE_SID=test [oracle@jytest3 dbs]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Fri Aug 4 20:59:37 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to an idle instance. SQL> startup pfile='$ORACLE_HOME/dbs/inittest.ora' nomount ORACLE instance started. Total System Global Area 4294967296 bytes Fixed Size 8628936 bytes Variable Size 2315257144 bytes Database Buffers 1962934272 bytes Redo Buffers 8146944 bytes
5.执行create database语句来创建CDB
下面的语句将创建一个名为test的CDB数据库。这个名字与参数文件中的db_name同名。并且满足以下条件:
.已经设置control_files参数
.创建了+data/test/datafile/testcdb目录
.创建了+data/test/datafile/pdbseed目录
.创建了+data/test/onlinelog/testcdb目录
为了创建包含root与CDB seed的CDB库在create database语句中包含了enable pluggable database子句。在这个例子还包含了seed file_name_convert子句来指定CDB seed文件的文件名与目录。
SQL> create database test 2 user sys identified by xxzx_7817600 3 user system identified by xxzx_7817600 4 logfile group 1 ('+data/test/onlinelog/testcdb/redo01.log') 5 size 100m blocksize 512, 6 group 2 ('+data/test/onlinelog/testcdb/redo02.log') 7 size 100m blocksize 512, 8 group 3 ('+data/test/onlinelog/testcdb/redo03.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 '+data/test/datafile/testcdb/system01.dbf' 18 size 700m reuse autoextend on next 10240k maxsize unlimited 19 sysaux datafile '+data/test/datafile/testcdb/sysaux01.dbf' 20 size 550m reuse autoextend on next 10240k maxsize unlimited 21 default tablespace deftbs 22 datafile '+data/test/datafile/testcdb/deftbs01.dbf' 23 size 500m reuse autoextend on maxsize unlimited 24 default temporary tablespace tempts1 25 tempfile '+data/test/datafile/testcdb/temp01.dbf' 26 size 20m reuse autoextend on next 640k maxsize unlimited 27 undo tablespace undotbs1 28 datafile '+data/test/datafile/testcdb/undotbs01.dbf' 29 size 200m reuse autoextend on next 5120k maxsize unlimited 30 enable pluggable database 31 seed file_name_convert = ('+data/test/datafile/testcdb/','+data/test/datafile/pdbseed/') 32 local undo on; Database created.
6.执行脚本$ORACLE_HOME/rdbms/admin/catcdb.sql
SQL> @$ORACLE_HOME/rdbms/admin/catcdb.sql SQL> SQL> Rem The script relies on the caller to have connected to the DB SQL> SQL> Rem This script invokes catcdb.pl that does all the work, so we just need to SQL> Rem construct strings for $ORACLE_HOME/rdbms/admin and SQL> Rem $ORACLE_HOME/rdbms/admin/catcdb.pl SQL> SQL> Rem $ORACLE_HOME SQL> column oracle_home new_value oracle_home noprint SQL> select sys_context('userenv', 'oracle_home') as oracle_home from dual; SQL> SQL> Rem OS-dependent slash SQL> column slash new_value slash noprint SQL> select sys_context('userenv', 'platform_slash') as slash from dual; SQL> SQL> Rem $ORACLE_HOME/rdbms/admin SQL> column rdbms_admin new_value rdbms_admin noprint SQL> select '&&oracle_home'||'&&slash'||'rdbms'||'&&slash'||'admin' as rdbms_admin from dual; old 1: select '&&oracle_home'||'&&slash'||'rdbms'||'&&slash'||'admin' as rdbms_admin from dual new 1: select '/u01/app/oracle/product/12.2.0/db'||'/'||'rdbms'||'/'||'admin' as rdbms_admin from dual SQL> SQL> Rem $ORACLE_HOME/rdbms/admin/catcdb.pl SQL> column rdbms_admin_catcdb new_value rdbms_admin_catcdb noprint SQL> select '&&rdbms_admin'||'&&slash'||'catcdb.pl' as rdbms_admin_catcdb from dual; old 1: select '&&rdbms_admin'||'&&slash'||'catcdb.pl' as rdbms_admin_catcdb from dual new 1: select '/u01/app/oracle/product/12.2.0/db/rdbms/admin'||'/'||'catcdb.pl' as rdbms_admin_catcdb from dual SQL> SQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2 Enter value for 1: Enter value for 2: Can't locate Term/ReadKey.pm in @INC (you may need to install the Term::ReadKey module) (@INC contains: /u01/app/oracle/product/12.2.0/db/rdbms/admin /usr/lib/perl5/site_perl/5.22.0/x86_64-linux /usr/lib/perl5/site_perl/5.22.0 /usr/lib/perl5/5.22.0/x86_64-linux /usr/lib/perl5/5.22.0 .) at /u01/app/oracle/product/12.2.0/db/rdbms/admin/catcdb.pl line 30. BEGIN failed--compilation aborted at /u01/app/oracle/product/12.2.0/db/rdbms/admin/catcdb.pl line 30.
对于这种错误参考了杨建荣的解决方法,抛出的错误提示找不到ReadKey.pm,Linux,Unix其实都是自带Perl的,但这里需要的文件在$ORACLE_HOME下的Perl目录,只需要把这个目录引用到PATH变量中就可以了,比如:
export PATH=$PATH:$ORACLE_HOME/OPatch:$ORACLE_HOME/perl/bin:$ORACLE_HOME/jdk/bin
[oracle@jytest3 dbs]$ export PATH=$PATH:$ORACLE_HOME/OPatch:$ORACLE_HOME/perl/bin:$ORACLE_HOME/jdk/bin [oracle@jytest3 dbs]$ export ORACLE_SID=test [oracle@jytest3 dbs]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Fri Aug 4 22:12:56 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> @$ORACLE_HOME/rdbms/admin/catcdb.sql SQL> SQL> Rem The script relies on the caller to have connected to the DB SQL> SQL> Rem This script invokes catcdb.pl that does all the work, so we just need to SQL> Rem construct strings for $ORACLE_HOME/rdbms/admin and SQL> Rem $ORACLE_HOME/rdbms/admin/catcdb.pl SQL> SQL> Rem $ORACLE_HOME SQL> column oracle_home new_value oracle_home noprint SQL> select sys_context('userenv', 'oracle_home') as oracle_home from dual; SQL> SQL> Rem OS-dependent slash SQL> column slash new_value slash noprint SQL> select sys_context('userenv', 'platform_slash') as slash from dual; SQL> SQL> Rem $ORACLE_HOME/rdbms/admin SQL> column rdbms_admin new_value rdbms_admin noprint SQL> select '&&oracle_home'||'&&slash'||'rdbms'||'&&slash'||'admin' as rdbms_admin from dual; old 1: select '&&oracle_home'||'&&slash'||'rdbms'||'&&slash'||'admin' as rdbms_admin from dual new 1: select '/u01/app/oracle/product/12.2.0/db'||'/'||'rdbms'||'/'||'admin' as rdbms_admin from dual SQL> SQL> Rem $ORACLE_HOME/rdbms/admin/catcdb.pl SQL> column rdbms_admin_catcdb new_value rdbms_admin_catcdb noprint SQL> select '&&rdbms_admin'||'&&slash'||'catcdb.pl' as rdbms_admin_catcdb from dual; old 1: select '&&rdbms_admin'||'&&slash'||'catcdb.pl' as rdbms_admin_catcdb from dual new 1: select '/u01/app/oracle/product/12.2.0/db/rdbms/admin'||'/'||'catcdb.pl' as rdbms_admin_catcdb from dual SQL> SQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2 Enter value for 1: Enter value for 2: Can't locate util.pm in @INC (you may need to install the util module) (@INC contains: /u01/app/oracle/product/12.2.0/db/rdbms/admin /u01/app/oracle/product/12.2.0/db/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi /u01/app/oracle/product/12.2.0/db/perl/lib/site_perl/5.22.0 /u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0/x86_64-linux-thread-multi /u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0 .) at /u01/app/oracle/product/12.2.0/db/rdbms/admin/catcdb.pl line 35. BEGIN failed--compilation aborted at /u01/app/oracle/product/12.2.0/db/rdbms/admin/catcdb.pl line 35.
这个问题把util改为Util
[oracle@jytest3 ~]$ find $ORACLE_HOME -name util.pm | wc -l [oracle@jytest3 ~]$ find $ORACLE_HOME -name Util.pm | wc -l 5 [oracle@jytest3 ~]$ find $ORACLE_HOME -name Util.pm /u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash/Util.pm /u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0/x86_64-linux-thread-multi/List/Util.pm /u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0/x86_64-linux-thread-multi/Scalar/Util.pm /u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0/x86_64-linux-thread-multi/Sub/Util.pm /u01/app/oracle/product/12.2.0/db/perl/lib/site_perl/5.22.0/HTTP/Headers/Util.pm
这个过程中到底该选哪个目录下的Util.pm呢,如果多点耐心仔细看看里面的内容还是能够找到一些头绪的,最后选择的是:
/u01/app/oracle/product/12.2.0/db/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash/Util.pm
需要手工修改catcdb.pl脚本
那么问题来了,这个catcdb.pl脚本是不是要改动呢。修改文件catcdb.pl,把下面的util修改为Util
use Term::ReadKey; # to not echo password use Getopt::Long; use Cwd; use File::Spec; use Data::Dumper; use Utilqw(trim, splitToArray); use catcon qw(catconSqlplus);
再来一轮测试,结果发现还是会有报错,这种尝试会让你开始怀疑自己的选择到底是不是正确的方向。如果还是没有找到,说明在当前的环境变量中没有匹配到相关的内容,我们需要直接切换到目录Hash下,然后运行脚本才可以,这个时候输出才算有了改观,提示你输入密码。
[oracle@jytest3 Hash]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Fri Aug 4 22:25:23 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to: Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production SQL> @$ORACLE_HOME/rdbms/admin/catcdb.sql SQL> Rem SQL> Rem $Header: rdbms/admin/catcdb.sql /main/7 2016/06/23 11:38:38 akruglik Exp $ SQL> Rem SQL> Rem catcdb.sql SQL> Rem SQL> Rem Copyright (c) 2013, 2016, Oracle and/or its affiliates. SQL> Rem All rights reserved. SQL> Rem SQL> Rem NAME SQL> Rem catcdb.sql - SQL> Rem SQL> Rem DESCRIPTION SQL> Rem invoke catcdb.pl SQL> Rem SQL> Rem NOTES SQL> Rem SQL> Rem SQL> Rem PARAMETERS: SQL> Rem - log directory SQL> Rem - base for log file name SQL> Rem SQL> Rem MODIFIED (MM/DD/YY) SQL> Rem akruglik 06/21/16 - Bug 22752041: pass --logDirectory and SQL> Rem --logFilename to catcdb.pl SQL> Rem akruglik 11/10/15 - use catcdb.pl to collect passowrds and pass them SQL> Rem on to catcdb_int.sql using env vars SQL> Rem aketkar 04/30/14 - remove SQL file metadata SQL> Rem cxie 08/16/13 - remove SQL_PHASE SQL> Rem cxie 07/10/13 - 17033183: add shipped_file metadata SQL> Rem cxie 03/19/13 - create CDB with all options installed SQL> Rem cxie 03/19/13 - Created SQL> Rem SQL> SQL> set echo on SQL> SQL> Rem The script relies on the caller to have connected to the DB SQL> SQL> Rem This script invokes catcdb.pl that does all the work, so we just need to SQL> Rem construct strings for $ORACLE_HOME/rdbms/admin and SQL> Rem $ORACLE_HOME/rdbms/admin/catcdb.pl SQL> SQL> Rem $ORACLE_HOME SQL> column oracle_home new_value oracle_home noprint SQL> select sys_context('userenv', 'oracle_home') as oracle_home from dual; SQL> SQL> Rem OS-dependent slash SQL> column slash new_value slash noprint SQL> select sys_context('userenv', 'platform_slash') as slash from dual; SQL> SQL> Rem $ORACLE_HOME/rdbms/admin SQL> column rdbms_admin new_value rdbms_admin noprint SQL> select '&&oracle_home'||'&&slash'||'rdbms'||'&&slash'||'admin' as rdbms_admin from dual; old 1: select '&&oracle_home'||'&&slash'||'rdbms'||'&&slash'||'admin' as rdbms_admin from dual new 1: select '/u01/app/oracle/product/12.2.0/db'||'/'||'rdbms'||'/'||'admin' as rdbms_admin from dual SQL> SQL> Rem $ORACLE_HOME/rdbms/admin/catcdb.pl SQL> column rdbms_admin_catcdb new_value rdbms_admin_catcdb noprint SQL> select '&&rdbms_admin'||'&&slash'||'catcdb.pl' as rdbms_admin_catcdb from dual; old 1: select '&&rdbms_admin'||'&&slash'||'catcdb.pl' as rdbms_admin_catcdb from dual new 1: select '/u01/app/oracle/product/12.2.0/db/rdbms/admin'||'/'||'catcdb.pl' as rdbms_admin_catcdb from dual SQL> SQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2 Enter new password for SYS: xxzx_7817600 Enter new password for SYSTEM: xxzx_7817600 Enter temporary tablespace name: tempts1 No options to container mapping specified, no options will be installed in any containers catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/catalog_catcon_27898.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catalog*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catalog_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/catproc_catcon_3352.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catproc*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catproc_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/catoctk_catcon_9051.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catoctk*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catoctk_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/owminst_catcon_9233.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/owminst*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/owminst_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11572.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11761.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_*.lst] files for spool files, if any validate_script_path: sqlplus script /u01/app/oracle/product/12.2.0/db/sqlplus/admin/help/hlpbld does not exist or is unreadable catconExec: empty Path returned by validate_script_path for SrcDir = /u01/app/oracle/product/12.2.0/db/sqlplus/admin/help, FileName = hlpbld catcon.pl: Unexpected error encountered in catconExec; exiting exec_DB_script: /u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11761_exec_DB_script.done did not need to be deleted before running a script exec_DB_script: opened Reader and Writer exec_DB_script: connected exec_DB_script: executed set echo on exec_DB_script: executed @@/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_kill_sess_11761_ALL.sql exec_DB_script: sent host sqlplus -v > /u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11761_exec_DB_script.done to Writer exec_DB_script: sent -exit- to Writer exec_DB_script: closed Writer exec_DB_script: marker was undefined; read and ignore output, if any exec_DB_script: finished reading and ignoring output exec_DB_script: waiting for child process to exit exec_DB_script: child process exited sureunlink: unlink(/u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11761_exec_DB_script.done) succeeded after 1 attempt(s) sureunlink: verify that the file really no longer exists sureunlink: confirmed that /u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11761_exec_DB_script.done no longer exists after 1 attempts exec_DB_script: deleted /u01/app/oracle/product/12.2.0/db/rdbms/log/pupbld_catcon_11761_exec_DB_script.done after running a script exec_DB_script: closed Reader exec_DB_script: waitpid returned kill_sqlplus_sessions: output produced in exec_DB_script [ SQL*Plus: Release 12.2.0.1.0 Production on Sat Aug 5 00:30:52 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. SQL> Connected. SQL> SQL> SQL> SQL> ALTER SYSTEM KILL SESSION '78,1729' force timeout 0 -- process 11802 2 / System altered. SQL> SQL> SQL> SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production ] end of output produced in exec_DB_script catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/catclust_catcon_11824.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catclust*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catclust_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/catfinal_catcon_12430.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catfinal*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catfinal_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/catbundleapply_catcon_12604.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catbundleapply*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/catbundleapply_*.lst] files for spool files, if any catcon.pl: completed successfully catcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db/rdbms/log/utlrp_catcon_12789.lst] catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/utlrp*.log] files for output generated by scripts catcon: See [/u01/app/oracle/product/12.2.0/db/rdbms/log/utlrp_*.lst] files for spool files, if any catcon.pl: completed successfully
使用OMF来创建CDB
下面的例子将介绍如何使用OMF功能来创建CDB
1.设置SID
[root@jytest3 ~]# su - oracle Last login: Fri Aug 4 15:07:33 CST 2017 [oracle@jytest3 ~]$ cd $ORACLE_HOME/dbs [oracle@jytest3 dbs]$ export ORACLE_SID=cs
2.创建密码文件
[oracle@jytest3 dbs]$ orapwd file=$ORACLE_HOME/dbs/orapwcs password=xxzx_7817600 format=12.2 entries=20
3.创建初始化参数
[oracle@jytest3 dbs]$ vi inittest.ora db_name='cs' memory_target=4G memory_max_target=4G control_files='+data/cs/controlfile/control01.ctl','+data/cs/controlfile/control02.ctl' enable_pluggable_database=true db_create_file_dest=+data
4.启动实例但不mount
[oracle@jytest3 dbs]$ export ORACLE_SID=cs [oracle@jytest3 dbs]$ sqlplus / as sysdba SQL*Plus: Release 12.2.0.1.0 Production on Fri Aug 4 20:59:37 2017 Copyright (c) 1982, 2016, Oracle. All rights reserved. Connected to an idle instance. SQL> startup pfile='$ORACLE_HOME/dbs/initcs.ora' nomount ORACLE instance started. Total System Global Area 4294967296 bytes Fixed Size 8628936 bytes Variable Size 2315257144 bytes Database Buffers 1962934272 bytes Redo Buffers 8146944 bytes
5.执行create database语句来创建CDB
下面的语句将创建一个名为cs的CDB数据库。这个名字与参数文件中的db_name同名。为了创建包含root与CDB seed的CDB库在create database语句中包含了enable pluggable database子句。在这个例子还包含了
seed tablespace datafiles子句来指定CDB seed文件的文件名与目录。
SQL> create database cs 2 user sys identified by xxzx_7817600 3 user system identified by xxzx_7817600 4 extent management local 5 default tablespace users 6 default temporary tablespace temp 7 undo tablespace undotbs1 8 enable pluggable database 9 seed 10 system datafiles size 125m autoextend on next 10m maxsize unlimited 11 sysaux datafiles size 100m; Database created.
6.执行脚本$ORACLE_HOME/rdbms/admin/catcdb.sql
2017年05月31日 17:01:02 Leshami 阅读数:4055
个人分类: -----Oracle 12c相关特性
版权声明:本文为博主原创文章,欢迎扩散,扩散请务必注明出处。 https://blog.csdn.net/robinson_0612/article/details/72821806
对于Oracle数据库的创建,Oracle除了支持dbca(GUI界面),同时也支持手工方式创建数据库,即使用CREATE DATABASE语句创建数据库。使用此语句对使用DBCA的一个优点是可以从脚本内创建数据库。在Oracle 12c版本中支持12c之前的非CDB数据库以及CDB容器数据库。因此创建方式略有不同。本文同时描述2种不同数据库的手工创建方法。
ORACLE_SID的环境变量用于该实例从稍后可能创建并同时在同一主机计算机上运行其他Oracle Database实例区分开来。
$ export ORACLE_SID=nocdb $ export ORACLE_UNQNAME=nocdb12
根据您的平台,在启动SQL * Plus之前(根据后续步骤的要求),您可能必须设置环境变量,或至少验证它们是否正确设置。如下查看当前已设定的环境变量,如果未设定,请使用export命令方式设定之。
$ env|grep ORAORACLE_UNQNAME=nocdbORACLE_SID=nocdbORACLE_BASE=/app/oracle/ora12cORACLE_HOSTNAME=ydq05.ydq.comORACLE_HOME=/app/oracle/ora12c/db_1123456
您必须进行身份验证并授予相应的系统权限才能创建数据库。
通常情况下,使用以下方式具有所需权限的管理员进行身份验证:
使用密码文件
具有操作系统认证(此演示中使用操作系统认证)
$ id oracle uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba)12
当Oracle实例启动时,它读取一个初始化参数文件。该文件可以是文本文件,可以使用文本编辑器或二进制文件进行创建和修改,该文件由数据库创建和动态修改。优选的二进制文件称为服务器参数文件。在此步骤中,您将创建一个文本初始化参数文件。在后面的步骤中,您可以从文本文件创建一个服务器参数文件。
$ mkdir -pv /app/oracle/ora12c/oradata/nocdb #创建存放数据文件的目录$ vi $ORACLE_HOME/dbs/initnocdb.oraDB_NAME=nocdbCONTROL_FILES='/app/oracle/ora12c/oradata/nocdb/contorl01.ctl'MEMORY_TARGET=380m1234567
在Windows平台上,连接到实例之前,必须手动创建它,如果它不存在。该ORADIM命令通过创建一个新的Windows服务创建一个Oracle数据库实例。
oradim -NEW -SID sid -STARTMODE MANUAL -PFILE file1
启动SQL * Plus并使用管理权限连接到Oracle数据库实例SYSDBA。
$ sqlplus / as sysdba --演示环境为12.1版本SQL*Plus: Release 12.1.0.1.0 Production on Wed May 31 10:44:41 2017Copyright (c) 1982, 2013, Oracle. All rights reserved. Connected to an idle instance. SQL>123456789
服务器参数文件使您可以使用该ALTER SYSTEM命令更改初始化参数,并在数据库关闭和启动时保留更改。您可以从编辑的文本初始化文件创建服务器参数文件。
SQL> create spfile from pfile='/app/oracle/ora12c/db_1/dbs/initnocdb.ora';12
启动实例而不安装数据库。
SQL> startup nomount; ORACLE instance started.Total System Global Area 1068937216 bytesFixed Size 2296576 bytesVariable Size 641729792 bytesDatabase Buffers 419430400 bytesRedo Buffers 5480448 bytes12345678
要创建新数据库,请使用该CREATE DATABASE语句。
SQL> CREATE DATABASE nocdb USER SYS IDENTIFIED BY pass USER SYSTEM IDENTIFIED BY pass LOGFILE GROUP 1 ('/app/oracle/ora12c/oradata/nocdb/redo01a.log','/app/oracle/ora12c/oradata/nocdb/redo01b.log') SIZE 100M BLOCKSIZE 512, GROUP 2 ('/app/oracle/ora12c/oradata/nocdb/redo02a.log','/app/oracle/ora12c/oradata/nocdb/redo02b.log') SIZE 100M BLOCKSIZE 512 MAXLOGHISTORY 1 MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 1024 CHARACTER SET AL32UTF8 NATIONAL CHARACTER SET AL16UTF16 EXTENT MANAGEMENT LOCAL DATAFILE '/app/oracle/ora12c/oradata/nocdb/system01.dbf' SIZE 700M SYSAUX DATAFILE '/app/oracle/ora12c/oradata/nocdb/sysaux01.dbf' SIZE 550M DEFAULT TABLESPACE users DATAFILE '/app/oracle/ora12c/oradata/nocdb/users01.dbf' SIZE 500M DEFAULT TEMPORARY TABLESPACE tempts1 TEMPFILE '/app/oracle/ora12c/oradata/nocdb/temp01.dbf' SIZE 20M UNDO TABLESPACE undotbs1 DATAFILE '/app/oracle/ora12c/oradata/nocdb/undotbs01.dbf' SIZE 200M USER_DATA TABLESPACE usertbs DATAFILE '/app/oracle/ora12c/oradata/nocdb/usertbs01.dbf' SIZE 200M;123456789101112131415161718192021222324
要使数据库起作用,必须为应用程序数据创建其他表空间。
SQL> CREATE TABLESPACE apps_tbs LOGGING DATAFILE '/app/oracle/ora12c/oradata/nocdb/apps01.dbf' SIZE 500M REUSE AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL;1234
运行构建数据字典视图,同义词和PL / SQL包所必需的脚本,并支持SQL * Plus的正常运行。
使用sysdba权限执行以下脚本
SQL> @?/rdbms/admin/catalog.sql --数据库字典,动态视图创建等 SQL> @?/rdbms/admin/catproc.sql --PL/SQL存过过程相关代码 SQL> @?/rdbms/admin/utlrp.sql --编译123
使用SYSTEM用户执行以下脚本
SQL> @?/sqlplus/admin/pupbld.sql --SQL*Plus相关--验证结果 SQL> SELECT name, 2 DECODE (cdb, 3 'YES', 'Multitenant Option enabled', 4 'Regular 12c Database: ') 5 "Multitenant Option", 6 open_mode, 7 con_id 8 FROM v$database; NAME Multitenant Option OPEN_MODE CON_ID--------- -------------------------- -------------------- ----------NOCDB Regular 12c Database: READ WRITE 0123456789101112131415
您可能需要运行其他脚本。您运行的脚本由您选择使用或安装的功能和选项决定。
进行完整备份,以确保您有一套完整的文件,如果发生介质故障,可以从中恢复。
您可能希望将Oracle实例配置为在其主机重新启动时自动启动。
使用CREATE DATABASESQL语句创建CDB非常类似于创建非CDB。使用CREATE DATABASESQL语句创建CDB时,必须启用PDB并指定根文件和种子文件的名称和位置。
要创建CDB,CREATE DATABASE语句必须包含ENABLE PLUGGABLE DATABASE子句。当包含此子句时,该语句使用根和种子创建CDB。如果未指定ENABLE PLUGGABLE DATABASE子句 那新创建的数据库是非CDB。该语句不会创建根和种子,非CDB永远不会包含PDB。
以下为几个主要差异部分
CDB数据库创建时应指定ENABLE PLUGGABLE DATABASE子句
CDB数据库应指定根文件和种子文件的名称和位置
CREATE DATABASE语句使用根文件(如数据文件)生成种子文件的名称。您必须指定根文件和种子文件的名称和位置。
CREATE DATABASE语句成功完成后,您可以使用种子及其文件创建新的PDB。种子在创建后不能被修改。
可以通过以下方式之一指定种子文件的名称和位置
使用 seed FILE_NAME_CONVERT 子句
如SEED FILE_NAME_CONVERT = (‘/app/oracle/ora12c/oradata/cdb1/’,’/app/oracle/ora12c/oradata/pdbseed/’)表示将cdb1目录下的文件转换到pdbseed目录下
基于oracle文件托管方式(OMF)
使用PDB_FILE_NAME_CONVERT初始化参数
可以为PDB种子数据库制定不同的属性
根SYSTEM和SYSAUX表空间的数据文件的属性可能不适合种子。在这种情况下,您可以使用子句为种子的数据文件指定不同的属性tablespace_datafile。使用这些子句指定所有数据文件包含的属性SYSTEM和SYSAUX表空间中的种子。从根继承的值用于尚未提供其值的任何属性。
如下示例
DATAFILE '/u01/app/oracle/oradata/newcdb/system01.dbf' SIZE 325M REUSE SYSAUX DATAFILE '/u01/app/oracle/oradata/newcdb/sysaux01.dbf' SIZE 325M REUSE --下面的seed部分使用了不同于上面root容器的配置,--如system数据文件此处大小为125M,而root容器中为352M--seed中开启了自动扩展,sysaux也同样使用了一些不同于root容器的属性--对于在seed中未明确指定的属性,则继承root容器数据文件属性SEED SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED SYSAUX DATAFILES SIZE 100M123456789101112
详细步骤参考12c下手工创建非cdb数据库,以下部分省略每一步骤详细描述,后面列出差异
--设定环境变量 $ export ORACLE_SID=cdb1 $ export ORACLE_UNQNAME=cdb1--创建相应目录 $ mkdir -pv /app/oracle/ora12c/oradata/cdb1 $ mkdir -pv /app/oracle/ora12c/oradata/pdbseed--生成参数文件 $ vi $ORACLE_HOME/dbs/initcdb1.ora DB_NAME=cdb1 CONTROL_FILES='/app/oracle/ora12c/oradata/cdb1/contorl01.ctl'MEMORY_TARGET=380m ENABLE_PLUGGABLE_DATABASE=true--开始建库 $ sqlplus / as sysdba SQL> create spfile from pfile='$ORACLE_HOME/dbs/initcdb1.ora'; SQL> startup nomount; SQL> CREATE DATABASE cdb1 USER SYS IDENTIFIED BY pass USER SYSTEM IDENTIFIED BY pass LOGFILE GROUP 1 ('/app/oracle/ora12c/oradata/cdb1/redo01a.log','/app/oracle/ora12c/oradata/cdb1/redo01b.log') SIZE 100M BLOCKSIZE 512, GROUP 2 ('/app/oracle/ora12c/oradata/cdb1/redo02a.log','/app/oracle/ora12c/oradata/cdb1/redo02b.log') SIZE 100M BLOCKSIZE 512 MAXLOGHISTORY 1 MAXLOGFILES 16 MAXLOGMEMBERS 3 MAXDATAFILES 1024 CHARACTER SET AL32UTF8 NATIONAL CHARACTER SET AL16UTF16 EXTENT MANAGEMENT LOCAL DATAFILE '/app/oracle/ora12c/oradata/cdb1/system01.dbf' SIZE 700M SYSAUX DATAFILE '/app/oracle/ora12c/oradata/cdb1/sysaux01.dbf' SIZE 550M DEFAULT TABLESPACE deftbs DATAFILE '/app/oracle/ora12c/oradata/cdb1/deftbs01.dbf' SIZE 500M DEFAULT TEMPORARY TABLESPACE tempts1 TEMPFILE '/app/oracle/ora12c/oradata/cdb1/temp01.dbf' SIZE 20M UNDO TABLESPACE undotbs1 DATAFILE '/app/oracle/ora12c/oradata/cdb1/undotbs01.dbf' SIZE 200M ENABLE PLUGGABLE DATABASE SEED FILE_NAME_CONVERT = ('/app/oracle/ora12c/oradata/cdb1/', '/app/oracle/ora12c/oradata/pdbseed/') SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED SYSAUX DATAFILES SIZE 100M USER_DATA TABLESPACE usertbs DATAFILE '/app/oracle/ora12c/oradata/pdbseed/usertbs01.dbf' SIZE 200M;--填充数据字典,如果是12cR2版本,则直接执行catcdb.sql代替以下脚本 --使用sysdba权限执行以下脚本 SQL> @?/rdbms/admin/catalog.sql --数据库字典,动态视图创建等 SQL> @?/rdbms/admin/catproc.sql --PL/SQL存过过程相关代码 SQL> @?/rdbms/admin/utlrp.sql --编译--使用SYSTEM用户执行以下脚本 SQL> @?/sqlplus/admin/pupbld.sql #SQL*Plus相关 SQL> select 'Leshami' Author,'http://blog.csdn.net/leshami' Blog, 2 '645746311' QQ from dual; AUTHOR BLOG QQ------- ---------------------------- ---------Leshami http://blog.csdn.net/leshami 645746311--验证结果 SQL> SELECT name, 2 DECODE (cdb, 3 'YES', 'Multitenant Option enabled', 4 'Regular 12c Database: ') 5 "Multitenant Option", 6 open_mode, 7 con_id 8 FROM v$database; NAME Multitenant Option OPEN_MODE CON_ID--------- -------------------------- -------------------- ----------CDB1 Multitenant Option enabled READ WRITE 01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
Oracle 12c多租户架构及优缺点
http://docs.oracle.com/database/122/ADMIN/creating-and-configuring-an-oracle-database.htm
http://docs.oracle.com/database/122/ADMIN/creating-and-configuring-a-cdb.htm
About Me
........................................................................................................................ ● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除 ● 本文在itpub( http://blog.itpub.net/26736162 )、博客园( http://www.cnblogs.com/lhrbest )和个人weixin公众号( xiaomaimiaolhr )上有同步更新 ● 本文itpub地址: http://blog.itpub.net/26736162 ● 本文博客园地址: http://www.cnblogs.com/lhrbest ● 本文pdf版、个人简介及小麦苗云盘地址: http://blog.itpub.net/26736162/viewspace-1624453/ ● 数据库笔试面试题库及解答: http://blog.itpub.net/26736162/viewspace-2134706/ ● DBA宝典今日头条号地址: http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826 ........................................................................................................................ ● QQ群号: 230161599 (满) 、618766405 ● weixin群:可加我weixin,我拉大家进群,非诚勿扰 ● 联系我请加QQ好友 ( 646634621 ) ,注明添加缘由 ● 于 2018-10-01 06:00 ~ 2018-10-31 24:00 在魔都完成 ● 最新修改时间:2018-10-01 06:00 ~ 2018-10-31 24:00 ● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解 ● 版权所有,欢迎分享本文,转载请保留出处 ........................................................................................................................ ● 小麦苗的微店 : https://weidian.com/s/793741433?wfr=c&ifr=shopdetail ● 小麦苗出版的数据库类丛书 : http://blog.itpub.net/26736162/viewspace-2142121/ ● 小麦苗OCP、OCM、高可用网络班 : http://blog.itpub.net/26736162/viewspace-2148098/ ● 小麦苗腾讯课堂主页 : https://lhr.ke.qq.com/ ........................................................................................................................ 使用 weixin客户端 扫描下面的二维码来关注小麦苗的weixin公众号( xiaomaimiaolhr )及QQ群(DBA宝典)、添加小麦苗weixin, 学习最实用的数据库技术。
........................................................................................................................ |
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26736162/viewspace-2215902/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26736162/viewspace-2215902/