手工创建cdb数据库(create database语句)

来源:互联网 发布:联通云计算公司 编辑:程序博客网 时间:2024/05/16 16:23


1. 创建newcdb的参数文件

[oracle@12cr2 ~]$ cd $ORACLE_HOME/dbs[oracle@12cr2 dbs]$ cat initnewcdb.ora db_create_file_dest='/u01/app/oracle/oradata/newcdb'sga_target=800Mdb_name=newcdbenable_pluggable_database=true

2. 创建存放数据文件的目录

[oracle@12cr2 dbs]$ mkdir /u01/app/oracle/oradata/newcdb

3. 创建CREATE DATABASE的SQL语句脚本

[oracle@12cr2 ~]$ cat create_omfdb.sql CREATE DATABASE newcdbUSER SYS IDENTIFIED BY newcdbUSER SYSTEM IDENTIFIED BY newcdbEXTENT MANAGEMENT LOCALDEFAULT TABLESPACE usersDEFAULT TEMPORARY TABLESPACE tempUNDO TABLESPACE undotbs1ENABLE PLUGGABLE DATABASE  SEED  SYSTEM DATAFILES SIZE 125M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED  SYSAUX DATAFILES SIZE 100M;

4. 指定SID,生成spfile,启动数据库到nomount状态

[oracle@12cr2 dbs]$ export ORACLE_SID=newcdb            [oracle@12cr2 ~]$ sqlplus / as sysdbaSQL*Plus: Release 12.2.0.1.0 Production on Mon May 15 21:26:10 2017Copyright (c) 1982, 2016, Oracle.  All rights reserved.Connected to an idle instance.SQL> create spfile from pfile;File created.SQL> startup nomount force;      ORACLE instance started.Total System Global Area  838860800 bytesFixed Size                  8798312 bytesVariable Size             226496408 bytesDatabase Buffers          599785472 bytesRedo Buffers                3780608 bytes

5. 创建数据库

SQL> set echo onSQL> set timing onSQL> @create_omfdb.sqlSQL> CREATE DATABASE newcdb  2  USER SYS IDENTIFIED BY newcdb  3  USER SYSTEM IDENTIFIED BY newcdb  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.Elapsed: 00:00:45.29SQL> set timing offSQL> show pdbs;    CON_ID CON_NAME                       OPEN MODE  RESTRICTED---------- ------------------------------ ---------- ----------         2 PDB$SEED                       READ ONLY  NO

6. 执行catcdb.sql脚本

修改oracle用户的环境变量,在PATH中加入$ORACLE_HOME/perl/bin

[oracle@12cr2 ~]$ vi .bash_profile export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/perl/bin:$PATH:$HOME/bin[oracle@12cr2 ~]$ export PATH=$ORACLE_HOME/bin:$ORACLE_HOME/perl/bin:$PATH:$HOME/bin
执行catcdb.sql,会报如下错误:
SQL> @?/rdbms/admin/catcdb.sqlSQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2Enter value for 1: /u01/app/oracle/product/12.2.0/db_1/rdbms/adminEnter value for 2: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.plCan't locate util.pm in @INC (you may need to install the util module) (@INC contains: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin /u01/app/oracle/product/12.2.0/db_1/perl/lib/site_perl/5.22.0/x86_64-linux-thread-multi /u01/app/oracle/product/12.2.0/db_1/perl/lib/site_perl/5.22.0 /u01/app/oracle/product/12.2.0/db_1/perl/lib/5.22.0/x86_64-linux-thread-multi /u01/app/oracle/product/12.2.0/db_1/perl/lib/5.22.0 .) at /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl line 35.BEGIN failed--compilation aborted at /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.pl line 35.
上面报错的解决方法,修改catcdb.pl文件,到$ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash下面执行catcdb.sql
[oracle@12cr2 Hash]$ vi $ORACLE_HOME/rdbms/admin/catcdb.pl修改use util qw(trim, splitToArray);为use Util qw(trim, splitToArray);

[oracle@12cr2 ~]$ cd $ORACLE_HOME/perl/lib/5.22.0/x86_64-linux-thread-multi/Hash[oracle@12cr2 Hash]$ lltotal 28drwxr-xr-x 2 oracle oinstall  4096 May  9 00:02 Util-rwxr-x--- 1 oracle oinstall 23392 May 12  2016 Util.pm[oracle@12cr2 Hash]$ sqlplus / as sysdbaSQL*Plus: Release 12.2.0.1.0 Production on Mon May 15 21:56:50 2017Copyright (c) 1982, 2016, Oracle.  All rights reserved.Connected to:Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit ProductionSQL> @?/rdbms/admin/catcdb.sqlSQL> host perl -I &&rdbms_admin &&rdbms_admin_catcdb --logDirectory &&1 --logFilename &&2Enter value for 1: /u01/app/oracle/product/12.2.0/db_1/rdbms/adminEnter value for 2: /u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catcdb.plEnter new password for SYS: newcdbEnter new password for SYSTEM: newcdbEnter temporary tablespace name: tempNo options to container mapping specified, no options will be installed in any containerscatcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catalog_catcon_3304.lst]catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catalog*.log] files for output generated by scriptscatcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catalog_*.lst] files for spool files, if any… …    SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production  ] end of output produced in exec_DB_scriptcatcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catclust_catcon_4806.lst]catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catclust*.log] files for output generated by scriptscatcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catclust_*.lst] files for spool files, if anycatcon.pl: completed successfullycatcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catfinal_catcon_5175.lst]catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catfinal*.log] files for output generated by scriptscatcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catfinal_*.lst] files for spool files, if anycatcon.pl: completed successfullycatcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catbundleapply_catcon_5259.lst]catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catbundleapply*.log] files for output generated by scriptscatcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/catbundleapply_*.lst] files for spool files, if anycatcon.pl: completed successfullycatcon: ALL catcon-related output will be written to [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/utlrp_catcon_5343.lst]catcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/utlrp*.log] files for output generated by scriptscatcon: See [/u01/app/oracle/product/12.2.0/db_1/rdbms/admin/utlrp_*.lst] files for spool files, if anycatcon.pl: completed successfully